pip: Wrong version detection with setuptools_scm, `pip install .` and hg-git

Description

I try to install a package (https://github.com/exabl/snek5000) with pip install -e . cloned with Mercurial and hg-git.

This package uses setuptools_scm to detect its version. setuptools_scm now supports using Mercurial as a Git client and provides the right version when using the commands python setup.py develop and pip install -e . --no-build-isolation.

However, if I just use pip install -e ., the package is correctly installed but the detected version is completely wrong.

Expected behavior

No response

pip version

pip 21.3.1

Python version

CPython 3.9

OS

Linux

How to Reproduce

With Mercurial setup to work with hg-git

hg clone git@github.com:exabl/snek5000.git
cd snek5000
pip install -e .

Output

No response

Code of Conduct

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 19 (12 by maintainers)

Commits related to this issue

Most upvoted comments

I try to summarize. I think this issue is now quite well understood.

It is related to the custom isolation used by pip and to the sensibility of (at least some) Mercurial installations to environment variables like PYTHONPATH and PYTHONNOUSERBASE.

The solutions could be:

  1. Improve Mercurial in terms of ignoring Python specific environment variables. I don’t know at which level it should be done. I guess it depends somehow on the installation method. Even if the next version of Mercurial is improved, the issue will continue to be there for most users since people tend to use quite old versions of hg.

  2. Implement the Mercurial isolation at the setuptools_scm level, i.e. remove PYTHONNOUSERBASE and clean PYTHONPATH for the environment used to call hg. It’s technically very simple (I can even submit a PR) and could also work with other installation tools for installation using setuptools_scm.

  3. Use internally in pip a proper virtual environment created with venv --without-pip (no need to use/change PYTHONNOUSERBASE and PYTHONPATH). It would fix other similar problems, in particular for other Python applications used during build. It would not fix the problem for other install tools, except if there is also a pep on “expectations for how tools set up the build environment”.