Skip to content

Commit 9541d4b

Browse files
committed
Allow setuptools-git-versioning script to infer version from setup.py, add logging and improve docs
1 parent 1121573 commit 9541d4b

18 files changed

+494
-187
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ repos:
6262
rev: v0.961
6363
hooks:
6464
- id: mypy
65-
additional_dependencies: [types-six, types-toml]
65+
additional_dependencies: [types-six, types-toml, types-Deprecated]
6666
- repo: https://github.com/pycqa/flake8
6767
rev: 4.0.1
6868
hooks:

CHANGELOG.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,17 @@ Changelog
2020
.. change::
2121
:tags: core, feature
2222

23-
Add ``cwd`` argument to most of functions, allowing to get versions a specific repo folder
23+
Add ``cwd`` argument to most of functions, allowing to get versions of a specific repo without changing current directory
24+
25+
.. change::
26+
:tags: dev, feature
27+
28+
Add info and debug messages to the module
29+
30+
.. change::
31+
:tags: docs, feature
32+
33+
Add documentation for ``setuptools-git-versioning`` script
2434

2535
1.10
2636
----

README.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ version number according :pep:`440`.
4040

4141
- Well-documented
4242

43-
4443
See `difference <https://setuptools-git-versioning.readthedocs.io/en/latest/differences.html>`_
4544
between ``setuptools-git-versioning`` and other tools.
4645

@@ -86,7 +85,7 @@ and a section ``tool.setuptools-git-versioning`` with config options:
8685
[tool.setuptools-git-versioning]
8786
enabled = true
8887
89-
And check the package version generated:
88+
And check the package version generated (see :ref:`command` help):
9089

9190
.. code:: bash
9291
@@ -116,7 +115,7 @@ and then add new argument ``setuptools_git_versioning`` with config options:
116115
setup_requires=["setuptools-git-versioning<2"],
117116
)
118117
119-
And check the package version generated:
118+
And check the package version generated (see :ref:`command` help):
120119

121120
.. code:: bash
122121

docs/command.rst

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
.. _command:
2+
3+
Console command
4+
-----------------------------------
5+
6+
Package contains script `setuptools-git-versioning` which can be used for calculating version number.\
7+
8+
See :ref:`_installation` instruction for creating the repo with your package.
9+
10+
To get current package version in `mypackage` repo just execute:
11+
12+
.. code:: bash
13+
14+
$ cd /path/to/mypackage
15+
$ setuptools-git-versioning
16+
0.0.1
17+
18+
# or pass path to your repo explicitly
19+
20+
$ setuptools-git-versioning /path/to/mypackage
21+
0.0.1
22+
23+
Version will be printed to ``stdout``.
24+
25+
This script is a wrapper for ``setuptools_git_versioning`` module, you just call it:
26+
27+
.. code:: bash
28+
29+
$ python -m setuptools_git_versioning /path/to/mypackage
30+
0.0.1
31+
32+
``-v`` option enables verbose output which is useful for debugging, messages are printed to ``stderr``:
33+
34+
.. code:: bash
35+
36+
$ setuptools-git-versioning /path/to/mypackage -v
37+
38+
INFO: No explicit config passed
39+
INFO: Searching for config files in '/path/to/mypackage' folder
40+
INFO: Trying 'setup.py' ...
41+
INFO: '/path/to/mypackage/pyproject.toml' does not exist
42+
INFO: Getting latest tag
43+
INFO: Latest tag: '1.0.0'
44+
INFO: Tag SHA-256: '8dc9881eacd373cb34c5d3f99a6ad9e2349a79c4'
45+
INFO: Parsing tag_formatter 'util:tag_formatter' of type 'str'
46+
INFO: Is dirty: False
47+
INFO: HEAD SHA-256: '8dc9881eacd373cb34c5d3f99a6ad9e2349a79c4'
48+
INFO: Commits count between HEAD and latest tag: 0
49+
INFO: HEAD is tagged: True
50+
INFO: Current branch: 'master'
51+
INFO: Using template from 'template' option
52+
INFO: Version number after resolving substitutions: '1.0.0'
53+
INFO: Result: '1.0.0'
54+
55+
1.0.0
56+
57+
58+
``-vv`` shows even more debug messages:
59+
60+
.. code:: bash
61+
62+
$ setuptools-git-versioning /path/to/mypackage -vvv
63+
64+
INFO: No explicit config passed
65+
INFO: Searching for config files in '/path/to/mypackage' folder
66+
INFO: Trying 'setup.py' ...
67+
DEBUG: Adding '/path/to/mypackage' folder to sys.path
68+
INFO: '/path/to/mypackage/pyproject.toml' does not exist
69+
INFO: Getting latest tag
70+
DEBUG: Sorting tags by 'creatordate'
71+
DEBUG: Executing 'git tag --sort=-creatordate --merged' at '/path/to/mypackage'
72+
INFO: Latest tag: '1.0.0'
73+
DEBUG: Executing 'git rev-list -n 1 "1.0.0"' at '/path/to/mypackage'
74+
INFO: Tag SHA-256: '8dc9881eacd373cb34c5d3f99a6ad9e2349a79c4'
75+
INFO: Parsing tag_formatter 'util:tag_formatter' of type 'str'
76+
DEBUG: Executing 'from mypkg.util import tag_formatter'
77+
DEBUG: Tag after formatting: '1.0.0'
78+
DEBUG: Executing 'git status --short' at '/path/to/mypackage'
79+
INFO: Is dirty: False
80+
DEBUG: Executing 'git rev-list -n 1 "HEAD"' at '/path/to/mypackage'
81+
INFO: HEAD SHA-256: '8dc9881eacd373cb34c5d3f99a6ad9e2349a79c4'
82+
DEBUG: Executing 'git rev-list --count HEAD "^8dc9881eacd373cb34c5d3f99a6ad9e2349a79c4"' at '/path/to/mypackage'
83+
INFO: Commits count between HEAD and latest tag: 0
84+
INFO: HEAD is tagged: True
85+
DEBUG: Executing 'git rev-parse --abbrev-ref HEAD' at '/path/to/mypackage'
86+
INFO: Current branch: 'master'
87+
INFO: Using template from 'template' option
88+
DEBUG: Template: '{tag}'
89+
DEBUG: Args:()
90+
INFO: Version number after resolving substitutions: '1.0.0'
91+
INFO: Result: '1.0.0'
92+
93+
1.0.0
94+
95+
96+
Command help
97+
~~~~~~~~~~~~~
98+
99+
.. argparse::
100+
:module: setuptools_git_versioning
101+
:func: _parser
102+
:prog: setuptools-git-versioning

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"sphinx_autodoc_typehints",
5050
"changelog",
5151
"numpydoc",
52+
"sphinxarg.ext",
5253
]
5354

5455
# Add any paths that contain templates here, relative to this directory.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
:hidden:
1616

1717
install
18+
command
1819
schemas/index
1920
options/index
2021
substitutions/index

docs/install.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.. _installation:
2+
23
.. include:: ../README.rst
34
:start-after: installation

requirements-doc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ changelog
22
furo
33
numpydoc
44
sphinx
5+
sphinx-argparse
56
sphinx-autodoc-typehints

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
deprecated
12
packaging
23
setuptools
34
toml>=0.10.2

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def parse_requirements(file_content):
1818

1919
setup(
2020
name="setuptools-git-versioning",
21-
version=version_from_git(),
21+
version=version_from_git(root=HERE),
2222
author="dolfinus",
2323
author_email="[email protected]",
2424
description="Use git repo data for building a version number according PEP-440",

0 commit comments

Comments
 (0)