mtkennerly / poetry-dynamic-versioning

Plugin for Poetry to enable dynamic versioning based on VCS tags
MIT License
588 stars 36 forks source link

Whl files generated by poetry build do not contain the static version files specific in substitiution #163

Closed vancromy closed 6 months ago

vancromy commented 6 months ago

Hello,

I have a use case where I do not want to git track my version file and instead want it to be generated on install (regardless of whether poetry or pip are used). If I run poetry install the desired _version.py file is created and has the correct version. But if I run pip install path-to-poetry-built-wheel.whl that file is not created and I get import issues in my package. I have also unzipped the poetry generated wheel file and cannot find the _version.py file in the wheel.

I installed the plugin with poetry self add ... and here is my pyproject.toml file:

[tool.poetry]
name = "random-package"
version = "0.0.0"
readme = "README.md"
packages = [
  {include = "random", from = "src"},
]

[tool.poetry.dependencies]
python = ">=3.9,<4.0"

[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"

[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
latest-tag = true
style = "semver"
pattern = "default-unprefixed"

[tool.poetry-dynamic-versioning.substitution]
files = ["src/random/pacakge/_version.py"]

[tool.poetry-dynamic-versioning.files."src/random/package/_version.py"]
persistent-substitution = true
initial-content = """
  # These version placeholders will be replaced later during substitution.
  __version__ = "0.0.0"
  __version_tuple__ = (0, 0, 0)
"""
mtkennerly commented 6 months ago

I have also unzipped the poetry generated wheel file and cannot find the _version.py file in the wheel.

I'm not able to reproduce that behavior. I see the generated file in the wheel, and the wheel's RECORD file also has an entry for it.

I'm using Poetry 1.5.1 and Python 3.10.7 on Windows 11. What's your environment?

I installed the plugin with poetry self add ...

Just to confirm, did you specify the [plugin] feature? (poetry self add "poetry-dynamic-versioning[plugin]")

vancromy commented 6 months ago

Hi @mtkennerly, thanks for the quick reply.

I am running macOS 14.2.1 (BuildVersion 23C71) and using pyenv installed python version 3.11.5, poetry version 1.7.1.

Yes I installed with the [plugin] extra. Here's the output of poetry self show poetry-dynamic-versioning:

Poetry show output name : poetry-dynamic-versioning version : 1.2.0 description : Plugin for Poetry to enable dynamic versioning based on VCS tags dependencies - dunamai >=1.18.0,<2.0.0 - jinja2 >=2.11.1,<4 - poetry >=1.2.0,<2.0.0 - tomlkit >=0.4

I just reproed it with the same config as above. The _version.py file is created after a poetry install but does not exist in the built wheels. I used poetry build --format wheel to generate the wheel file. See attached screenshot: image

vancromy commented 6 months ago

Ah! After a bit of debugging I realised this was due to the fact that I am gitignoring the file and since I did not add it via the include keyword in the tool.poetry section, it wasn't making it into the build. Could be this is a novice mistake from me but it may be worth having a short note about this in the README?

mtkennerly commented 6 months ago

Good catch! I've added a note to the README.