Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent versionning from git tags #483

Closed
oiesauvage opened this issue Aug 10, 2021 · 7 comments · Fixed by #491
Closed

Inconsistent versionning from git tags #483

oiesauvage opened this issue Aug 10, 2021 · 7 comments · Fixed by #491
Labels
bug Something isn't working
Milestone

Comments

@oiesauvage
Copy link

Description of your problem

I use pyscaffold for several Python projects (amazing work btw!). On one of them with pyscaffold 4.0.2, I am building with tox -e build and generate sphinx documentation with tox -e docs with theme from readthedocs. The version infered from commit tag is OK for the build, but never for the documentation build: the displayed version on the html page is always 0.0.0.
Besides, when I type python setup.py --version the result is correct, but when doing the following in the Python console:

from mypackage import __version__ as version
print(version)

The result is also falling back to 0.0.0.

Describe the solution you would like to see for your use-case

Replace in generated setup.py:

setup(
            use_scm_version={"version_scheme": "no-guess-dev"}
        )

by:

setup(
            use_scm_version={"version_scheme": "no-guess-dev"},
            setup_requires=["setuptools_scm"],
        )

In my case, it solves the issue. It seems to be the way to go in setuptools_scm documentation.

Versions and main components

  • PyScaffold Version: 4.0.2
  • Python Version: 3.8.10
  • Operating system: Ubuntu 20.04.2.0 LTS
  • How did you install PyScaffold: conda
@abravalheri
Copy link
Collaborator

abravalheri commented Aug 10, 2021

Thank you for reporting the issue @oiesauvage.

In the past, we did include a setup_requires in the setup.py file, however, when we adopted pyproject.toml it started to cause problems because the dependency resolution algorithm seemed to be unreliable when both things were in place. The PyPA maintainers explicitly recommended to not use setup_requires with pyproject.toml. You can see the discussion in pypa/pyproject-hooks#86.

Can I ask you a few extra questions about this issue?

  • Does the documentation also show 0.0.0 when building it with tox -e docs and cleaning the cache in docs/_build?
  • If you do a git tag and run pip install -e . again inside your virtual environment, does the print(version) still return 0.0.0? (It might be the case setuptools_scm is just caching the version at the moment you run pip install -e . ...)

@abravalheri
Copy link
Collaborator

abravalheri commented Aug 10, 2021

Could you also try to add

isolated_build = True

to tox.ini?

I suspect that it might be the most correct way to solve this issue (but potentially increase the time to run tox).

Alternatively, I wonder if adding setuptools-scm to docs/requirements.txt also solves the problem...

@oiesauvage
Copy link
Author

Thank you for your answer @abravalheri :-)

I tried your suggestions:

  • what do you mean exactly by "cleaning the cache in docs/_build "? I tried tox -e clean but no success.
  • pip install -e . solves the issue for print(version) but not for generated documentation pages.
  • isolated_build = True in tox.ini solves the problem for docs and seems indeed the way to go.
  • adding setuptools-scm to docs/requirements.txt does nothing in my case.

@abravalheri
Copy link
Collaborator

Thanks @oiesauvage for the feedback and for trying these things out.

docs/_build holds the Sphinx docs cache... For simplicity, tox -e clean is not removing those, just the intermediate steps to build the package distribution file.

So it seems that isolated_build = True is the answer...
I feel like it makes the build a bit slower, but if it is less error prone, maybe we should adopt it. @FlorianWilhelm what would it be your take on this?


I did a few extra tests myself by generating a fresh project from the master version of PyScaffold, with putup myproj.

If I create a git tag, before running tox -e docs, then the version in the docs are generated correctly.

Once I create a new tag and try to run tox -e docs again, the docs show the previous version, To fix it I need to run tox -r -e docs to recreate the virtualenv created by tox.

It might be related to the fact that currently we have usedevelop = True to speed up the tox task, and it seems that setuptools-scm requires a new installation once a new git tag is created.

@oiesauvage
Copy link
Author

@abravalheri alright, i tried deleting docs/_build without results. Besides, I did not feel a major slowdown with isolated_build = True on my project (I did not timed it though), but it may depend of your required dependencies...

@FlorianWilhelm
Copy link
Member

Interesting @abravalheri. From the docs it seems that isolated_build = True tells tox to look at pyproject.toml. If this makes it work and since we want to move forward to more pyproject.toml anyway, I might be a good further step to make it a default. Maybe even in version 4.1 already?

@FlorianWilhelm FlorianWilhelm added the bug Something isn't working label Aug 12, 2021
@FlorianWilhelm FlorianWilhelm added this to the v4.1 milestone Sep 4, 2021
@FlorianWilhelm
Copy link
Member

@abravalheri, I set this as part of the v4.1 release. Feel free to remove if you don't agree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants