♻️ Replace versioneer with a custom tool
Instead of customizing an existing tool that does a lot of stuff that we don't need but lacks what we DO need (branch based virtual tags), now there's a custom single file implementation that mixes concepts from versioneer, miniver and the lookup that so far was implemented in OctoPrint's custom build of versioneer, and does so with less overhead. Closes #4685
This commit is contained in:
1 parent
aba8d21e75
commit
579bfccb2c
14 files changed
+390
-3087
No files matched your search
@@ -5,6 +5,5 @@ src/octoprint/static/less/bootstrap/* linguist-vendored
|
||||
src/octoprint/static/less/font-awesome.less linguist-vendored
|
||||
src/octoprint/static/less/mixins.less linguist-vendored
|
||||
src/octoprint/static/less/variables.less linguist-vendored
|
||||
versioneer.py linguist-vendored
|
||||
|
||||
docs/* linguist-documentation
|
||||
@@ -14,13 +14,13 @@ repos:
|
||||
- id: check-merge-conflict
|
||||
- id: fix-encoding-pragma
|
||||
args: ["--remove"]
|
||||
exclude: "setup.py|versioneer.py|src/octoprint_setuptools/__init__.py"
|
||||
exclude: "setup.py|src/octoprint_setuptools/__init__.py"
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v3.3.1
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: ["--py37-plus"]
|
||||
exclude: "setup.py|versioneer.py|src/octoprint_setuptools/__init__.py"
|
||||
exclude: "setup.py|src/octoprint_setuptools/__init__.py"
|
||||
- repo: https://github.com/OctoPrint/codemods
|
||||
rev: "0.6.3"
|
||||
hooks:
|
||||
@@ -36,8 +36,6 @@ repos:
|
||||
"--ignore",
|
||||
"setup.py",
|
||||
"--ignore",
|
||||
"versioneer.py",
|
||||
"--ignore",
|
||||
"src/octoprint_setuptools/__init__.py"
|
||||
]
|
||||
- repo: https://github.com/pre-commit/mirrors-isort
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
# Configuration file for the versioneer lookup, manually mapping tags based on branches
|
||||
#
|
||||
# Format is
|
||||
#
|
||||
# <branch-regex> <tag> <reference commit>
|
||||
#
|
||||
# The file is processed from top to bottom, the first matching line wins. If <tag> or <reference commit> are left out,
|
||||
# the lookup table does not apply to the matched branches
|
||||
|
||||
# master, meta, rc and prerelease shall not use the lookup table, only tags
|
||||
master
|
||||
meta/.*
|
||||
rc/.*
|
||||
hotfix/.*
|
||||
prerelease
|
||||
|
||||
# neither should disconnected checkouts, e.g. 'git checkout <tag>'
|
||||
HEAD
|
||||
\(detached.*
|
||||
|
||||
# maintenance is currently the branch for preparation of maintenance release 1.10.0
|
||||
# so are any fix/... and improve/... branches
|
||||
maintenance 1.10.0 cd955e9a46782119b36cc22b8dea5652ebbf9774 pep440-dev
|
||||
fix/.* 1.10.0 cd955e9a46782119b36cc22b8dea5652ebbf9774 pep440-dev
|
||||
improve/.* 1.10.0 cd955e9a46782119b36cc22b8dea5652ebbf9774 pep440-dev
|
||||
|
||||
# staging/bugfix is the branch for preparation of the 1.9.x bugfix releases
|
||||
# so are any bug/... branches
|
||||
staging/bugfix 1.9.3 f027aaa7300f70b046525a49245b33c43dd198c1 pep440-dev
|
||||
bug/.* 1.9.3 f027aaa7300f70b046525a49245b33c43dd198c1 pep440-dev
|
||||
|
||||
# staging/maintenance is currently the branch for preparation of 1.9.0rc7
|
||||
# so is regressionfix/...
|
||||
staging/maintenance 1.9.0rc7 9ba981a2ea789030927fc49b6ad166bc68f6b5f9 pep440-dev
|
||||
regressionfix/.* 1.9.0rc7 9ba981a2ea789030927fc49b6ad166bc68f6b5f9 pep440-dev
|
||||
|
||||
# staging/devel is currently inactive (but has the 1.4.1rc4 namespace)
|
||||
staging/devel 1.4.1rc4 650d54d1885409fa1d411eb54b9e8c7ff428910f pep440-dev
|
||||
|
||||
# every other branch is a development branch and thus gets resolved to 2.0.0.dev for now
|
||||
.* 2.0.0 2da7aa358d950b4567aaab8f18d6b5779193e077 pep440-dev
|
||||
+1
-1
@@ -3,8 +3,8 @@ recursive-include src/octoprint/templates *
|
||||
recursive-include src/octoprint/plugins *
|
||||
recursive-include src/octoprint/translations *
|
||||
include src/octoprint/util/piptestballoon/setup.py
|
||||
include versioneer.py
|
||||
include src/octoprint/_version.py
|
||||
include src/octoprint/_static_version.py
|
||||
include requirements.txt
|
||||
include *.md
|
||||
exclude CODE_OF_CONDUCT.md
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ copyright = (
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = octoprint._version.get_versions()["version"]
|
||||
version = octoprint.__version__
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = version
|
||||
|
||||
|
||||
@@ -72,4 +72,4 @@ Those usually have one of the following prefixes:
|
||||
There are also a few older development branches that are slowly being migrated or deleted.
|
||||
|
||||
All these branches and branch patterns are set up to automatically get a correct :ref:`version number <sec-development-versions>`
|
||||
generated through versioneer and thus should also be adhered to during development.
|
||||
generated through a custom versioning tool and thus should also be adhered to during development.
|
||||
@@ -16,12 +16,11 @@ backwards compatibility on the documented APIs (both internal and external). Exa
|
||||
Finally, the **MAJOR** version number increases if there are breaking API changes that concern any of the
|
||||
documented interfaces (REST API, plugin interfaces, ...). Example: ``1.x.y`` to ``2.0.0``.
|
||||
|
||||
OctoPrint's version numbers are automatically generated using a customized version of
|
||||
`versioneer <https://github.com/warner/python-versioneer>`_ and depend on the selected git branch, nearest
|
||||
git tag and commits. Unless a git tag is used for version number determination, the version number will
|
||||
also contain the git hash within the local version identifier to allow for an exact determination of the
|
||||
active code base (e.g. ``1.2.9.dev68+g46c7a9c``). Additionally, instances with active uncommitted changes
|
||||
will contain ``.dirty`` in the local version identifier.
|
||||
OctoPrint's version numbers are automatically generated using a custom versioning tool and depend on
|
||||
the selected git branch, nearest git tag and commits. Unless a git tag is used for version number
|
||||
determination, the version number will also contain the git hash within the local version identifier to
|
||||
allow for an exact determination of the active code base (e.g. ``1.2.9.dev68+g46c7a9c``). Additionally,
|
||||
instances with active uncommitted changes will contain ``.dirty`` in the local version identifier.
|
||||
|
||||
.. rubric:: Footnotes
|
||||
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
[metadata]
|
||||
license_file = LICENSE.txt
|
||||
license_files = LICENSE.txt
|
||||
|
||||
[bdist_wheel]
|
||||
universal = 1
|
||||
|
||||
[versioneer]
|
||||
VCS = git
|
||||
style = pep440-tag
|
||||
versionfile_source = src/octoprint/_version.py
|
||||
versionfile_build = octoprint/_version.py
|
||||
tag_prefix =
|
||||
parentdir_prefix =
|
||||
lookupfile = .versioneer-lookup
|
||||
|
||||
[flake8]
|
||||
max-line-length = 90
|
||||
extend-ignore = E203, E231, E265, E266, E402, E501, E731, B023, B903, B904, B907, B950, W503
|
||||
|
||||
@@ -13,8 +13,6 @@ import sys
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
from distutils.command.build_py import build_py as _build_py
|
||||
|
||||
import setuptools # noqa: F401,E402
|
||||
|
||||
try:
|
||||
@@ -22,8 +20,6 @@ try:
|
||||
except ImportError:
|
||||
octoprint_setuptools = None
|
||||
|
||||
import versioneer # noqa: F401
|
||||
|
||||
# ----------------------------------------------------------------------------------------
|
||||
|
||||
# Supported python versions
|
||||
@@ -251,11 +247,23 @@ class ScanDepsCommand(setuptools.Command):
|
||||
print_update(update)
|
||||
|
||||
|
||||
def get_cmdclass():
|
||||
# make sure these are always available, even when run by dependabot
|
||||
global versioneer, octoprint_setuptools, md_to_html_build_py_factory
|
||||
def get_version_and_cmdclass(pkg_path):
|
||||
import os
|
||||
from importlib.util import module_from_spec, spec_from_file_location
|
||||
|
||||
cmdclass = versioneer.get_cmdclass()
|
||||
spec = spec_from_file_location("version", os.path.join(pkg_path, "_version.py"))
|
||||
module = module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
data = module.get_data()
|
||||
return data["version"], module.get_cmdclass(pkg_path)
|
||||
|
||||
|
||||
def get_cmdclass(cmdclass):
|
||||
# make sure these are always available, even when run by dependabot
|
||||
global octoprint_setuptools, md_to_html_build_py_factory
|
||||
|
||||
from setuptools.command.build_py import build_py as _build_py
|
||||
|
||||
if octoprint_setuptools:
|
||||
# add clean command
|
||||
@@ -289,7 +297,7 @@ def get_cmdclass():
|
||||
"THIRDPARTYLICENSES.md",
|
||||
]
|
||||
},
|
||||
cmdclass["build_py"] if "build_py" in cmdclass else _build_py,
|
||||
cmdclass.get("build_py", _build_py),
|
||||
)
|
||||
|
||||
cmdclass["scan_deps"] = ScanDepsCommand
|
||||
@@ -313,86 +321,67 @@ def package_data_dirs(source, sub_folders):
|
||||
return dirs
|
||||
|
||||
|
||||
def params():
|
||||
# make sure these are always available, even when run by dependabot
|
||||
global versioneer, get_cmdclass, read_file_contents, here, PYTHON_REQUIRES, SETUP_REQUIRES, INSTALL_REQUIRES, EXTRA_REQUIRES
|
||||
|
||||
name = "OctoPrint"
|
||||
version = versioneer.get_version()
|
||||
cmdclass = get_cmdclass()
|
||||
|
||||
description = "The snappy web interface for your 3D printer"
|
||||
long_description = read_file_contents(os.path.join(here, "README.md"))
|
||||
long_description_content_type = "text/markdown"
|
||||
|
||||
python_requires = PYTHON_REQUIRES
|
||||
setup_requires = SETUP_REQUIRES
|
||||
install_requires = INSTALL_REQUIRES
|
||||
extras_require = EXTRA_REQUIRES
|
||||
|
||||
classifiers = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Environment :: Web Environment",
|
||||
"Framework :: Flask",
|
||||
"Intended Audience :: Developers",
|
||||
"Intended Audience :: Education",
|
||||
"Intended Audience :: End Users/Desktop",
|
||||
"Intended Audience :: Manufacturing",
|
||||
"Intended Audience :: Other Audience",
|
||||
"Intended Audience :: Science/Research",
|
||||
"License :: OSI Approved :: GNU Affero General Public License v3",
|
||||
"Natural Language :: English",
|
||||
"Natural Language :: German",
|
||||
"Operating System :: OS Independent",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: JavaScript",
|
||||
"Topic :: Printing",
|
||||
"Topic :: System :: Monitoring",
|
||||
]
|
||||
author = "Gina Häußge"
|
||||
author_email = "gina@octoprint.org"
|
||||
url = "https://octoprint.org"
|
||||
license = "GNU Affero General Public License v3"
|
||||
keywords = "3dprinting 3dprinter 3d-printing 3d-printer octoprint"
|
||||
|
||||
project_urls = {
|
||||
"Community Forum": "https://community.octoprint.org",
|
||||
"Bug Reports": "https://github.com/OctoPrint/OctoPrint/issues",
|
||||
"Source": "https://github.com/OctoPrint/OctoPrint",
|
||||
"Funding": "https://support.octoprint.org",
|
||||
}
|
||||
|
||||
packages = setuptools.find_packages(where="src")
|
||||
package_dir = {
|
||||
"": "src",
|
||||
}
|
||||
package_data = {
|
||||
"octoprint": package_data_dirs(
|
||||
"src/octoprint", ["static", "templates", "plugins", "translations"]
|
||||
)
|
||||
+ ["util/piptestballoon/setup.py"]
|
||||
}
|
||||
|
||||
include_package_data = True
|
||||
zip_safe = False
|
||||
|
||||
if os.environ.get("READTHEDOCS", None) == "True":
|
||||
# we can't tell read the docs to please perform a pip install -e .[docs], so we help
|
||||
# it a bit here by explicitly adding the docs dependencies
|
||||
install_requires = install_requires + extras_require["docs"]
|
||||
|
||||
entry_points = {"console_scripts": ["octoprint = octoprint:main"]}
|
||||
|
||||
return locals()
|
||||
|
||||
|
||||
setuptools.setup(**params())
|
||||
if __name__ == "__main__":
|
||||
version, cmdclass = get_version_and_cmdclass("src/octoprint")
|
||||
setuptools.setup(
|
||||
name="OctoPrint",
|
||||
version=version,
|
||||
cmdclass=get_cmdclass(cmdclass),
|
||||
description="The snappy web interface for your 3D printer",
|
||||
long_description=read_file_contents(os.path.join(here, "README.md")),
|
||||
long_description_content_type="text/markdown",
|
||||
python_requires=PYTHON_REQUIRES,
|
||||
setup_requires=SETUP_REQUIRES,
|
||||
install_requires=INSTALL_REQUIRES,
|
||||
extras_require=EXTRA_REQUIRES,
|
||||
classifiers=[
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Environment :: Web Environment",
|
||||
"Framework :: Flask",
|
||||
"Intended Audience :: Developers",
|
||||
"Intended Audience :: Education",
|
||||
"Intended Audience :: End Users/Desktop",
|
||||
"Intended Audience :: Manufacturing",
|
||||
"Intended Audience :: Other Audience",
|
||||
"Intended Audience :: Science/Research",
|
||||
"License :: OSI Approved :: GNU Affero General Public License v3",
|
||||
"Natural Language :: English",
|
||||
"Natural Language :: German",
|
||||
"Operating System :: OS Independent",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 3",
|
||||
"Programming Language :: Python :: 3.7",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: 3.11",
|
||||
"Programming Language :: Python :: 3.12",
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Programming Language :: JavaScript",
|
||||
"Topic :: Printing",
|
||||
"Topic :: System :: Monitoring",
|
||||
],
|
||||
author="Gina Häußge",
|
||||
author_email="gina@octoprint.org",
|
||||
url="https://octoprint.org",
|
||||
license="GNU Affero General Public License v3",
|
||||
keywords="3dprinting 3dprinter 3d-printing 3d-printer octoprint",
|
||||
project_urls={
|
||||
"Community Forum": "https://community.octoprint.org",
|
||||
"Bug Reports": "https://github.com/OctoPrint/OctoPrint/issues",
|
||||
"Source": "https://github.com/OctoPrint/OctoPrint",
|
||||
"Funding": "https://support.octoprint.org",
|
||||
},
|
||||
packages=setuptools.find_packages(where="src"),
|
||||
package_dir={"": "src"},
|
||||
package_data={
|
||||
"octoprint": package_data_dirs(
|
||||
"src/octoprint", ["static", "templates", "plugins", "translations"]
|
||||
)
|
||||
+ ["util/piptestballoon/setup.py"]
|
||||
},
|
||||
include_package_data=True,
|
||||
zip_safe=False,
|
||||
entry_points={"console_scripts": ["octoprint = octoprint:main"]},
|
||||
)
|
||||
@@ -4,20 +4,20 @@ import logging as log
|
||||
import os
|
||||
import sys
|
||||
|
||||
from ._version import get_versions
|
||||
from ._version import get_data as get_version_data
|
||||
|
||||
# ~~ version
|
||||
|
||||
|
||||
versions = get_versions()
|
||||
version_data = get_version_data()
|
||||
|
||||
__version__ = versions["version"]
|
||||
__branch__ = versions.get("branch", None)
|
||||
__version__ = version_data["version"]
|
||||
__branch__ = version_data["branch"]
|
||||
__display_version__ = __version__
|
||||
__revision__ = versions.get("full-revisionid", versions.get("full", None))
|
||||
__revision__ = version_data["revision"]
|
||||
|
||||
del versions
|
||||
del get_versions
|
||||
del version_data
|
||||
del get_version_data
|
||||
|
||||
# figure out current umask - sadly only doable by setting a new one and resetting it, no query method
|
||||
UMASK = os.umask(0)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
version = "__use_git__"
|
||||
branch = None
|
||||
revision = None
|
||||
+286
-648
@@ -1,86 +1,107 @@
|
||||
# This file helps to compute a version number in source trees obtained from
|
||||
# git-archive tarball (such as those provided by githubs download-from-tag
|
||||
# feature). Distribution tarballs (built by setup.py sdist) and build
|
||||
# directories (produced by setup.py build) will contain a much shorter file
|
||||
# that just contains the computed version number.
|
||||
"""
|
||||
This file is responsible for calculating the version of OctoPrint.
|
||||
|
||||
# This file is released into the public domain. Generated by
|
||||
# versioneer-0.15+dev (https://github.com/warner/python-versioneer)
|
||||
It's based heavily on versioneer and miniver.
|
||||
|
||||
"""Git implementation of _version.py."""
|
||||
The version is calculated as follows:
|
||||
|
||||
If a file named `_static_version.py` exists in the package root, it is
|
||||
imported and the version is read from there. This is the case for
|
||||
source distributions created by `setup.py sdist` as well as binary distributions
|
||||
built by `setup.py bdist` and `setup.py bdist_wheel`.
|
||||
|
||||
If no such file exists, the version is calculated from git and the provided set
|
||||
of branch version rules. If the current branch matches one of the rules, the
|
||||
version is calculated as `<tag>.dev<distance>+g<short>` where `<tag>` is the
|
||||
virtual tag associated with the current branch, `<distance>` is the distance of
|
||||
the current HEAD from the reference commit of the branch and `<short>` is the
|
||||
short SHA1 of the current HEAD. If the current branch does not match any of the
|
||||
rules, the version is the closest tag reachable from the current HEAD.
|
||||
|
||||
If the current HEAD is dirty, the version as calculated from a matching branch
|
||||
rule is appended with `.dirty`. Versions from a closest tag instead get
|
||||
`.post<distance>.dev0` appended.
|
||||
|
||||
If no tag can be determined but a commit hash, the version is `0+unknown.g<short>`.
|
||||
|
||||
If no commit hash can be determined either, the version is `0+unknown`.
|
||||
"""
|
||||
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# Adjust this on every release (candidate)
|
||||
BRANCH_VERSIONS = """
|
||||
# Configuration for the branch versions, manually mapping tags based on branches
|
||||
#
|
||||
# Format is
|
||||
#
|
||||
# <branch-regex> <tag> <reference commit>
|
||||
#
|
||||
# The data is processed from top to bottom, the first matching line wins.
|
||||
|
||||
def get_keywords():
|
||||
"""Get the keywords needed to look up the version information."""
|
||||
# these strings will be replaced by git during git-archive.
|
||||
# setup.py/versioneer.py will grep for the variable names, so they must
|
||||
# each be defined on a line of their own. _version.py will just call
|
||||
# get_keywords().
|
||||
git_refnames = "$Format:%d$"
|
||||
git_full = "$Format:%H$"
|
||||
keywords = {"refnames": git_refnames, "full": git_full}
|
||||
return keywords
|
||||
# maintenance is currently the branch for preparation of maintenance release 1.10.0
|
||||
# so are any fix/... and improve/... branches
|
||||
maintenance 1.10.0 cd955e9a46782119b36cc22b8dea5652ebbf9774
|
||||
fix/.* 1.10.0 cd955e9a46782119b36cc22b8dea5652ebbf9774
|
||||
improve/.* 1.10.0 cd955e9a46782119b36cc22b8dea5652ebbf9774
|
||||
|
||||
# staging/bugfix is the branch for preparation of the 1.9.x bugfix releases
|
||||
# so are any bug/... branches
|
||||
staging/bugfix 1.9.3 f027aaa7300f70b046525a49245b33c43dd198c1
|
||||
bug/.* 1.9.3 f027aaa7300f70b046525a49245b33c43dd198c1
|
||||
|
||||
# staging/maintenance is currently the branch for preparation of 1.9.0rc7
|
||||
# so is regressionfix/...
|
||||
staging/maintenance 1.9.0rc7 9ba981a2ea789030927fc49b6ad166bc68f6b5f9
|
||||
regressionfix/.* 1.9.0rc7 9ba981a2ea789030927fc49b6ad166bc68f6b5f9
|
||||
|
||||
# staging/devel is currently inactive (but has the 1.4.1rc4 namespace)
|
||||
staging/devel 1.4.1rc4 650d54d1885409fa1d411eb54b9e8c7ff428910f
|
||||
|
||||
# devel and dev/* are development branches and thus get resolved to 2.0.0.dev for now
|
||||
devel 2.0.0 2da7aa358d950b4567aaab8f18d6b5779193e077
|
||||
dev/* 2.0.0 2da7aa358d950b4567aaab8f18d6b5779193e077
|
||||
feature/* 2.0.0 2da7aa358d950b4567aaab8f18d6b5779193e077
|
||||
"""
|
||||
|
||||
package_root = os.path.dirname(os.path.realpath(__file__))
|
||||
package_name = os.path.basename(package_root)
|
||||
|
||||
STATIC_FILE = "_static_version.py"
|
||||
|
||||
STATIC_FILE_TEMPLATE = """
|
||||
# This file has been generated by _version.py.
|
||||
version = "{version}"
|
||||
branch = "{branch}"
|
||||
revision = "{revision}"
|
||||
""".strip()
|
||||
|
||||
_verbose = False
|
||||
|
||||
|
||||
class VersioneerConfig:
|
||||
def _git(*args, **kwargs):
|
||||
git = ["git"]
|
||||
if sys.platform == "win32":
|
||||
git = ["git.cmd", "git.exe"]
|
||||
|
||||
"""Container for Versioneer configuration parameters."""
|
||||
cwd = kwargs.pop("cwd", None)
|
||||
if cwd is None:
|
||||
cwd = os.path.dirname(__file__)
|
||||
hide_stderr = kwargs.pop("hide_stderr", False)
|
||||
verbose = kwargs.pop("verbose", False)
|
||||
|
||||
|
||||
def get_config():
|
||||
"""Create, populate and return the VersioneerConfig() object."""
|
||||
# these strings are filled in when 'setup.py versioneer' creates
|
||||
# _version.py
|
||||
cfg = VersioneerConfig()
|
||||
cfg.VCS = "git"
|
||||
cfg.style = "pep440-tag"
|
||||
cfg.tag_prefix = ""
|
||||
cfg.parentdir_prefix = ""
|
||||
cfg.versionfile_source = "src/octoprint/_version.py"
|
||||
cfg.lookupfile = ".versioneer-lookup"
|
||||
cfg.verbose = False
|
||||
return cfg
|
||||
|
||||
|
||||
class NotThisMethod(Exception):
|
||||
|
||||
"""Exception raised if a method is not valid for the current scenario."""
|
||||
|
||||
|
||||
LONG_VERSION_PY = {}
|
||||
HANDLERS = {}
|
||||
|
||||
|
||||
def register_vcs_handler(vcs, method): # decorator
|
||||
"""Decorator to mark a method as the handler for a particular VCS."""
|
||||
|
||||
def decorate(f):
|
||||
"""Store f in HANDLERS[vcs][method]."""
|
||||
if vcs not in HANDLERS:
|
||||
HANDLERS[vcs] = {}
|
||||
HANDLERS[vcs][method] = f
|
||||
return f
|
||||
|
||||
return decorate
|
||||
|
||||
|
||||
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
|
||||
"""Call the given command(s)."""
|
||||
assert isinstance(commands, list)
|
||||
p = None
|
||||
for c in commands:
|
||||
for c in git:
|
||||
try:
|
||||
dispcmd = str([c] + args)
|
||||
# remember shell=False, so use git.cmd on windows, not just git
|
||||
dispcmd = str([c] + list(args))
|
||||
if verbose:
|
||||
print("trying %s" % dispcmd)
|
||||
p = subprocess.Popen(
|
||||
[c] + args,
|
||||
[c] + list(args),
|
||||
cwd=cwd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=(subprocess.PIPE if hide_stderr else None),
|
||||
@@ -96,11 +117,9 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
|
||||
return None
|
||||
else:
|
||||
if verbose:
|
||||
print(f"unable to find command, tried {commands}")
|
||||
print(f"unable to find command, tried {git}")
|
||||
return None
|
||||
stdout = p.communicate()[0].strip()
|
||||
if sys.version_info[0] >= 3:
|
||||
stdout = stdout.decode()
|
||||
stdout = p.communicate()[0].strip().decode()
|
||||
if p.returncode != 0:
|
||||
if verbose:
|
||||
print("unable to run %s (error)" % dispcmd)
|
||||
@@ -108,616 +127,235 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False):
|
||||
return stdout
|
||||
|
||||
|
||||
def versions_from_parentdir(parentdir_prefix, root, verbose):
|
||||
"""Try to determine the version from the parent directory name.
|
||||
|
||||
Source tarballs conventionally unpack into a directory that includes
|
||||
both the project name and a version string.
|
||||
"""
|
||||
dirname = os.path.basename(root)
|
||||
if not dirname.startswith(parentdir_prefix):
|
||||
if verbose:
|
||||
print(
|
||||
"guessing rootdir is '%s', but '%s' doesn't start with "
|
||||
"prefix '%s'" % (root, dirname, parentdir_prefix)
|
||||
)
|
||||
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
|
||||
return {
|
||||
"version": dirname[len(parentdir_prefix) :],
|
||||
"full-revisionid": None,
|
||||
"dirty": False,
|
||||
"error": None,
|
||||
}
|
||||
def _get_long():
|
||||
return _git("rev-parse", "HEAD")
|
||||
|
||||
|
||||
@register_vcs_handler("git", "get_keywords")
|
||||
def git_get_keywords(versionfile_abs):
|
||||
"""Extract version information from the given file."""
|
||||
# the code embedded in _version.py can just fetch the value of these
|
||||
# keywords. When used from setup.py, we don't want to import _version.py,
|
||||
# so we do it with a regexp instead. This function is not used from
|
||||
# _version.py.
|
||||
keywords = {}
|
||||
def _get_short():
|
||||
return _git("rev-parse", "--short", "HEAD")
|
||||
|
||||
|
||||
def _get_tag():
|
||||
return _git("describe", "--tags", "--abbrev=0", "--always")
|
||||
|
||||
|
||||
def _get_branch():
|
||||
return _git("rev-parse", "--abbrev-ref", "HEAD")
|
||||
|
||||
|
||||
def _get_dirty():
|
||||
describe = _git("describe", "--tags", "--dirty", "--always")
|
||||
return describe is None or describe.endswith("-dirty")
|
||||
|
||||
|
||||
def _get_distance(ref):
|
||||
try:
|
||||
f = open(versionfile_abs, encoding="utf-8")
|
||||
for line in f.readlines():
|
||||
if line.strip().startswith("git_refnames ="):
|
||||
mo = re.search(r'=\s*"(.*)"', line)
|
||||
if mo:
|
||||
keywords["refnames"] = mo.group(1)
|
||||
if line.strip().startswith("git_full ="):
|
||||
mo = re.search(r'=\s*"(.*)"', line)
|
||||
if mo:
|
||||
keywords["full"] = mo.group(1)
|
||||
f.close()
|
||||
except OSError:
|
||||
pass
|
||||
return keywords
|
||||
return int(_git("rev-list", "--count", "HEAD", f"^{ref}"))
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
@register_vcs_handler("git", "keywords")
|
||||
def git_versions_from_keywords(keywords, tag_prefix, verbose):
|
||||
"""Get version information from git keywords."""
|
||||
if not keywords:
|
||||
raise NotThisMethod("no keywords at all, weird")
|
||||
refnames = keywords["refnames"].strip()
|
||||
if refnames.startswith("$Format"):
|
||||
if verbose:
|
||||
print("keywords are unexpanded, not using")
|
||||
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
|
||||
refs = {r.strip() for r in refnames.strip("()").split(",")}
|
||||
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
|
||||
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
|
||||
TAG = "tag: "
|
||||
tags = {r[len(TAG) :] for r in refs if r.startswith(TAG)}
|
||||
if not tags:
|
||||
# Either we're using git < 1.8.3, or there really are no tags. We use
|
||||
# a heuristic: assume all version tags have a digit. The old git %d
|
||||
# expansion behaves like git log --decorate=short and strips out the
|
||||
# refs/heads/ and refs/tags/ prefixes that would let us distinguish
|
||||
# between branches and tags. By ignoring refnames without digits, we
|
||||
# filter out many common branch names like "release" and
|
||||
# "stabilization", as well as "HEAD" and "master".
|
||||
tags = {r for r in refs if re.search(r"\d", r)}
|
||||
if verbose:
|
||||
print("discarding '%s', no digits" % ",".join(refs - tags))
|
||||
|
||||
branches = [
|
||||
r
|
||||
for r in refs
|
||||
if not r.startswith(TAG) and r != "HEAD" and not r.startswith("refs/")
|
||||
]
|
||||
if verbose:
|
||||
print("likely branches: %s" % ",".join(sorted(branches)))
|
||||
branch = None
|
||||
if branches:
|
||||
branch = branches[0]
|
||||
|
||||
if verbose:
|
||||
print("likely tags: %s" % ",".join(sorted(tags)))
|
||||
for ref in sorted(tags):
|
||||
# sorting will prefer e.g. "2.0" over "2.0rc1"
|
||||
if ref.startswith(tag_prefix):
|
||||
r = ref[len(tag_prefix) :]
|
||||
if verbose:
|
||||
print("picking %s" % r)
|
||||
|
||||
result = {
|
||||
"version": r,
|
||||
"full-revisionid": keywords["full"].strip(),
|
||||
"dirty": False,
|
||||
"error": None,
|
||||
}
|
||||
if branch is not None:
|
||||
result["branch"] = branch
|
||||
return result
|
||||
# no suitable tags, so version is "0+unknown", but full hex is still there
|
||||
if verbose:
|
||||
print("no suitable tags, using unknown + full revision id")
|
||||
return {
|
||||
"version": "0+unknown",
|
||||
"full-revisionid": keywords["full"].strip(),
|
||||
"dirty": False,
|
||||
"error": "no suitable tags",
|
||||
}
|
||||
|
||||
|
||||
@register_vcs_handler("git", "pieces_from_vcs")
|
||||
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
|
||||
"""Get version from 'git describe' in the root of the source tree.
|
||||
|
||||
This only gets called if the git-archive 'subst' keywords were *not*
|
||||
expanded, and _version.py hasn't already been rewritten with a short
|
||||
version string, meaning we're inside a checked out source tree.
|
||||
"""
|
||||
if not os.path.exists(os.path.join(root, ".git")):
|
||||
if verbose:
|
||||
print("no .git in %s" % root)
|
||||
raise NotThisMethod("no .git directory")
|
||||
|
||||
GITS = ["git"]
|
||||
if sys.platform == "win32":
|
||||
GITS = ["git.cmd", "git.exe"]
|
||||
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
|
||||
# if there isn't one, this yields HEX[-dirty] (no NUM)
|
||||
describe_out = run_command(
|
||||
GITS,
|
||||
[
|
||||
"describe",
|
||||
"--tags",
|
||||
"--dirty",
|
||||
"--always",
|
||||
"--long",
|
||||
"--match",
|
||||
"%s*" % tag_prefix,
|
||||
],
|
||||
cwd=root,
|
||||
)
|
||||
# --long was added in git-1.5.5
|
||||
if describe_out is None:
|
||||
raise NotThisMethod("'git describe' failed")
|
||||
describe_out = describe_out.strip()
|
||||
full_out = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
|
||||
if full_out is None:
|
||||
raise NotThisMethod("'git rev-parse' failed")
|
||||
full_out = full_out.strip()
|
||||
|
||||
pieces = {}
|
||||
pieces["long"] = full_out
|
||||
pieces["short"] = full_out[:7] # maybe improved later
|
||||
pieces["error"] = None
|
||||
|
||||
# parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
|
||||
# TAG might have hyphens.
|
||||
git_describe = describe_out
|
||||
|
||||
# look for -dirty suffix
|
||||
dirty = git_describe.endswith("-dirty")
|
||||
pieces["dirty"] = dirty
|
||||
if dirty:
|
||||
git_describe = git_describe[: git_describe.rindex("-dirty")]
|
||||
|
||||
# figure out our branch
|
||||
abbrev_ref_out = run_command(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root)
|
||||
if abbrev_ref_out is not None and abbrev_ref_out != "HEAD":
|
||||
pieces["branch"] = abbrev_ref_out.strip()
|
||||
|
||||
# now we have TAG-NUM-gHEX or HEX
|
||||
|
||||
if "-" in git_describe:
|
||||
# TAG-NUM-gHEX
|
||||
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
|
||||
if not mo:
|
||||
# unparsable. Maybe git-describe is misbehaving?
|
||||
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
|
||||
return pieces
|
||||
|
||||
# tag
|
||||
full_tag = mo.group(1)
|
||||
if not full_tag.startswith(tag_prefix):
|
||||
if verbose:
|
||||
fmt = "tag '%s' doesn't start with prefix '%s'"
|
||||
print(fmt % (full_tag, tag_prefix))
|
||||
pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
|
||||
full_tag,
|
||||
tag_prefix,
|
||||
)
|
||||
return pieces
|
||||
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
|
||||
|
||||
# distance: number of commits since tag
|
||||
pieces["distance"] = int(mo.group(2))
|
||||
|
||||
# commit: short hex revision ID
|
||||
pieces["short"] = mo.group(3)
|
||||
|
||||
else:
|
||||
# HEX: no tags
|
||||
pieces["closest-tag"] = None
|
||||
count_out = run_command(GITS, ["rev-list", "HEAD", "--count"], cwd=root)
|
||||
pieces["distance"] = int(count_out) # total number of commits
|
||||
|
||||
return pieces
|
||||
|
||||
|
||||
@register_vcs_handler("git", "parse_lookup_file")
|
||||
def git_parse_lookup_file(path):
|
||||
"""Parse a versioneer lookup file.
|
||||
|
||||
This file allows definition of branch specific data like virtual tags or
|
||||
custom styles to use for version rendering.
|
||||
"""
|
||||
if not os.path.exists(path):
|
||||
def _parse_branch_versions():
|
||||
if not BRANCH_VERSIONS:
|
||||
return []
|
||||
|
||||
import re
|
||||
|
||||
lookup = []
|
||||
with open(path, encoding="utf-8") as f:
|
||||
for line in f:
|
||||
if "#" in line:
|
||||
line = line[: line.index("#")]
|
||||
line = line.strip()
|
||||
if not line:
|
||||
branch_versions = []
|
||||
for line in BRANCH_VERSIONS.splitlines():
|
||||
if "#" in line:
|
||||
line = line[: line.index("#")]
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
|
||||
try:
|
||||
split_line = list(map(lambda x: x.strip(), line.split()))
|
||||
if not len(split_line):
|
||||
continue
|
||||
if len(split_line) != 3:
|
||||
continue
|
||||
|
||||
try:
|
||||
split_line = list(map(lambda x: x.strip(), line.split()))
|
||||
if not len(split_line):
|
||||
continue
|
||||
|
||||
matcher = re.compile(split_line[0])
|
||||
|
||||
if len(split_line) == 1:
|
||||
entry = [matcher, None, None, None]
|
||||
elif len(split_line) == 2:
|
||||
render = split_line[1]
|
||||
entry = [matcher, render, None, None]
|
||||
elif len(split_line) == 3:
|
||||
tag, ref_commit = split_line[1:]
|
||||
entry = [matcher, None, tag, ref_commit]
|
||||
elif len(split_line) == 4:
|
||||
tag, ref_commit, render = split_line[1:]
|
||||
entry = [matcher, render, tag, ref_commit]
|
||||
else:
|
||||
continue
|
||||
|
||||
lookup.append(entry)
|
||||
except Exception:
|
||||
logging.getLogger(__name__).exception("Versioneer problem")
|
||||
break
|
||||
return lookup
|
||||
matcher = re.compile(split_line[0])
|
||||
branch_versions.append([matcher, split_line[1], split_line[2]])
|
||||
except Exception:
|
||||
break
|
||||
return branch_versions
|
||||
|
||||
|
||||
@register_vcs_handler("git", "pieces_from_lookup")
|
||||
def git_pieces_from_lookup(lookup, root, verbose, run_command=run_command):
|
||||
"""Extract version information based on provided lookup data."""
|
||||
GITS = ["git"]
|
||||
if sys.platform == "win32":
|
||||
GITS = ["git.cmd", "git.exe"]
|
||||
def _get_data_from_git():
|
||||
branch = _get_branch()
|
||||
if _verbose:
|
||||
print(f"Branch: {branch}")
|
||||
|
||||
stdout = run_command(GITS, ["rev-parse", "--abbrev-ref", "HEAD"], cwd=root)
|
||||
if stdout is None:
|
||||
raise NotThisMethod("git rev-parse --abbrev-ref HEAD failed")
|
||||
is_dirty = _get_dirty()
|
||||
if _verbose:
|
||||
print(f"Dirty: {is_dirty}") # noqa: E241
|
||||
|
||||
current_branch = stdout.strip()
|
||||
if current_branch == "HEAD":
|
||||
raise NotThisMethod("not on a branch")
|
||||
sha = _get_long()
|
||||
if _verbose:
|
||||
print(f"SHA: {sha}") # noqa: E241
|
||||
|
||||
for matcher, render, tag, ref_commit in lookup:
|
||||
if matcher.match(current_branch):
|
||||
if tag is None or ref_commit is None:
|
||||
raise NotThisMethod("tag or ref_commit is unset for " "this branch")
|
||||
short = _get_short()
|
||||
if _verbose:
|
||||
print(f"Short: {short}") # noqa: E241
|
||||
|
||||
stdout = run_command(
|
||||
GITS, ["rev-list", "%s..HEAD" % ref_commit, "--count"], cwd=root
|
||||
)
|
||||
if stdout is None:
|
||||
raise NotThisMethod(
|
||||
"git rev-list %s..HEAD " "--count failed" % ref_commit
|
||||
)
|
||||
try:
|
||||
num_commits = int(stdout.strip())
|
||||
except ValueError:
|
||||
raise NotThisMethod(
|
||||
"git rev-list %s..HEAD --count didn't "
|
||||
"return a valid number" % ref_commit
|
||||
)
|
||||
tag = _get_tag()
|
||||
distance = _get_distance(tag)
|
||||
template = "{tag}"
|
||||
dirty = "+g{short}.dirty"
|
||||
|
||||
stdout = run_command(GITS, ["rev-parse", "--short", "HEAD"], cwd=root)
|
||||
if stdout is None:
|
||||
raise NotThisMethod("git describe rev-parse " "--short HEAD failed")
|
||||
short_hash = stdout.strip()
|
||||
if branch is not None:
|
||||
lookup = _parse_branch_versions()
|
||||
for matcher, virtual_tag, ref_commit in lookup:
|
||||
if not matcher.match(branch):
|
||||
continue
|
||||
|
||||
stdout = run_command(
|
||||
GITS, ["describe", "--tags", "--dirty", "--always"], cwd=root
|
||||
)
|
||||
if stdout is None:
|
||||
raise NotThisMethod("git describe --tags --dirty " "--always failed")
|
||||
dirty = stdout.strip().endswith("-dirty")
|
||||
tag = virtual_tag
|
||||
distance = _get_distance(ref_commit)
|
||||
template = "{tag}.dev{distance}+g{short}"
|
||||
dirty = ".dirty"
|
||||
break
|
||||
|
||||
stdout = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
|
||||
if stdout is None:
|
||||
raise NotThisMethod("git rev-parse HEAD failed")
|
||||
full = stdout.strip()
|
||||
if is_dirty:
|
||||
template += dirty
|
||||
|
||||
return {
|
||||
"long": full,
|
||||
"short": short_hash,
|
||||
"dirty": dirty,
|
||||
"branch": current_branch,
|
||||
"closest-tag": tag,
|
||||
"distance": num_commits,
|
||||
"error": None,
|
||||
"render": render,
|
||||
}
|
||||
|
||||
raise NotThisMethod("no matching lookup definition found")
|
||||
|
||||
|
||||
def plus_or_dot(pieces):
|
||||
"""Return a + if we don't already have one, else return a ."""
|
||||
if "+" in pieces.get("closest-tag", ""):
|
||||
return "."
|
||||
return "+"
|
||||
|
||||
|
||||
def render_pep440(pieces):
|
||||
"""Build up version string, with post-release "local version identifier".
|
||||
|
||||
Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
|
||||
get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
|
||||
|
||||
Exceptions:
|
||||
1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
|
||||
"""
|
||||
if pieces["closest-tag"]:
|
||||
rendered = pieces["closest-tag"]
|
||||
if pieces["distance"] or pieces["dirty"]:
|
||||
rendered += plus_or_dot(pieces)
|
||||
rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
|
||||
if pieces["dirty"]:
|
||||
rendered += ".dirty"
|
||||
else:
|
||||
# exception #1
|
||||
rendered = "0+untagged.%d.g%s" % (pieces["distance"], pieces["short"])
|
||||
if pieces["dirty"]:
|
||||
rendered += ".dirty"
|
||||
return rendered
|
||||
|
||||
|
||||
def render_pep440_tag(pieces):
|
||||
"""TAG[[.postDISTANCE].dev0+gHEX] -- Just the tag if not dirty, else more info
|
||||
|
||||
Useful for projects that want commit based tracking on some branches
|
||||
but have the master branch only report tags, to allow for commits that
|
||||
do not modify actual code (e.g. to .github/* or docs).
|
||||
|
||||
Exceptions:
|
||||
1: no tags. 0.postDISTANCE[.dev0]+gHEX
|
||||
"""
|
||||
if pieces["closest-tag"]:
|
||||
rendered = pieces["closest-tag"]
|
||||
if pieces["dirty"]:
|
||||
rendered += ".post%d" % pieces["distance"]
|
||||
rendered += ".dev0"
|
||||
rendered += "+g%s" % pieces["short"]
|
||||
else:
|
||||
# exception #1
|
||||
rendered = "0.post%d" % pieces["distance"]
|
||||
if pieces["dirty"]:
|
||||
rendered += ".dev0"
|
||||
rendered += "+g%s" % pieces["short"]
|
||||
return rendered
|
||||
|
||||
|
||||
def render_pep440_pre(pieces):
|
||||
"""TAG[.post.devDISTANCE] -- No -dirty.
|
||||
|
||||
Exceptions:
|
||||
1: no tags. 0.post.devDISTANCE
|
||||
"""
|
||||
if pieces["closest-tag"]:
|
||||
rendered = pieces["closest-tag"]
|
||||
if pieces["distance"]:
|
||||
rendered += ".post.dev%d" % pieces["distance"]
|
||||
else:
|
||||
# exception #1
|
||||
rendered = "0.post.dev%d" % pieces["distance"]
|
||||
return rendered
|
||||
|
||||
|
||||
def render_pep440_post(pieces):
|
||||
"""TAG[.postDISTANCE[.dev0]+gHEX] .
|
||||
|
||||
The ".dev0" means dirty. Note that .dev0 sorts backwards
|
||||
(a dirty tree will appear "older" than the corresponding clean one),
|
||||
but you shouldn't be releasing software with -dirty anyways.
|
||||
|
||||
Exceptions:
|
||||
1: no tags. 0.postDISTANCE[.dev0]
|
||||
"""
|
||||
if pieces["closest-tag"]:
|
||||
rendered = pieces["closest-tag"]
|
||||
if pieces["distance"] or pieces["dirty"]:
|
||||
rendered += ".post%d" % pieces["distance"]
|
||||
if pieces["dirty"]:
|
||||
rendered += ".dev0"
|
||||
rendered += plus_or_dot(pieces)
|
||||
rendered += "g%s" % pieces["short"]
|
||||
else:
|
||||
# exception #1
|
||||
rendered = "0.post%d" % pieces["distance"]
|
||||
if pieces["dirty"]:
|
||||
rendered += ".dev0"
|
||||
rendered += "+g%s" % pieces["short"]
|
||||
return rendered
|
||||
|
||||
|
||||
def render_pep440_dev(pieces):
|
||||
"""TAG[.devDISTANCE]+gHEX[.dirty] .
|
||||
|
||||
Exceptions:
|
||||
1: no tags. 0.devDISTANCE+gHEX[.dirty]
|
||||
"""
|
||||
if pieces["closest-tag"]:
|
||||
rendered = pieces["closest-tag"]
|
||||
if pieces["distance"]:
|
||||
rendered += ".dev%d" % pieces["distance"]
|
||||
rendered += plus_or_dot(pieces)
|
||||
else:
|
||||
# exception #1
|
||||
rendered = "0.dev%d" % pieces["distance"]
|
||||
rendered += "+"
|
||||
rendered += "g%s" % pieces["short"]
|
||||
if pieces["dirty"]:
|
||||
rendered += ".dirty"
|
||||
return rendered
|
||||
|
||||
|
||||
def render_pep440_old(pieces):
|
||||
"""TAG[.postDISTANCE[.dev0]] .
|
||||
|
||||
The ".dev0" means dirty.
|
||||
|
||||
Eexceptions:
|
||||
1: no tags. 0.postDISTANCE[.dev0]
|
||||
"""
|
||||
if pieces["closest-tag"]:
|
||||
rendered = pieces["closest-tag"]
|
||||
if pieces["distance"] or pieces["dirty"]:
|
||||
rendered += ".post%d" % pieces["distance"]
|
||||
if pieces["dirty"]:
|
||||
rendered += ".dev0"
|
||||
else:
|
||||
# exception #1
|
||||
rendered = "0.post%d" % pieces["distance"]
|
||||
if pieces["dirty"]:
|
||||
rendered += ".dev0"
|
||||
return rendered
|
||||
|
||||
|
||||
def render_git_describe(pieces):
|
||||
"""TAG[-DISTANCE-gHEX][-dirty].
|
||||
|
||||
Like 'git describe --tags --dirty --always'.
|
||||
|
||||
Exceptions:
|
||||
1: no tags. HEX[-dirty] (note: no 'g' prefix)
|
||||
"""
|
||||
if pieces["closest-tag"]:
|
||||
rendered = pieces["closest-tag"]
|
||||
if pieces["distance"]:
|
||||
rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
|
||||
else:
|
||||
# exception #1
|
||||
rendered = pieces["short"]
|
||||
if pieces["dirty"]:
|
||||
rendered += "-dirty"
|
||||
return rendered
|
||||
|
||||
|
||||
def render_git_describe_long(pieces):
|
||||
"""TAG-DISTANCE-gHEX[-dirty].
|
||||
|
||||
Like 'git describe --tags --dirty --always -long'.
|
||||
The distance/hash is unconditional.
|
||||
|
||||
Exceptions:
|
||||
1: no tags. HEX[-dirty] (note: no 'g' prefix)
|
||||
"""
|
||||
if pieces["closest-tag"]:
|
||||
rendered = pieces["closest-tag"]
|
||||
rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
|
||||
else:
|
||||
# exception #1
|
||||
rendered = pieces["short"]
|
||||
if pieces["dirty"]:
|
||||
rendered += "-dirty"
|
||||
return rendered
|
||||
|
||||
|
||||
def render(pieces, style):
|
||||
"""Render the given version pieces into the requested style."""
|
||||
if pieces["error"]:
|
||||
return {
|
||||
"version": "unknown",
|
||||
"full-revisionid": pieces.get("long"),
|
||||
"dirty": None,
|
||||
"error": pieces["error"],
|
||||
}
|
||||
|
||||
if "render" in pieces and pieces["render"] is not None:
|
||||
style = pieces["render"]
|
||||
|
||||
if not style or style == "default":
|
||||
style = "pep440" # the default
|
||||
|
||||
if style == "pep440":
|
||||
rendered = render_pep440(pieces)
|
||||
elif style == "pep440-pre":
|
||||
rendered = render_pep440_pre(pieces)
|
||||
elif style == "pep440-post":
|
||||
rendered = render_pep440_post(pieces)
|
||||
elif style == "pep440-old":
|
||||
rendered = render_pep440_old(pieces)
|
||||
elif style == "pep440-dev":
|
||||
rendered = render_pep440_dev(pieces)
|
||||
elif style == "pep440-tag":
|
||||
rendered = render_pep440_tag(pieces)
|
||||
elif style == "git-describe":
|
||||
rendered = render_git_describe(pieces)
|
||||
elif style == "git-describe-long":
|
||||
rendered = render_git_describe_long(pieces)
|
||||
else:
|
||||
raise ValueError("unknown style '%s'" % style)
|
||||
|
||||
result = {
|
||||
"version": rendered,
|
||||
"full-revisionid": pieces["long"],
|
||||
"dirty": pieces["dirty"],
|
||||
"error": None,
|
||||
vars = {
|
||||
"tag": tag,
|
||||
"distance": distance,
|
||||
"full": sha,
|
||||
"short": short,
|
||||
}
|
||||
|
||||
if tag is None:
|
||||
if short is None:
|
||||
template = "0+unknown"
|
||||
else:
|
||||
template = "0+unknown.g{short}"
|
||||
if is_dirty:
|
||||
template += ".dirty"
|
||||
|
||||
return {
|
||||
"version": template.format(**vars),
|
||||
"branch": branch,
|
||||
"revision": sha,
|
||||
}
|
||||
if "branch" in pieces and pieces["branch"] is not None:
|
||||
result["branch"] = pieces["branch"]
|
||||
return result
|
||||
|
||||
|
||||
def get_versions():
|
||||
"""Get version information or return default if unable to do so."""
|
||||
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
|
||||
# __file__, we can work backwards from there to the root. Some
|
||||
# py2exe/bbfreeze/non-CPython implementations don't do __file__, in which
|
||||
# case we can only use expanded keywords.
|
||||
def _get_data_from_static_file():
|
||||
data = {}
|
||||
with open(os.path.join(package_root, STATIC_FILE)) as f:
|
||||
exec(f.read(), {}, data)
|
||||
if data["version"] == "__use_git__":
|
||||
return None
|
||||
return data
|
||||
|
||||
cfg = get_config()
|
||||
verbose = cfg.verbose
|
||||
|
||||
def _get_data_from_keywords():
|
||||
git_refnames = "$Format:%d$"
|
||||
git_full = "$Format:%H$"
|
||||
if git_refnames.startswith("$Format") or git_full.startswith("$Format"):
|
||||
# keywords not extended, method not applicable
|
||||
return None
|
||||
|
||||
refs = {
|
||||
r.strip()[8:] if r.strip().startswith("HEAD -> ") else r.strip()
|
||||
for r in git_refnames.strip().strip("()").split(",")
|
||||
}
|
||||
|
||||
tags = {r[5:] for r in refs if r.startswith("tag: ")}
|
||||
if not tags:
|
||||
tags = {r for r in refs if re.search(r"\d", r)}
|
||||
tag = sorted(tags)[0] if tags else None
|
||||
|
||||
branches = [
|
||||
r
|
||||
for r in refs
|
||||
if not r.startswith("tag: ") and r != "HEAD" and not r.startswith("refs/")
|
||||
]
|
||||
branch = branches[0] if branches else None
|
||||
|
||||
if tag is None:
|
||||
template = "0+unknown.g{short}"
|
||||
else:
|
||||
template = "{tag}"
|
||||
|
||||
return {
|
||||
"version": template.format(short=git_full[:8], tag=tag),
|
||||
"branch": branch,
|
||||
"revision": git_full,
|
||||
}
|
||||
|
||||
|
||||
def _write_static_file(path, data=None):
|
||||
if data is None:
|
||||
data = get_data()
|
||||
|
||||
try:
|
||||
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix, verbose)
|
||||
except NotThisMethod:
|
||||
os.remove(path)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
try:
|
||||
root = os.path.realpath(__file__)
|
||||
# versionfile_source is the relative path from the top of the source
|
||||
# tree (where the .git directory might live) to this file. Invert
|
||||
# this to find the root from __file__.
|
||||
for _ in cfg.versionfile_source.split("/"):
|
||||
root = os.path.dirname(root)
|
||||
except NameError:
|
||||
return {
|
||||
"version": "0+unknown",
|
||||
"full-revisionid": None,
|
||||
"dirty": None,
|
||||
"error": "unable to find root of source tree",
|
||||
}
|
||||
with open(path, "w") as f:
|
||||
f.write(STATIC_FILE_TEMPLATE.format(**data))
|
||||
|
||||
lookupfile = cfg.lookupfile if cfg.lookupfile is not None else ".versioneer-lookup"
|
||||
lookuppath = os.path.join(root, lookupfile)
|
||||
if os.path.exists(lookuppath):
|
||||
try:
|
||||
lookup_data = git_parse_lookup_file(lookuppath)
|
||||
pieces = git_pieces_from_lookup(lookup_data, root, verbose)
|
||||
return render(pieces, cfg.style)
|
||||
except NotThisMethod:
|
||||
pass
|
||||
|
||||
try:
|
||||
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
|
||||
return render(pieces, cfg.style)
|
||||
except NotThisMethod:
|
||||
pass
|
||||
|
||||
try:
|
||||
if cfg.parentdir_prefix:
|
||||
return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)
|
||||
except NotThisMethod:
|
||||
pass
|
||||
def get_data():
|
||||
for method in (
|
||||
_get_data_from_static_file,
|
||||
_get_data_from_keywords,
|
||||
_get_data_from_git,
|
||||
):
|
||||
data = method()
|
||||
if data is not None:
|
||||
return data
|
||||
|
||||
return {
|
||||
"version": "0+unknown",
|
||||
"full-revisionid": None,
|
||||
"dirty": None,
|
||||
"error": "unable to compute version",
|
||||
"branch": None,
|
||||
"revision": None,
|
||||
}
|
||||
|
||||
|
||||
def get_cmdclass(pkg_source_path):
|
||||
from setuptools import Command
|
||||
from setuptools.command.build_py import build_py as build_py_orig
|
||||
from setuptools.command.sdist import sdist as sdist_orig
|
||||
|
||||
class _build_py(build_py_orig):
|
||||
def run(self):
|
||||
super().run()
|
||||
|
||||
src_marker = "src" + os.path.sep
|
||||
if pkg_source_path.startswith(src_marker):
|
||||
path = pkg_source_path[len(src_marker) :]
|
||||
else:
|
||||
path = pkg_source_path
|
||||
|
||||
_write_static_file(os.path.join(self.build_lib, path, STATIC_FILE))
|
||||
|
||||
class _sdist(sdist_orig):
|
||||
def make_release_tree(self, base_dir, files):
|
||||
super().make_release_tree(base_dir, files)
|
||||
|
||||
_write_static_file(os.path.join(base_dir, pkg_source_path, STATIC_FILE))
|
||||
|
||||
class version(Command):
|
||||
description = "prints the version"
|
||||
user_options = []
|
||||
|
||||
def initialize_options(self):
|
||||
pass
|
||||
|
||||
def finalize_options(self):
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
print(get_data()["version"])
|
||||
|
||||
return dict(sdist=_sdist, build_py=_build_py, version=version)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
_verbose = True
|
||||
print(get_data()["version"])
|
||||
@@ -492,9 +492,8 @@ class SoftwareUpdatePlugin(
|
||||
)
|
||||
return
|
||||
|
||||
from octoprint._version import get_versions
|
||||
from octoprint import __version__ as octoprint_version
|
||||
|
||||
octoprint_version = get_versions()["version"]
|
||||
if data_version != octoprint_version:
|
||||
self._logger.info(
|
||||
"Version cache was created for another version of OctoPrint, not using it"
|
||||
@@ -509,10 +508,9 @@ class SoftwareUpdatePlugin(
|
||||
self._logger.exception("Error parsing in version cache data")
|
||||
|
||||
def _save_version_cache(self):
|
||||
from octoprint._version import get_versions
|
||||
from octoprint import __version__ as octoprint_version
|
||||
from octoprint.util import atomic_write
|
||||
|
||||
octoprint_version = get_versions()["version"]
|
||||
self._version_cache["__version"] = octoprint_version
|
||||
|
||||
with atomic_write(
|
||||
|
||||
-2271
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user