pypa / pypa/setuptools

read_configuration() reports wrong version if different version of package has already been imported

Open
#2,575 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

Consider a minimal Python project that uses the attr: directive to set its version, like so:

mymodule.py:

__version__ = "0.1.0"

setup.py:

from setuptools import setup
setup()

setup.cfg:

[metadata]
name = mymodule
version = attr:mymodule.__version__

[options]
py_modules = mymodule

If this project is installed in the current environment, and then the __version__ string in the source is changed to a new value, running the following (from a directory other than the one in which mymodule.py is located) will return the version of the installed project rather than the version in the source:

>>> import mymodule
>>> from setuptools.config import read_configuration
>>> read_configuration("path/to/setup.cfg")["metadata"]["version"]
'0.1.0'

This bug affects me because my package-releasing project makes use of read_configuration() while also depending on some of the same projects that it's used to manage & produce releases for, resulting in the wrong version being determined for those projects whenever I try to make a new release.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal project described in mymodule.py, setup.py, and setup.cfg, then reproduce the behavior through setuptools.config.read_configuration() after importing mymodule from the installed environment. Trace how the attr: version is resolved; done means read_configuration() returns the version from the specified source project rather than an already-imported installed package.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.