ensure
ensure copied to clipboard
Dry version
Make setup.py
the source of truth for version. I tried to use __init__.py
first, but the star imports won't work otherwise, so this one is the second best option. setup.py
is imported in conf.py
only and is guarded therefore it works with pip install -e .
and should even with the documentation.
Codecov Report
Merging #30 into master will not change coverage. The diff coverage is
n/a
.
@@ Coverage Diff @@
## master #30 +/- ##
=======================================
Coverage 90.25% 90.25%
=======================================
Files 3 3
Lines 513 513
=======================================
Hits 463 463
Misses 50 50
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 41dfd37...38a5a0e. Read the comment docs.
This PR, is merely delaying dealing with a complicated issue by applying a temporary bandaid.
Puts great faith in our ability to write valid semantic version strings, by hand, correctly every time. And ignores the current version from git / Mercurial. Which is the first source of truth. So what would that make setup.py
?
- Wishful thinking source of truth?
- Conspiracy theory source of truth cuz no one wants to go there?
- Boomer, whats
setup.py
?
setuptools-scm
is pulling the current version from git / Mercurial. During the process of creating a tagged release, these command gets setuptools-scm
to use a tagged/postrelease/prerelease version, rather that the full version from git
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_ENSURE="1.0.5a1.dev1" python setup.py --version
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_ENSURE="1.0.5a3.dev36" python -m build
ENSURE is the name of this project. To adapt for another project, capitalize and turn period and hypens into underscores
Both commands are necessary. The first tells setuptools-scm
to write _version.py
(add to .gitignore
) into the package and then build the whl and tarball.
Before this, highly recommend validating the version, Using packaging.version.Version
. It's too easy to make a mistake
Assuming Ensure embraces pyproject.toml and migrates from setup.py
, here is a working/documented/typed, setup.py
from __future__ import annotations
from setuptools import setup
from setuptools_scm import ScmVersion
from setuptools_scm.version import get_local_dirty_tag
def _clean_version() -> dict[str, str]:
"""scm is generating developer versions, rather than tagged versions
dict communicating between :menuselection:`setuptools_scm --> setuptools`
:returns: start folder relative path. e.g. tests/ui
:rtype: dict[str, str]
.. seealso::
`Credit <https://stackoverflow.com/q/73157896>`_
"""
def get_version(version: ScmVersion) -> str:
"""Get local scheme. Aka tagged version
:param version: Version as setuptools_scm grabs from vcs
:type version: :py:class:`setuptools_scm.ScmVersion`
:returns: local scheme
:rtype: str
"""
# str(version.tag)
return version.format_with("{tag}")
def clean_scheme(version: ScmVersion) -> str:
"""Full version from vcs
:param version: Version as setuptools_scm grabs from vcs
:type version: :py:class:`setuptools_scm.ScmVersion`
:returns: version scheme
:rtype: str
"""
return get_local_dirty_tag(version) if version.dirty else "+clean"
return {"local_scheme": get_version, "version_scheme": clean_scheme}
The above code deals with the thorny issue of a tagged/prerelease/postrelease vs full version
setuptools-scm
will auto-magically generate a _version.py
file within the package. A huge source of confusion is this version is being pulled from git (or mercurial). So how to get a tagged version?
git version would look like, 0.1.1a1.dev9+gdsafad-sadfsad tagged version should then look like 0.1.2 or 0.1.2a1 or 0.1.2post7 or 0.1.2b3 or 0.1.2rc4
The tagged version has the epoch (e.g. prepend 1!
) and local (e.g. gdsafad-sadfsad
) removed
>>> from packaging.version import Version
>>> v = Version("1!0.1.1a1.dev9+gdsafad-sadfsad")
>>> v.epoch
1
>>> v.major
0
>>> v.minor
1
>>> v.micro
1
>>> v.local
'gdsafad.sadfsad'
>>> v.pre
('a', 1)
>>> v.dev
9
>>> v.is_devrelease
True
>>> v.is_prerelease
True
>>> v.is_postrelease
False
>>> v_fix = Version("0.1.1a1dev9")
>>> v_fix
<Version('0.1.1a1.dev9')>
>>> v_fix = Version("0.1.1.a1dev9")
>>> v_fix
<Version('0.1.1a1.dev9')>
^^^ that's more like it!
Look at those beautiful validated fixed version strings. Can totally imagine making these mistakes, every single time.
An excellent project to reference, pycoverage. It'll give a good starting point or perhaps maybe it's good enough
Let history decide. Should version strings be hardcoded or should use packages which were made to address this exact issue, setuptools-scm?
@KeyWeeUsr thank you for your PR and apologies for the delay in reviewing it, and for the noise in the comments.
I will close this now, as this package will be migrated to use setuptools_scm to manage its version at the earliest opportunity.