pypa / pypa/setuptools

Version "attr" method in setup.py builds dist names incorrectly

Open
#2,492 4 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

Hello,

Currently, the "Single-sourcing the package version" page provides several methods for storing a package's version in one location. The first includes a "modern" technique as of setuptools 46.4.0, describing this mechanism for use in setup.cfg:

[metadata]
version = attr: package.__version__

I was pleasantly surprised to find the setuptools.setup() call would also accept (read: not halt in an error state) this string in its version= parameter. However, I found none of the distribution files build with the correct name embedded.

I have set up a repository to test this issue here.

Setup

Given a package example_pkg, the setup.py program includes these lines:

setuptools.setup(
    name="example_pkg",
    version="attr: example_pkg.__version__",
  # ...
)

A wheel is built with this command:

python3 setup.py bdist_wheel

Expected output

I expect the generated file to be dist/example_pkg-0.0.1-py3-none-any.whl. This is the effect when the setup() call is written like this:

setuptools.setup(
    name="example_pkg",
    version="0.0.1",
  # ...
)

Current output

The output file is currently errantly named dist/example_pkg-attr_.example_pkg._version_-py3-none-any.whl.

Reproduction instructions

  1. Clone the above linked repository.
  2. Run make. The errant file is in the directory using_setup_py/dist. A functioning example of the same version retrieval syntax is in using_setup_cfg/.

As a last comment, it seems a bit ironic that the configuration file currently has more programmatic access to code variables than the setup script. Shouldn't these two methods behave the same? Or, is there a specification somewhere I've missed?

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 by cloning the linked reproduction repository and running make; compare using_setup_py/ with the functioning using_setup_cfg/ example, especially their setup.py and setup.cfg files. Reproduce the wheel built by python3 setup.py bdist_wheel and trace why its filename differs from the expected example_pkg-0.0.1-py3-none-any.whl; done means the setup.py version form produces the correct distribution name.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.