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

Add console_scripts entry point for "checking" the version? #365

Open
bhrutledge opened this issue Oct 20, 2019 · 4 comments
Open

Add console_scripts entry point for "checking" the version? #365

bhrutledge opened this issue Oct 20, 2019 · 4 comments

Comments

@bhrutledge
Copy link

Hi there! Thanks for making this. I'm setting up a new project, and I've found it very useful to offload the version management.

I've made a rudimentary release pipeline with tox:

[testenv:release]
description =
    Upload distribution to TestPyPI after building and checking.
    For PyPI, run `tox -e release pypi`.
basepython = python3
skip_install = true
deps =
    wheel
    twine
    setuptools_scm
    keyring
whitelist_externals =
    rm
commands =
    rm -rf build dist
    python setup.py sdist bdist_wheel
    twine check dist/*
    python check_version.py
    twine upload --repository {posargs:testpypi} dist/*

And the contents of check_version.py is:

import sys

from setuptools_scm import get_version

version = get_version()
print("Version: " + version)

if "+" in version:
    sys.exit(
        "ERROR: Invalid version. "
        "Make sure the working tree is clean, then tag a new version."
    )

Could something like check_version be implemented in setuptools_scm?

It's somewhat overkill, because PyPI will reject PEP-440 local versions, but I thought it'd be nice to abort before that step.

@RonnyPfannschmidt
Copy link
Contributor

currently this is already exposed via multiple entry-points that do not require creating a script

the old setuptools integration features python setup.py --version

a main entry-point is exposed for python -m setuptools_scm

both of those don't do the local version check (its something i actually avoid in my release pipelines)
but i do believe its fine to add something like that to the setuptools_scm entry-point

would you like to propose a pr and/or the exact semantics you'd like to see?

@bhrutledge
Copy link
Author

Thanks!

I see that __main__.py already has an ls subcommand. What about something like this?

python -m setuptools_scm check

And maybe something like this in entry_points?

[console_scripts]
scm_version = setuptools_scm.__main__:main

Also, I discovered that Warehouse uses packaging.version to invalidate local versions; I'm inclined do the same.

Finally, if you don't mind, why do you avoid the local version check?

@RonnyPfannschmidt
Copy link
Contributor

i do use devpi and there local versions are fine
in addition my release pipeline that does pypi only happens on tags or specific commands that do the

the command should be named like something that clearly indicates a check for pypi uploadability

@bhrutledge
Copy link
Author

python -m setuptools_scm pypi_check?

Also, I forgot that this was already under consideration in pypa/twine#430. Happy to consider implementing it there, although adding it here would make it useful for other uploaders (e.g. Poetry) and allow for a clearer course of action (e.g. "clean your working tree").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants