Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdist installation fails when pip is run from wheel #9953

Closed
1 task done
abn opened this issue May 6, 2021 · 3 comments · Fixed by #9960
Closed
1 task done

sdist installation fails when pip is run from wheel #9953

abn opened this issue May 6, 2021 · 3 comments · Fixed by #9960
Assignees
Labels
type: bug A confirmed bug or unintended behavior
Milestone

Comments

@abn
Copy link
Contributor

abn commented May 6, 2021

Description

This might not be a bug per say as pip is not officially zip safe. However, a previously working scenario is no longer working, figured I would raise this here.

In pip versions prior to 21.1.1, we were able to use pip as shown below.

curl -sLO https://files.pythonhosted.org/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl
python pip-21.0.1-py3-none-any.whl/pip install https://files.pythonhosted.org/packages/52/7e/6a41d1504225ef9213731e69ecebfa8fe78c614bcb01e1147f6242073636/black-21.5b0.tar.gz

However, with 21.1.1 this no longer works.

Expected behavior

An sdist package can be installed successfully when installed with python pip-<version>.whl/pip install <sdist>.

pip version

21.1.1

Python version

3.9

OS

Fedora 34

How to Reproduce

The following commands reproduce the issue.

curl -sLO https://files.pythonhosted.org/packages/cd/6f/43037c7bcc8bd8ba7c9074256b1a11596daa15555808ec748048c1507f08/pip-21.1.1-py3-none-any.whl
python pip-21.1.1-py3-none-any.whl/pip --verbose install https://files.pythonhosted.org/packages/52/7e/6a41d1504225ef9213731e69ecebfa8fe78c614bcb01e1147f6242073636/black-21.5b0.tar.gz

Output

Using pip 21.1.1 from //pip-21.1.1-py3-none-any.whl/pip (python 3.9)
Non-user install because site-packages writeable
Created temporary directory: /tmp/pip-ephem-wheel-cache-okb9brsr
Created temporary directory: /tmp/pip-req-tracker-ga2kbjwp
Initialized build tracking at /tmp/pip-req-tracker-ga2kbjwp
Created build tracker: /tmp/pip-req-tracker-ga2kbjwp
Entered build tracker: /tmp/pip-req-tracker-ga2kbjwp
Created temporary directory: /tmp/pip-install-tbgi_mxf
Collecting https://files.pythonhosted.org/packages/52/7e/6a41d1504225ef9213731e69ecebfa8fe78c614bcb01e1147f6242073636/black-21.5b0.tar.gz
  Created temporary directory: /tmp/pip-req-build-remwfpjm
  Created temporary directory: /tmp/pip-unpack-92wlal61
  Looking up "https://files.pythonhosted.org/packages/52/7e/6a41d1504225ef9213731e69ecebfa8fe78c614bcb01e1147f6242073636/black-21.5b0.tar.gz" in the cache
  No cache entry available
  Starting new HTTPS connection (1): files.pythonhosted.org:443
  https://files.pythonhosted.org:443 "GET /packages/52/7e/6a41d1504225ef9213731e69ecebfa8fe78c614bcb01e1147f6242073636/black-21.5b0.tar.gz HTTP/1.1" 200 1152691
  Downloading black-21.5b0.tar.gz (1.2 MB)
  Ignoring unknown cache-control directive: immutable
  Updating cache with response from "https://files.pythonhosted.org/packages/52/7e/6a41d1504225ef9213731e69ecebfa8fe78c614bcb01e1147f6242073636/black-21.5b0.tar.gz"
  Caching due to etag
  Added https://files.pythonhosted.org/packages/52/7e/6a41d1504225ef9213731e69ecebfa8fe78c614bcb01e1147f6242073636/black-21.5b0.tar.gz to build tracker '/tmp/pip-req-tracker-ga2kbjwp'
  Created temporary directory: /tmp/pip-build-env-4zs5x6tm
  Created temporary directory: /tmp/pip-standalone-pip-kf46cir8
  Installing build dependencies: started
  Running command /usr/local/bin/python /tmp/pip-standalone-pip-kf46cir8/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-4zs5x6tm/overlay --no-warn-script-location -v --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=41.0' setuptools-scm wheel
  /usr/local/bin/python: can't find '__main__' module in '/tmp/pip-standalone-pip-kf46cir8/__env_pip__.zip/pip'
  Installing build dependencies: finished with status 'error'
