pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.54k stars 1.19k forks source link

[BUG] _load_raw method of class PthDistributions has an issue from version 67.8.0 #4731

Open morganw opened 3 weeks ago

morganw commented 3 weeks ago

setuptools version

setuptools==67.8.0

Python version

Python3.11

OS

macOS

Additional environment information

No response

Description

just upgrade my python package with python setup.py install. but find that still link to old version package and find that the version was not deleted from easy-install.pth

looks like setuptools==67.7.2 is ok, but from setuptools==67.8.0, there is an issue in _load_raw method of class PthDistributions:

normalized_path = normalize_path(os.path.join(self.basedir, path)

it maybe should is paths[-1]=normalized_path = normalize_path(os.path.join(self.basedir, path))

the paths is not full path, so, there will be an issue in below find_distributions:

self.paths, self.dirty = self._load() self._init_paths = self.paths[:] super().init([], None, None) for path in yield_lines(self.paths): list(map(self.add, find_distributions(path, True)))

Expected behavior

when upgrade the package, the previous version should be remove from easy-install.pth and can link to the current version

How to Reproduce

  1. create a python package with version 1.0.27
  2. install it with python setup.py install
  3. change version to 1.0.28
  4. upgrade it with python setup.py install
  5. check if upgrade success, should have below message, if not, looks like upgrade failed. Copying test_cli-1.0.28-py3.9.egg to /usr/local/lib/python3.9/site-packages Removing test-cli 1.0.27 from easy-install.pth file Adding test-cli 1.0.28 to easy-install.pth file

Output

Copying test_cli-1.0.28-py3.9.egg to /usr/local/lib/python3.9/site-packages Removing test-cli 1.0.27 from easy-install.pth file Adding test-cli 1.0.28 to easy-install.pth file

abravalheri commented 3 weeks ago

Hi @morganw, please note that any easy-install solution or python setup.py XXX CLI commands, are deprecated and no longer receive first class support.

The recommended approach is as follows:

  1. Please make sure you have updated the package source code to include a pyproject.toml file with a [build-system] table, as documented in the user guide.
    • Note that you need to list all your build dependencies in the [build-system] requires field (e.g. if you use any non-stdlib library in your setup.py script.
    • Please also note that if you need to import your local folders in your setup.py script then you also need to manually add the local folder to sys.path or use build-backend = "setuptools.build_meta:__legacy__"
  2. Please use pip>=23 to install your package using pip install .

There is a old blog post with some extra details about the deprecation https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html.