Skip to content

Fallback to pep517 if setup.py is present and setuptools cannot be imported#10717

Merged
pradyunsg merged 5 commits into
pypa:mainfrom
hrnciar:fallback-to-pep517
Apr 23, 2022
Merged

Fallback to pep517 if setup.py is present and setuptools cannot be imported#10717
pradyunsg merged 5 commits into
pypa:mainfrom
hrnciar:fallback-to-pep517

Conversation

@hrnciar

@hrnciar hrnciar commented Dec 8, 2021

Copy link
Copy Markdown
Contributor

This is WIP PR without any documentation or tests. I'd like to first know your opinion whether the idea is acceptable. Thank you.

@pfmoore

pfmoore commented Dec 8, 2021

Copy link
Copy Markdown
Member

I'm inclined to agree with the suggestion @uranusjr made on Discourse - if there's no setup.py and setuptools cannot be imported, the only possible thing that will work is to use PEP 517, so why not do that? Which means this PR can simply be "use PEP 517 if setuptools cannot be imported".

@hroncok

hroncok commented Dec 9, 2021

Copy link
Copy Markdown
Contributor

I'd argue that when the user explicitly used --no-pep517 and setuptools is not installed, that deserves an error.

@hroncok

hroncok commented Dec 9, 2021

Copy link
Copy Markdown
Contributor

That combined basically means something like:

    ... elif not has_setuptools:
        if use_pep517 is not None and not use_pep517:
            raise InstallationError(
                "Disabling PEP 517 processing is invalid: "
                "setuptools not installed"
            )
        use_pep517 = True

@uranusjr

uranusjr commented Dec 9, 2021

Copy link
Copy Markdown
Member

The “can’t do --no-use-pep517 because setuptools is not found” error can even be raised as early as command argument parsing, instead of half-way into package installation.

@hrnciar hrnciar force-pushed the fallback-to-pep517 branch 3 times, most recently from 2af305c to 7fb607b Compare December 10, 2021 14:54
# https://discuss.python.org/t/pip-without-setuptools-could-the-experience-be-improved/11810/9
elif use_pep517 is None:
use_pep517 = has_pyproject
use_pep517 = has_pyproject or not importlib.util.find_spec("setuptools")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the setuptools check can be technically made much sooner in this function, but this way, it is avoided when not necessary. Not sure which approach is better.

Comment thread src/pip/_internal/cli/cmdoptions.py Outdated
@pradyunsg

pradyunsg commented Dec 10, 2021

Copy link
Copy Markdown
Member

FWIW, I was hoping to go down a different avenue here: dc217bb

That presents a clearer error message instead of opting these projects into PEP 517.

@hroncok

hroncok commented Dec 10, 2021

Copy link
Copy Markdown
Contributor

At least to me, opting to PEP 517 when setuptools is not installed sounds like a more user-friendly thing to do than erroring out (and gradually downloading a lesser and lesser version of the package only to error again and again).

@pradyunsg

Copy link
Copy Markdown
Member

Yea... #10655 is annoying.

It seems to me that there's reasonable agreement that we should stop backtracking on build failures, which combined with better presentation of build failures (I'll file this as a PR once #10703 merges) could be a more "complete" solution here; rather than needing to change this one special case?

@hroncok

hroncok commented Dec 10, 2021

Copy link
Copy Markdown
Contributor

Even without backtracking, I still think that using PEP 517 when setuptools is not present is the nicer thing to do, but I won't fight you on that. A better error report and no backtracking makes this good enough for me.

@pradyunsg

Copy link
Copy Markdown
Member

Thinking about this a bit more, I think we should do all three things: this PR, #10722 and #10723. They're all better behaviours, and I think it's totally reasonable for us to do all of them.

@hrnciar hrnciar force-pushed the fallback-to-pep517 branch 3 times, most recently from 7fb607b to eb1c8f3 Compare January 3, 2022 12:27
@hrnciar

hrnciar commented Jan 4, 2022

Copy link
Copy Markdown
Contributor Author

I was trying to solve the CI issues, but I ran into some test failures. I don't think they are caused by this PR, because I am getting the same failures when I run the tests on the main branch locally. If that's the case, I think PR is ready for review.

@hrnciar hrnciar marked this pull request as ready for review January 4, 2022 12:09
@uranusjr

uranusjr commented Jan 4, 2022

Copy link
Copy Markdown
Member

Those are caused by #10742, don’t mind them.

@hroncok

hroncok commented Jan 18, 2022

Copy link
Copy Markdown
Contributor

Is this ready to be merged, or do we need to change something?

@github-actions github-actions Bot added the needs rebase or merge PR has conflicts with current master label Jan 27, 2022
@hrnciar hrnciar force-pushed the fallback-to-pep517 branch from eb1c8f3 to e7a790a Compare March 2, 2022 11:53
@pypa-bot pypa-bot removed the needs rebase or merge PR has conflicts with current master label Mar 2, 2022
@hroncok

hroncok commented Mar 30, 2022

Copy link
Copy Markdown
Contributor

What si the next step here?

@uranusjr

Copy link
Copy Markdown
Member

Anyone else wants to take a look? If not I’m inclined to include this in the 22.1 release.

@uranusjr uranusjr added this to the 22.1 milestone Mar 30, 2022

@pfmoore pfmoore left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor point, but otherwise LGTM

Comment thread src/pip/_internal/cli/cmdoptions.py Outdated
@hroncok

hroncok commented Mar 30, 2022

Copy link
Copy Markdown
Contributor

I would still prefer this not be wrapped.

So, use a long line or split the string literal?

@pfmoore

pfmoore commented Mar 30, 2022

Copy link
Copy Markdown
Member

use a long line or split the string literal?

Ultimately whatever stops black whining about the layout, I don't really care 🙂 If I were writing this without regard for black, I'd use a long line.

Comment thread src/pip/_internal/cli/cmdoptions.py Outdated
@uranusjr

Copy link
Copy Markdown
Member

I added a commit to split the literal.

@hroncok

This comment was marked as resolved.

Comment thread src/pip/_internal/cli/cmdoptions.py Outdated
@uranusjr

This comment was marked as resolved.

@uranusjr uranusjr force-pushed the fallback-to-pep517 branch from 0dfd5b8 to 7776a6d Compare March 31, 2022 05:50

@sbidoul sbidoul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok with the concept and implementation LGTM. Does our test suite lend itself to adding a test case for this ?

Comment thread news/10717.bugfix.rst Outdated
@uranusjr

Copy link
Copy Markdown
Member

This needs a rebase to fix CI.

Comment thread news/10717.bugfix.rst Outdated
@pradyunsg pradyunsg merged commit 452d7da into pypa:main Apr 23, 2022
@pradyunsg

Copy link
Copy Markdown
Member

Thanks @hrnciar! Hopefully me short-circuiting the CI because of my lack of patience won't bite me (eg: because the linters were updated). :)

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants