question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

22.1: Editable installs for packages with extras & flit causes `UndefinedEnvironmentName`

See original GitHub issue

Description

First of all, thanks for pip and for taking the time to read this issue!

We use editable installs on sigstore-python to provide a convenient development environment. For example, either with or without the dev extra:

pip install --editable .
pip install --editable .[dev]

Our dependencies are entirely managed within a pyproject.toml, with a small stub setup.py to help pip do an editable install.

Up until pip==22.1, these commands worked just fine. Upon upgrading to 22.1 (released today), we get this error:

  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_vendor/packaging/markers.py", line 215, in _get_env
    raise UndefinedEnvironmentName(
pip._vendor.packaging.markers.UndefinedEnvironmentName: 'extra' does not exist in evaluation environment.

(I’ve truncated the traceback. I’ll paste the full-length trace below.)

When I run with --debug, I see that the dev extra is being passed in as an environment marker, which then fails since extra is not included in the marker environment.

image

Screen Shot 2022-05-11 at 7 34 06 PM

Expected behavior

I expect pip install --editable . to behave the same as it did in the last stable release (22.0.4), i.e. install correctly with no errors.

pip version

22.1

Python version

3.10.0

OS

macOS 12.3.1

How to Reproduce

These steps should reproduce the failure:

git clone https://github.com/sigstore/sigstore-python && cd sigstore-python
make dev

If that fails to pull down the latest pip for whatever reason, you can do it explicitly:

git clone https://github.com/sigstore/sigstore-python && cd sigstore-python
python -m venv env && source env/bin/activate
pip install --upgrade pip
pip install --editable .

Output

Obtaining file:///Users/william/devel/sigstore-python
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Checking if build backend supports build_editable: started
  Checking if build backend supports build_editable: finished with status 'done'
  Getting requirements to build editable: started
  Getting requirements to build editable: finished with status 'done'
ERROR: Exception:
Traceback (most recent call last):
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 167, in exc_logging_wrapper
    status = run_func(*args)
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
    return func(self, options, args)
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/commands/install.py", line 340, in run
    requirement_set = resolver.resolve(
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 75, in resolve
    collected = self.factory.collect_root_requirements(root_reqs)
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 506, in collect_root_requirements
    req = self._make_requirement_from_install_req(
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 468, in _make_requirement_from_install_req
    cand = self._make_candidate_from_link(
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/factory.py", line 188, in _make_candidate_from_link
    self._editable_candidate_cache[link] = EditableCandidate(
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 316, in __init__
    super().__init__(
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 161, in __init__
    self.dist = self._prepare()
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 230, in _prepare
    dist = self._prepare_distribution()
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/resolution/resolvelib/candidates.py", line 326, in _prepare_distribution
    return self._factory.preparer.prepare_editable_requirement(self._ireq)
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 543, in prepare_editable_requirement
    dist = _get_prepared_distribution(
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/operations/prepare.py", line 57, in _get_prepared_distribution
    abstract_dist.prepare_distribution_metadata(finder, build_isolation)
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py", line 45, in prepare_distribution_metadata
    self._install_build_reqs(finder)
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/distributions/sdist.py", line 114, in _install_build_reqs
    conflicting, missing = self.req.build_env.check_requirements(build_reqs)
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_internal/build_env.py", line 178, in check_requirements
    if req.marker is not None and not req.marker.evaluate():
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_vendor/packaging/markers.py", line 304, in evaluate
    return _evaluate_markers(self._markers, current_environment)
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_vendor/packaging/markers.py", line 234, in _evaluate_markers
    lhs_value = _get_env(environment, lhs.value)
  File "/Users/william/devel/sigstore-python/env/lib/python3.10/site-packages/pip/_vendor/packaging/markers.py", line 215, in _get_env
    raise UndefinedEnvironmentName(
pip._vendor.packaging.markers.UndefinedEnvironmentName: 'extra' does not exist in evaluation environment.

Code of Conduct

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:16 (12 by maintainers)

github_iconTop GitHub Comments

4reactions
pradyunsgcommented, May 12, 2022

Ah, indeed. I misunderstood that it was using setuptools’ experimental support for pyproject.toml, and wasn’t looking carefully. 😃

This is indeed a flit-specific issue. When it can’t figure out what the version of the package is (either by looking at version in pyproject.toml or looking for __version__ = <str> assignments in the top level module via AST), then it installs all the runtime dependencies to be able to import the package during the build: https://github.com/pypa/flit/blob/ec6e6b7c8994d5e79d0fd951d9e4c26a7c5d9977/flit_core/flit_core/buildapi.py#L35

This is happening because sigstore has an additional indirection for loading the version, for some reason, so a simple AST parse is not able to find the version.

So… the use case is significantly less disruptive – for packages that use flit, define extras and don’t want to maintain a static version in pyproject.toml or the module.py/module/__init__.py file.

3reactions
pfmoorecommented, May 12, 2022

At a minimum, flit could not include optional dependencies when generating the list of build dependencies, as they’ll be ignored anyway. But this should be discussed on the flit tracker, not here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to install a package using pip in editable mode with ...
Practically, one needs both the frontend and the backend. The only compliant backend I've been able to find so far is Flit. The...
Read more >
Release history — Flit 3.8.0 documentation
Fix for installing packages with flit install . Make requests_download an extra dependency, to avoid a circular build dependency. To use flit installfrom ......
Read more >
pipenv Documentation - Read the Docs
Automatically adds/removes packages to a Pipfile when they are installed or ... You can tell Pipenv to install a path as editable —...
Read more >
poetry-link - PyPI
Editable installs for packages developed with Poetry using Flit. ... This command makes use of the Flit backend to leverage its excellent symlink...
Read more >
Pip 19.1 and installing in editable mode with pyproject.toml
The convenience of this that of having build frontend, because it means I can use flit or poetry or setuptools as I see...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found