pypa / setuptools

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

[BUG] dynamic versioning fails to solve dependencies because of off topic error message #4285

Closed fenchu closed 1 month ago

fenchu commented 1 month ago

setuptools version

69.2.0

Python version

3.12.2

OS

windows11

Additional environment information

No response

Description

this pyproject.toml file works:

[build-system]
build-backend = 'setuptools.build_meta'
requires = ["setuptools>=69.2.0"]

[project]
name = "report"
version = "0.95"
description = "dgasdgasdgasdgasdgasdgasdgasdgsadgsadgsadg"
authors = [
    { name = "Morten Bjoernsvik", email = "mobj@buypass.no" },
]

readme = "README.md"
requires-python = ">=3.6"

dependencies = [
    "ansi2html>=1.8.0"
]

[tool.setuptools]
include-package-data = true
packages = ["report"]

[tool.setuptools.package-data]
report = ["dat/*.dat", "test/*"]

[project.scripts]
report-html = "report.report:main"

[project.urls]
Homepage = "dfasdfasfasdfasdfasdfasdgasdgasdg"

But when I try to add dynamic versioning from report.VERSION it looks like this:

[build-system]
build-backend = 'setuptools.build_meta'
requires = ["setuptools>=69.2.0"]

[tool.setuptools.dynamic]
version = {attr = "report.__version__"}

[project]
name = "report"
dynamic = ["version"]
description = "asdgasdgasdgasdgasdgasdgasdgasdgasdg"
authors = [
    { name = "Morten Bjoernsvik", email = "mobj@buypass.no" },
]

readme = "README.md"
requires-python = ">=3.6"

dependencies = [
    "ansi2html>=1.8.0"
]

[tool.setuptools]
include-package-data = true
packages = ["report"]

[tool.setuptools.package-data]
report = ["dat/*.dat", "test/*"]

[project.scripts]
report-html = "report.report:main"

[project.urls]
Homepage = "sdfasdfasdfasdfasdgasdgasdgasdgasdg"

I get this error:

pip install git+https:/xxx/testtools/report
:
        File "C:\Users\mobj\AppData\Local\Temp\pip-req-build-fu3n8ifp\report\report.py", line 5, in <module>
          from ansi2html import Ansi2HTMLConverter
      ModuleNotFoundError: No module named 'ansi2html'
      [end of output]

So how should we use dynamic loading, I want to set the version once not two places.

Expected behavior

If I do not use dynamic it works fine

pip install git+https:/xxx/testtools/report
Collecting git+https://xxx/testtools/report
  Cloning https://xxx/testtools/report to c:\users\mobj\appdata\local\temp\pip-req-build-ijkps_ob
  Running command git clone --filter=blob:none --quiet https://xxx/testtools/report 'C:\Users\mobj\AppData\Local\Temp\pip-req-build-ijkps_ob'
  warning: redirecting to https://xxx/testtools/report.git/
  Resolved https://xxx/testtools/report to commit c56da01c2a893f2629c81f7cbc4f3fd38f2ab25a
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: ansi2html>=1.8.0 in c:\dist\venvs\report\lib\site-packages (from report==0.95) (1.9.1)

How to Reproduce

pip install git+https:/xxx/testtools/report with the dynamic version of pyproject.toml

Output

pip install git+https:/xxx/testtools/report
:
        File "C:\Users\mobj\AppData\Local\Temp\pip-req-build-fu3n8ifp\report\report.py", line 5, in <module>
          from ansi2html import Ansi2HTMLConverter
      ModuleNotFoundError: No module named 'ansi2html'
      [end of output]

I can add some feature in my module so the VERSION reads the pyproject.toml file :-)

fenchu commented 1 month ago

I do not have a __init__.py So I expected it to pick up directly from the module:

>>> import report
>>> report.report.__version__
0.96

so changing it to:

[tool.setuptools.dynamic]
version = {attr = "report.report.__version__"}

fixed it.

But the error message and stacktrace is totaly confusing. something like unavle to pick up version would be much saner than this unable to install module