WARNING: Discarding https://files.pythonhosted.org/packages/52/7e/6a41d1504225ef9213731e69ecebfa8fe78c614bcb01e1147f6242073636/black-21.5b0.tar.gz. Command errored out with exit status 1: /usr/local/bin/python /tmp/pip-standalone-pip-kf46cir8/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-4zs5x6tm/overlay --no-warn-script-location -v --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=41.0' setuptools-scm wheel Check the logs for full command output.
ERROR: Command errored out with exit status 1: /usr/local/bin/python /tmp/pip-standalone-pip-kf46cir8/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-4zs5x6tm/overlay --no-warn-script-location -v --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=41.0' setuptools-scm wheel Check the logs for full command output.
Exception information:
Traceback (most recent call last):
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/cli/base_command.py", line 180, in _main
    status = self.run(options, args)
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/cli/req_command.py", line 204, in wrapper
    return func(self, options, args)
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/commands/install.py", line 318, in run
    requirement_set = resolver.resolve(
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/resolution/resolvelib/resolver.py", line 103, in resolve
    r = self.factory.make_requirement_from_install_req(
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/resolution/resolvelib/factory.py", line 433, in make_requirement_from_install_req
    raise self._build_failures[ireq.link]
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/resolution/resolvelib/factory.py", line 200, in _make_candidate_from_link
    self._link_candidate_cache[link] = LinkCandidate(
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/resolution/resolvelib/candidates.py", line 306, in __init__
    super().__init__(
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/resolution/resolvelib/candidates.py", line 151, in __init__
    self.dist = self._prepare()
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/resolution/resolvelib/candidates.py", line 234, in _prepare
    dist = self._prepare_distribution()
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/resolution/resolvelib/candidates.py", line 317, in _prepare_distribution
    return self._factory.preparer.prepare_linked_requirement(
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/operations/prepare.py", line 508, in prepare_linked_requirement
    return self._prepare_linked_requirement(req, parallel_builds)
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/operations/prepare.py", line 570, in _prepare_linked_requirement
    dist = _get_prepared_distribution(
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/operations/prepare.py", line 60, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/distributions/sdist.py", line 34, in prepare_distribution_metadata
    self._setup_isolation(finder)
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/distributions/sdist.py", line 62, in _setup_isolation
    self.req.build_env.install_requirements(
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/build_env.py", line 199, in install_requirements
    self._install_requirements(
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/build_env.py", line 247, in _install_requirements
    call_subprocess(args, spinner=spinner, extra_environ=extra_environ)
  File "//pip-21.1.1-py3-none-any.whl/pip/_internal/utils/subprocess.py", line 244, in call_subprocess
    raise InstallationSubprocessError(proc.returncode, command_desc)
pip._internal.exceptions.InstallationSubprocessError: Command errored out with exit status 1: /usr/local/bin/python /tmp/pip-standalone-pip-kf46cir8/__env_pip__.zip/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-4zs5x6tm/overlay --no-warn-script-location -v --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'setuptools>=41.0' setuptools-scm wheel Check the logs for full command output.
1 location(s) to search for versions of pip:
* https://pypi.org/simple/pip/
Fetching project page and analyzing links: https://pypi.org/simple/pip/
Getting page https://pypi.org/simple/pip/
Found index url https://pypi.org/simple
Looking up "https://pypi.org/simple/pip/" in the cache
Request header has "max_age" as 0, cache bypassed
Starting new HTTPS connection (1): pypi.org:443
https://pypi.org:443 "GET /simple/pip/ HTTP/1.1" 200 16359
Updating cache with response from "https://pypi.org/simple/pip/"
Caching due to etag
  Found link https://files.pythonhosted.org/packages/3d/9d/1e313763bdfb6a48977b65829c6ce2a43eaae29ea2f907c8bbef024a7219/pip-0.2.tar.gz#sha256=88bb8d029e1bf4acd0e04d300104b7440086f94cc1ce1c5c3c31e3293aee1f81 (from https://pypi.org/simple/pip/), version: 0.2
<snipped>
  Found link https://files.pythonhosted.org/packages/94/b0/e10bdc8809c81796c80aa3644a8e3dc16594fb1bd68f5996929f26cad980/pip-21.1.1.tar.gz#sha256=51ad01ddcd8de923533b01a870e7b987c2eb4d83b50b89e1bf102723ff9fed8b (from https://pypi.org/simple/pip/) (requires-python:>=3.6), version: 21.1.1
Skipping link: not a file: https://pypi.org/simple/pip/
Given no hashes to check 165 links for project 'pip': discarding no candidates
WARNING: You are using pip version 20.2.4; however, version 21.1.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Removed https://files.pythonhosted.org/packages/52/7e/6a41d1504225ef9213731e69ecebfa8fe78c614bcb01e1147f6242073636/black-21.5b0.tar.gz from build tracker '/tmp/pip-req-tracker-ga2kbjwp'
Removed build tracker: '/tmp/pip-req-tracker-ga2kbjwp'

Code of Conduct

@abn abn added S: needs triage Issues/PRs that need to be triaged type: bug A confirmed bug or unintended behavior labels May 6, 2021
@uranusjr
Copy link
Member

uranusjr commented May 6, 2021

Thanks for the report. This is caused by “PEP 517 inception” (a term I invented for #9878), but slightly more obscure. Starting with 21.1, pip now builds itself as a zip file when being used to populate an isolated environment, but when it can’t do that if the “host” pip is already a zip. This is currently detected by checking if pip.__file__ is a zip file. But pip-21.1.1-py3-none-any.whl/pip is not a zip file! So the check needs some fix to account for this (e.g. go up the path chain and see if any of the parents is a file? I didn’t actually check the current implementation and don’t know what the exact right solution is yet.)

I’ll spend some time looking into this in the coming weekend. Adding this into the 21.1.2 milestone as a regression.

@uranusjr uranusjr added this to the 21.1.2 milestone May 6, 2021
@uranusjr uranusjr self-assigned this May 6, 2021
@pfmoore
Copy link
Member

pfmoore commented May 6, 2021

+1 to fixing this if it's straightforward to do so, and I think it's fair in that context to view this as a regression, but to be clear, as the OP said, this isn't formally supported usage of pip.

Although @uranusjr does the "PEP 517 inception" mechanism (which I haven't looked at too closely) rely on pip-running-from-a-zip being able to install? And if so, does it need to be able to install from general sources (e.g. PyPI)? Because if we're using pip from a zip internally, maybe we need to document that we mustn't break that usage (at a minimum in an "internal use only" section of the docs...)

abn added a commit to abn/pip that referenced this issue May 6, 2021
This change ensures that when pip is executed from a wheel, standalone
pip creation for build environment reuses the wheel.

Resolves: pypa#9953
abn added a commit to abn/pip that referenced this issue May 6, 2021
This change ensures that when pip is executed from a wheel, standalone
pip creation for build environment reuses the wheel.

Resolves: pypa#9953
@abn
Copy link
Contributor Author

abn commented May 6, 2021

@uranusjr I have attempted a fix (#9960) as it seemed fairly trivial. I have tested it locally for the reported use case and it works. Happy for it to be closed in favour of a more complete one as required.

abn added a commit to abn/pip that referenced this issue May 7, 2021
This change ensures that when pip is executed from a wheel/zip,
standalone pip creation for build environment reuses the source.

Resolves: pypa#9953
abn added a commit to abn/pip that referenced this issue May 8, 2021
This change ensures that when pip is executed from a wheel/zip,
standalone pip creation for build environment reuses the source.

Resolves: pypa#9953
abn added a commit to abn/pip that referenced this issue May 8, 2021
This change ensures that when pip is executed from a wheel/zip,
standalone pip creation for build environment reuses the source.

Resolves: pypa#9953
Co-authored-by: Tzu-ping Chung <[email protected]>
abn added a commit to abn/pip that referenced this issue May 8, 2021
This change ensures that when pip is executed from a wheel/zip,
standalone pip creation for build environment reuses the source.

Resolves: pypa#9953
Co-authored-by: Tzu-ping Chung <[email protected]>
@sbidoul sbidoul removed the S: needs triage Issues/PRs that need to be triaged label May 9, 2021
sbidoul pushed a commit to sbidoul/pip that referenced this issue May 23, 2021
This change ensures that when pip is executed from a wheel/zip,
standalone pip creation for build environment reuses the source.

Resolves: pypa#9953
Co-authored-by: Tzu-ping Chung <[email protected]>
inmantaci added a commit to inmanta/inmanta-core that referenced this issue May 24, 2021
Bumps [pip](https://github.com/pypa/pip) from 21.1.1 to 21.1.2.
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a href="https://github.com/pypa/pip/blob/main/NEWS.rst">pip's changelog</a>.</em></p>
<blockquote>
<h1>21.1.2 (2021-05-23)</h1>
<h2>Bug Fixes</h2>
<ul>
<li>New resolver: Correctly exclude an already installed package if its version is
known to be incompatible to stop the dependency resolution process with a clear
error message. (<code>[#9841](pypa/pip#9841) &lt;https://github.com/pypa/pip/issues/9841&gt;</code>_)</li>
<li>Allow ZIP to archive files with timestamps earlier than 1980. (<code>[#9910](pypa/pip#9910) &lt;https://github.com/pypa/pip/issues/9910&gt;</code>_)</li>
<li>Emit clearer error message when a project root does not contain either
<code>pyproject.toml</code>, <code>setup.py</code> or <code>setup.cfg</code>. (<code>[#9944](pypa/pip#9944) &lt;https://github.com/pypa/pip/issues/9944&gt;</code>_)</li>
<li>Fix detection of existing standalone pip instance for PEP 517 builds. (<code>[#9953](pypa/pip#9953) &lt;https://github.com/pypa/pip/issues/9953&gt;</code>_)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/pypa/pip/commit/8737f903eaa9475e1b7693e436d9bdf17e46e43a"><code>8737f90</code></a> Bump for release</li>
<li><a href="https://github.com/pypa/pip/commit/d7cf6cacdee550983686692d0d463ad493cb993d"><code>d7cf6ca</code></a> Update AUTHORS.txt</li>
<li><a href="https://github.com/pypa/pip/commit/30faa6478edbc1e54498b7cbb20111d75a96d2dd"><code>30faa64</code></a> Fix duplicate top line in NEWS.rst</li>
<li><a href="https://github.com/pypa/pip/commit/128ec362547fe11f8b3c6402687a00a06e7f6e51"><code>128ec36</code></a> Test case for backtracking an installed candidate</li>
<li><a href="https://github.com/pypa/pip/commit/729c626da75b25af0640a77efdbbfc57e567e1f9"><code>729c626</code></a> Exclude a known incompatible installed candidate</li>
<li><a href="https://github.com/pypa/pip/commit/1c31d3314c42d19b354f376991db2b33134dde5e"><code>1c31d33</code></a> Update src/pip/_internal/build_env.py</li>
<li><a href="https://github.com/pypa/pip/commit/e266aa55ac6484d33c36aee7082243edd669e2a8"><code>e266aa5</code></a> Update news/9910.bugfix.rst</li>
<li><a href="https://github.com/pypa/pip/commit/00003d5325b333290b4bcde17791ed3a489562d0"><code>00003d5</code></a> 9910 news</li>
<li><a href="https://github.com/pypa/pip/commit/d55e02c71673f4332c191cf8095360c5900f7c6e"><code>d55e02c</code></a> Set strict_timestamps=False when zip is called for isolated environment</li>
<li><a href="https://github.com/pypa/pip/commit/4f983c4476251c83bc320ebaaff0cb9b71d2e981"><code>4f983c4</code></a> Handle standalone pip creation from pip wheel</li>
<li>Additional commits viewable in <a href="https://github.com/pypa/pip/compare/21.1.1...21.1.2">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pip&package-manager=pip&previous-version=21.1.1&new-version=21.1.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)

</details>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug A confirmed bug or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants