pypa / setuptools-scm

the blessed package to manage your versions by scm tags
https://setuptools-scm.readthedocs.io/en/latest/
MIT License
860 stars 211 forks source link

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

Open bhrutledge opened 5 years ago

bhrutledge commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

python -m setuptools_scm pypi_check?

Also, I forgot that this was already under consideration in https://github.com/pypa/twine/issues/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").