version-query 1.6.3__tar.gz → 1.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {version_query-1.6.3/version_query.egg-info → version_query-1.7.0}/PKG-INFO +106 -25
  2. {version_query-1.6.3 → version_query-1.7.0}/README.rst +102 -21
  3. version_query-1.7.0/test/test_local_git_version.py +21 -0
  4. {version_query-1.6.3 → version_query-1.7.0}/test/test_query.py +11 -0
  5. version_query-1.7.0/version_query/local_git_version.py +22 -0
  6. {version_query-1.6.3 → version_query-1.7.0/version_query.egg-info}/PKG-INFO +106 -25
  7. {version_query-1.6.3 → version_query-1.7.0}/version_query.egg-info/SOURCES.txt +4 -0
  8. {version_query-1.6.3 → version_query-1.7.0}/LICENSE +0 -0
  9. {version_query-1.6.3 → version_query-1.7.0}/MANIFEST.in +0 -0
  10. {version_query-1.6.3 → version_query-1.7.0}/NOTICE +0 -0
  11. {version_query-1.6.3 → version_query-1.7.0}/pyproject.toml +0 -0
  12. {version_query-1.6.3 → version_query-1.7.0}/requirements.txt +0 -0
  13. {version_query-1.6.3 → version_query-1.7.0}/requirements_test.txt +0 -0
  14. {version_query-1.6.3 → version_query-1.7.0}/setup.cfg +0 -0
  15. {version_query-1.6.3 → version_query-1.7.0}/setup.py +0 -0
  16. {version_query-1.6.3 → version_query-1.7.0}/test/__init__.py +0 -0
  17. {version_query-1.6.3 → version_query-1.7.0}/test/examples.py +0 -0
  18. {version_query-1.6.3 → version_query-1.7.0}/test/test_cli.py +0 -0
  19. {version_query-1.6.3 → version_query-1.7.0}/test/test_git.py +0 -0
  20. {version_query-1.6.3 → version_query-1.7.0}/test/test_packaging.py +0 -0
  21. {version_query-1.6.3 → version_query-1.7.0}/test/test_version.py +0 -0
  22. {version_query-1.6.3 → version_query-1.7.0}/version_query/__init__.py +0 -0
  23. {version_query-1.6.3 → version_query-1.7.0}/version_query/__main__.py +0 -0
  24. {version_query-1.6.3 → version_query-1.7.0}/version_query/_version.py +0 -0
  25. {version_query-1.6.3 → version_query-1.7.0}/version_query/git_query.py +0 -0
  26. {version_query-1.6.3 → version_query-1.7.0}/version_query/main.py +0 -0
  27. {version_query-1.6.3 → version_query-1.7.0}/version_query/parser.py +0 -0
  28. {version_query-1.6.3 → version_query-1.7.0}/version_query/patterns.py +0 -0
  29. {version_query-1.6.3 → version_query-1.7.0}/version_query/py.typed +0 -0
  30. {version_query-1.6.3 → version_query-1.7.0}/version_query/py_query.py +0 -0
  31. {version_query-1.6.3 → version_query-1.7.0}/version_query/query.py +0 -0
  32. {version_query-1.6.3 → version_query-1.7.0}/version_query/version.py +0 -0
  33. {version_query-1.6.3 → version_query-1.7.0}/version_query.egg-info/dependency_links.txt +0 -0
  34. {version_query-1.6.3 → version_query-1.7.0}/version_query.egg-info/requires.txt +0 -0
  35. {version_query-1.6.3 → version_query-1.7.0}/version_query.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: version-query
3
- Version: 1.6.3
3
+ Version: 1.7.0
4
4
  Summary: Zero-overhead package versioning for Python.
5
5
  Home-page: https://github.com/mbdevpl/version-query
6
6
  Download-URL:
@@ -81,7 +81,7 @@ Zero-overhead package versioning for Python.
81
81
  :alt: grade from Codacy
82
82
 
83
83
  .. image:: https://img.shields.io/github/license/mbdevpl/version-query.svg
84
- :target: https://github.com/mbdevpl/version-query/blob/v1.6.3/NOTICE
84
+ :target: https://github.com/mbdevpl/version-query/blob/v1.7.0/NOTICE
85
85
  :alt: license
86
86
 
87
87
  Package versioning toolkit for Python which relies on git tags, git history traversal
@@ -94,34 +94,43 @@ for easier development, testing and pre-release deployment?!
94
94
 
95
95
  Search no more!
96
96
 
97
- As long as you mark your releases using git tags, instead of hardcoding:
97
+ As long as you use git and you mark your releases using git tags, version-query will do the rest.
98
98
 
99
- .. code:: python
99
+ It's 21st century, stop hardcoding version numbers!
100
100
 
101
- __version__ = '1.5.0.dev2'
101
+ .. contents::
102
+ :backlinks: none
102
103
 
103
- You can do:
104
104
 
105
- .. code:: python
105
+ Overview
106
+ ========
106
107
 
107
- from version_query import predict_version_str
108
+ There are two main ways of using version-query - at runtime or at build time.
108
109
 
109
- __version__ = predict_version_str()
110
+ Using at runtime
111
+ ----------------
110
112
 
111
- It's 21st century, stop hardcoding version numbers!
113
+ When using this way, version-query is needed as a runtime dependency of your package.
112
114
 
113
- This will set the version to release version when you really release a new version,
114
- and it will automatically generate a suitable development version at development/pre-release phase.
115
+ If, for example, you have a constant storing the version of your package in some Python module:
115
116
 
117
+ .. code:: python
116
118
 
117
- .. contents::
118
- :backlinks: none
119
+ VERSION = '1.5.0.dev2'
119
120
 
121
+ You can do the following instead of hardcoding it:
120
122
 
121
- Overview
122
- ========
123
+ .. code:: python
123
124
 
124
- At development time, the current version number is automatically generated based on:
125
+ from version_query import predict_version_str
126
+
127
+ VERSION = predict_version_str()
128
+
129
+ This will set the version to release version when you really release a new version,
130
+ and it will automatically generate a suitable development version at development/pre-release phase.
131
+
132
+ When your package is imported while running from inside the repository, such as during development,
133
+ the current version number is automatically generated based on:
125
134
 
126
135
  * tags
127
136
  * current commit SHA
@@ -134,16 +143,88 @@ or at runtime) then the script relies on metadata generated at packaging time.
134
143
  That's why, regardless if package is installed from PyPI (from source or wheel distribution)
135
144
  or cloned from GitHub, the version query will work.
136
145
 
137
- Additionally, version numbers in version-query are mutable objects and they can be conveniently
138
- incremented, compared with each other, as well as converted to/from other popular
139
- versioning formats.
146
+ Using at build time
147
+ -------------------
148
+
149
+ This is the way to go if you want to use version-query only as a dependency when building
150
+ the package, in such case it's not necessary to to add it to runtime dependencies.
151
+
152
+ There are many build systems available for Python, and version-query may not be compatible
153
+ with all of them. Below are some examples.
154
+
155
+ setuptools with ``setup.py`` script
156
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157
+
158
+ This is a legacy way of building Python packages, but it is still widely used.
159
+
160
+ In such setup, you just need to add the following to your ``setup.py`` file:
161
+
162
+ .. code:: python
163
+
164
+ import setuptools
165
+ from version_query import predict_version_str
166
+
167
+
168
+ setuptools.setup(
169
+ ...,
170
+ version=predict_version_str()
171
+ )
172
+
173
+ If you are already using version-query at runtime in your package to set a constant
174
+ (for example ``my_package.VERSION``, please see "Using at runtime" section above for details),
175
+ you may instead reuse the same constant in your ``setup.py`` file:
176
+
177
+ .. code:: python
178
+
179
+ import setuptools
180
+
181
+ from my_package import VERSION
182
+
183
+
184
+ setuptools.setup(
185
+ ...,
186
+ version=VERSION
187
+ )
188
+
189
+ dynamic version attribute in ``pyproject.toml``
190
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191
+
192
+ A more modern approach in Python is to use ``pyproject.toml`` for building packages.
193
+
194
+ Some build systems that use ``pyproject.toml`` support setting the version dynamically
195
+ by allowing users to point to an attribute of some module in order to get the version.
196
+
197
+ One of such packages is setuptools. When using it, one can do the following:
198
+
199
+ .. code:: toml
200
+
201
+ [project]
202
+ dynamic = ["version"]
203
+ ...
204
+
205
+ [build-system]
206
+ requires = ["setuptools >= 70.0"]
207
+ build-backend = "setuptools.build_meta"
208
+
209
+ [tool.setuptools.dynamic]
210
+ version = {attr = "version_query.local_git_version.PREDICTED"}
211
+
212
+ Depending on how you build your package, the build system may copy files to a temporary folder
213
+ when building. In such case, you need to set ``PROJECT_FOLDER`` environment variable
214
+ to the current working directory before running the build command.
215
+
216
+ For example, when using ``build`` package:
217
+
218
+ .. code:: bash
219
+
220
+ PROJECT_FOLDER=$(pwd) python3 -m build
140
221
 
141
222
  Versioning scheme
142
223
  =================
143
224
 
144
225
  Version scheme used by version-query is a relaxed mixture of:
145
226
 
146
- * `Semantic Versioning 2.0.0 <http://semver.org/>`_ and
227
+ * `Semantic Versioning 2.0.0 <http://semver.org/>`__ and
147
228
 
148
229
  * `PEP 440 -- Version Identification and Dependency Specification <https://www.python.org/dev/peps/pep-0440/>`_.
149
230
 
@@ -328,7 +409,7 @@ The base specification of the comparison scheme is:
328
409
 
329
410
  * `PEP 508 -- Dependency specification for Python Software Packages <https://www.python.org/dev/peps/pep-0508/>`_ as well as
330
411
 
331
- * `Semantic Versioning 2.0.0 <http://semver.org/>`_.
412
+ * `Semantic Versioning 2.0.0 <http://semver.org/>`__.
332
413
 
333
414
  With the notable difference to both that all version components are taken into account when
334
415
  establishing version precedence.
@@ -426,7 +507,7 @@ The Version objects are mutable, hashable and comparable.
426
507
  version = version_query.query_caller(stack_level=1)
427
508
  version = version_query.predict_caller(2)
428
509
 
429
- Version object can be obtained for any supported path, as well as for any python code
510
+ Version object can be obtained for any supported path, as well as for any Python code
430
511
  currently being executed -- as long as it is located in a supported location.
431
512
 
432
513
 
@@ -491,8 +572,8 @@ Requirements
491
572
 
492
573
  Python version 3.9 or later.
493
574
 
494
- Python libraries as specified in `requirements.txt <https://github.com/mbdevpl/version-query/blob/v1.6.3/requirements.txt>`_.
575
+ Python libraries as specified in `requirements.txt <https://github.com/mbdevpl/version-query/blob/v1.7.0/requirements.txt>`_.
495
576
 
496
- Building and running tests additionally requires packages listed in `requirements_test.txt <https://github.com/mbdevpl/version-query/blob/v1.6.3/requirements_test.txt>`_.
577
+ Building and running tests additionally requires packages listed in `requirements_test.txt <https://github.com/mbdevpl/version-query/blob/v1.7.0/requirements_test.txt>`_.
497
578
 
498
579
  Tested on Linux, macOS and Windows.
@@ -41,34 +41,43 @@ for easier development, testing and pre-release deployment?!
41
41
 
42
42
  Search no more!
43
43
 
44
- As long as you mark your releases using git tags, instead of hardcoding:
44
+ As long as you use git and you mark your releases using git tags, version-query will do the rest.
45
45
 
46
- .. code:: python
46
+ It's 21st century, stop hardcoding version numbers!
47
47
 
48
- __version__ = '1.5.0.dev2'
48
+ .. contents::
49
+ :backlinks: none
49
50
 
50
- You can do:
51
51
 
52
- .. code:: python
52
+ Overview
53
+ ========
53
54
 
54
- from version_query import predict_version_str
55
+ There are two main ways of using version-query - at runtime or at build time.
55
56
 
56
- __version__ = predict_version_str()
57
+ Using at runtime
58
+ ----------------
57
59
 
58
- It's 21st century, stop hardcoding version numbers!
60
+ When using this way, version-query is needed as a runtime dependency of your package.
59
61
 
60
- This will set the version to release version when you really release a new version,
61
- and it will automatically generate a suitable development version at development/pre-release phase.
62
+ If, for example, you have a constant storing the version of your package in some Python module:
62
63
 
64
+ .. code:: python
63
65
 
64
- .. contents::
65
- :backlinks: none
66
+ VERSION = '1.5.0.dev2'
66
67
 
68
+ You can do the following instead of hardcoding it:
67
69
 
68
- Overview
69
- ========
70
+ .. code:: python
70
71
 
71
- At development time, the current version number is automatically generated based on:
72
+ from version_query import predict_version_str
73
+
74
+ VERSION = predict_version_str()
75
+
76
+ This will set the version to release version when you really release a new version,
77
+ and it will automatically generate a suitable development version at development/pre-release phase.
78
+
79
+ When your package is imported while running from inside the repository, such as during development,
80
+ the current version number is automatically generated based on:
72
81
 
73
82
  * tags
74
83
  * current commit SHA
@@ -81,16 +90,88 @@ or at runtime) then the script relies on metadata generated at packaging time.
81
90
  That's why, regardless if package is installed from PyPI (from source or wheel distribution)
82
91
  or cloned from GitHub, the version query will work.
83
92
 
84
- Additionally, version numbers in version-query are mutable objects and they can be conveniently
85
- incremented, compared with each other, as well as converted to/from other popular
86
- versioning formats.
93
+ Using at build time
94
+ -------------------
95
+
96
+ This is the way to go if you want to use version-query only as a dependency when building
97
+ the package, in such case it's not necessary to to add it to runtime dependencies.
98
+
99
+ There are many build systems available for Python, and version-query may not be compatible
100
+ with all of them. Below are some examples.
101
+
102
+ setuptools with ``setup.py`` script
103
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104
+
105
+ This is a legacy way of building Python packages, but it is still widely used.
106
+
107
+ In such setup, you just need to add the following to your ``setup.py`` file:
108
+
109
+ .. code:: python
110
+
111
+ import setuptools
112
+ from version_query import predict_version_str
113
+
114
+
115
+ setuptools.setup(
116
+ ...,
117
+ version=predict_version_str()
118
+ )
119
+
120
+ If you are already using version-query at runtime in your package to set a constant
121
+ (for example ``my_package.VERSION``, please see "Using at runtime" section above for details),
122
+ you may instead reuse the same constant in your ``setup.py`` file:
123
+
124
+ .. code:: python
125
+
126
+ import setuptools
127
+
128
+ from my_package import VERSION
129
+
130
+
131
+ setuptools.setup(
132
+ ...,
133
+ version=VERSION
134
+ )
135
+
136
+ dynamic version attribute in ``pyproject.toml``
137
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
138
+
139
+ A more modern approach in Python is to use ``pyproject.toml`` for building packages.
140
+
141
+ Some build systems that use ``pyproject.toml`` support setting the version dynamically
142
+ by allowing users to point to an attribute of some module in order to get the version.
143
+
144
+ One of such packages is setuptools. When using it, one can do the following:
145
+
146
+ .. code:: toml
147
+
148
+ [project]
149
+ dynamic = ["version"]
150
+ ...
151
+
152
+ [build-system]
153
+ requires = ["setuptools >= 70.0"]
154
+ build-backend = "setuptools.build_meta"
155
+
156
+ [tool.setuptools.dynamic]
157
+ version = {attr = "version_query.local_git_version.PREDICTED"}
158
+
159
+ Depending on how you build your package, the build system may copy files to a temporary folder
160
+ when building. In such case, you need to set ``PROJECT_FOLDER`` environment variable
161
+ to the current working directory before running the build command.
162
+
163
+ For example, when using ``build`` package:
164
+
165
+ .. code:: bash
166
+
167
+ PROJECT_FOLDER=$(pwd) python3 -m build
87
168
 
88
169
  Versioning scheme
89
170
  =================
90
171
 
91
172
  Version scheme used by version-query is a relaxed mixture of:
92
173
 
93
- * `Semantic Versioning 2.0.0 <http://semver.org/>`_ and
174
+ * `Semantic Versioning 2.0.0 <http://semver.org/>`__ and
94
175
 
95
176
  * `PEP 440 -- Version Identification and Dependency Specification <https://www.python.org/dev/peps/pep-0440/>`_.
96
177
 
@@ -275,7 +356,7 @@ The base specification of the comparison scheme is:
275
356
 
276
357
  * `PEP 508 -- Dependency specification for Python Software Packages <https://www.python.org/dev/peps/pep-0508/>`_ as well as
277
358
 
278
- * `Semantic Versioning 2.0.0 <http://semver.org/>`_.
359
+ * `Semantic Versioning 2.0.0 <http://semver.org/>`__.
279
360
 
280
361
  With the notable difference to both that all version components are taken into account when
281
362
  establishing version precedence.
@@ -373,7 +454,7 @@ The Version objects are mutable, hashable and comparable.
373
454
  version = version_query.query_caller(stack_level=1)
374
455
  version = version_query.predict_caller(2)
375
456
 
376
- Version object can be obtained for any supported path, as well as for any python code
457
+ Version object can be obtained for any supported path, as well as for any Python code
377
458
  currently being executed -- as long as it is located in a supported location.
378
459
 
379
460
 
@@ -0,0 +1,21 @@
1
+ """Tests of local_git_version module."""
2
+
3
+ import logging
4
+
5
+ import unittest
6
+
7
+
8
+ from version_query.local_git_version import QUERIED, PREDICTED
9
+
10
+ _LOG = logging.getLogger(__name__)
11
+
12
+
13
+ class Tests(unittest.TestCase):
14
+
15
+ def test_queried(self):
16
+ _LOG.debug('QUERIED: %s', QUERIED)
17
+ self.assertIsInstance(QUERIED, str)
18
+
19
+ def test_predicted(self):
20
+ _LOG.debug('PREDICTED: %s', PREDICTED)
21
+ self.assertIsInstance(PREDICTED, str)
@@ -23,6 +23,15 @@ _LOG = logging.getLogger(__name__)
23
23
 
24
24
 
25
25
  class Tests(unittest.TestCase):
26
+ """Test querying tools from several modules.
27
+
28
+ Note:
29
+
30
+ Tests that run setup script directly fail due to conflict between distutils used internally
31
+ by setuptools and distutils used internally by pip. For more information, see:
32
+ - https://github.com/pypa/setuptools/issues/3297
33
+ - https://github.com/pypa/pip/issues/8761
34
+ """
26
35
 
27
36
  def _check_examples_count(self, description, examples):
28
37
  lvl = logging.WARNING if len(examples) < 10 else logging.INFO
@@ -87,6 +96,7 @@ class Tests(unittest.TestCase):
87
96
 
88
97
  @unittest.skipUnless(
89
98
  os.environ.get('TEST_PACKAGING') or os.environ.get('CI'), 'skipping packaging test')
99
+ @unittest.skipIf(sys.version_info < (3, 12), 'requires Python 3.12+')
90
100
  def test_query_pkg_info_current(self):
91
101
  with preserve_logger_level('version_query'):
92
102
  run_module('setup', 'build')
@@ -120,6 +130,7 @@ class Tests(unittest.TestCase):
120
130
 
121
131
  @unittest.skipUnless(
122
132
  os.environ.get('TEST_PACKAGING') or os.environ.get('CI'), 'skipping packaging test')
133
+ @unittest.skipIf(sys.version_info < (3, 12), 'requires Python 3.12+')
123
134
  def test_query_package_folder_current(self):
124
135
  with preserve_logger_level('version_query'):
125
136
  run_module('setup', 'build')
@@ -0,0 +1,22 @@
1
+ """Use this module when reading the version from an attribute is needed without Python code.
2
+
3
+ For example, when using setuptools in pyproject.toml,
4
+ one can set the version dynamically as follows:
5
+
6
+ [project]
7
+ dynamic = ["version"]
8
+ ...
9
+
10
+ [tool.setuptools.dynamic]
11
+ version = {attr = "version_query.local_git_version.PREDICTED"}
12
+ """
13
+
14
+ import os
15
+ import pathlib
16
+
17
+ from .git_query import query_git_repo, predict_git_repo
18
+
19
+ _CURRENT_FOLDER: pathlib.Path = pathlib.Path()
20
+ _PROJECT_FOLDER: pathlib.Path = pathlib.Path(os.environ.get('PROJECT_FOLDER', _CURRENT_FOLDER))
21
+ QUERIED: str = query_git_repo(_PROJECT_FOLDER).to_str()
22
+ PREDICTED: str = predict_git_repo(_PROJECT_FOLDER).to_str()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: version-query
3
- Version: 1.6.3
3
+ Version: 1.7.0
4
4
  Summary: Zero-overhead package versioning for Python.
5
5
  Home-page: https://github.com/mbdevpl/version-query
6
6
  Download-URL:
@@ -81,7 +81,7 @@ Zero-overhead package versioning for Python.
81
81
  :alt: grade from Codacy
82
82
 
83
83
  .. image:: https://img.shields.io/github/license/mbdevpl/version-query.svg
84
- :target: https://github.com/mbdevpl/version-query/blob/v1.6.3/NOTICE
84
+ :target: https://github.com/mbdevpl/version-query/blob/v1.7.0/NOTICE
85
85
  :alt: license
86
86
 
87
87
  Package versioning toolkit for Python which relies on git tags, git history traversal
@@ -94,34 +94,43 @@ for easier development, testing and pre-release deployment?!
94
94
 
95
95
  Search no more!
96
96
 
97
- As long as you mark your releases using git tags, instead of hardcoding:
97
+ As long as you use git and you mark your releases using git tags, version-query will do the rest.
98
98
 
99
- .. code:: python
99
+ It's 21st century, stop hardcoding version numbers!
100
100
 
101
- __version__ = '1.5.0.dev2'
101
+ .. contents::
102
+ :backlinks: none
102
103
 
103
- You can do:
104
104
 
105
- .. code:: python
105
+ Overview
106
+ ========
106
107
 
107
- from version_query import predict_version_str
108
+ There are two main ways of using version-query - at runtime or at build time.
108
109
 
109
- __version__ = predict_version_str()
110
+ Using at runtime
111
+ ----------------
110
112
 
111
- It's 21st century, stop hardcoding version numbers!
113
+ When using this way, version-query is needed as a runtime dependency of your package.
112
114
 
113
- This will set the version to release version when you really release a new version,
114
- and it will automatically generate a suitable development version at development/pre-release phase.
115
+ If, for example, you have a constant storing the version of your package in some Python module:
115
116
 
117
+ .. code:: python
116
118
 
117
- .. contents::
118
- :backlinks: none
119
+ VERSION = '1.5.0.dev2'
119
120
 
121
+ You can do the following instead of hardcoding it:
120
122
 
121
- Overview
122
- ========
123
+ .. code:: python
123
124
 
124
- At development time, the current version number is automatically generated based on:
125
+ from version_query import predict_version_str
126
+
127
+ VERSION = predict_version_str()
128
+
129
+ This will set the version to release version when you really release a new version,
130
+ and it will automatically generate a suitable development version at development/pre-release phase.
131
+
132
+ When your package is imported while running from inside the repository, such as during development,
133
+ the current version number is automatically generated based on:
125
134
 
126
135
  * tags
127
136
  * current commit SHA
@@ -134,16 +143,88 @@ or at runtime) then the script relies on metadata generated at packaging time.
134
143
  That's why, regardless if package is installed from PyPI (from source or wheel distribution)
135
144
  or cloned from GitHub, the version query will work.
136
145
 
137
- Additionally, version numbers in version-query are mutable objects and they can be conveniently
138
- incremented, compared with each other, as well as converted to/from other popular
139
- versioning formats.
146
+ Using at build time
147
+ -------------------
148
+
149
+ This is the way to go if you want to use version-query only as a dependency when building
150
+ the package, in such case it's not necessary to to add it to runtime dependencies.
151
+
152
+ There are many build systems available for Python, and version-query may not be compatible
153
+ with all of them. Below are some examples.
154
+
155
+ setuptools with ``setup.py`` script
156
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
157
+
158
+ This is a legacy way of building Python packages, but it is still widely used.
159
+
160
+ In such setup, you just need to add the following to your ``setup.py`` file:
161
+
162
+ .. code:: python
163
+
164
+ import setuptools
165
+ from version_query import predict_version_str
166
+
167
+
168
+ setuptools.setup(
169
+ ...,
170
+ version=predict_version_str()
171
+ )
172
+
173
+ If you are already using version-query at runtime in your package to set a constant
174
+ (for example ``my_package.VERSION``, please see "Using at runtime" section above for details),
175
+ you may instead reuse the same constant in your ``setup.py`` file:
176
+
177
+ .. code:: python
178
+
179
+ import setuptools
180
+
181
+ from my_package import VERSION
182
+
183
+
184
+ setuptools.setup(
185
+ ...,
186
+ version=VERSION
187
+ )
188
+
189
+ dynamic version attribute in ``pyproject.toml``
190
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
191
+
192
+ A more modern approach in Python is to use ``pyproject.toml`` for building packages.
193
+
194
+ Some build systems that use ``pyproject.toml`` support setting the version dynamically
195
+ by allowing users to point to an attribute of some module in order to get the version.
196
+
197
+ One of such packages is setuptools. When using it, one can do the following:
198
+
199
+ .. code:: toml
200
+
201
+ [project]
202
+ dynamic = ["version"]
203
+ ...
204
+
205
+ [build-system]
206
+ requires = ["setuptools >= 70.0"]
207
+ build-backend = "setuptools.build_meta"
208
+
209
+ [tool.setuptools.dynamic]
210
+ version = {attr = "version_query.local_git_version.PREDICTED"}
211
+
212
+ Depending on how you build your package, the build system may copy files to a temporary folder
213
+ when building. In such case, you need to set ``PROJECT_FOLDER`` environment variable
214
+ to the current working directory before running the build command.
215
+
216
+ For example, when using ``build`` package:
217
+
218
+ .. code:: bash
219
+
220
+ PROJECT_FOLDER=$(pwd) python3 -m build
140
221
 
141
222
  Versioning scheme
142
223
  =================
143
224
 
144
225
  Version scheme used by version-query is a relaxed mixture of:
145
226
 
146
- * `Semantic Versioning 2.0.0 <http://semver.org/>`_ and
227
+ * `Semantic Versioning 2.0.0 <http://semver.org/>`__ and
147
228
 
148
229
  * `PEP 440 -- Version Identification and Dependency Specification <https://www.python.org/dev/peps/pep-0440/>`_.
149
230
 
@@ -328,7 +409,7 @@ The base specification of the comparison scheme is:
328
409
 
329
410
  * `PEP 508 -- Dependency specification for Python Software Packages <https://www.python.org/dev/peps/pep-0508/>`_ as well as
330
411
 
331
- * `Semantic Versioning 2.0.0 <http://semver.org/>`_.
412
+ * `Semantic Versioning 2.0.0 <http://semver.org/>`__.
332
413
 
333
414
  With the notable difference to both that all version components are taken into account when
334
415
  establishing version precedence.
@@ -426,7 +507,7 @@ The Version objects are mutable, hashable and comparable.
426
507
  version = version_query.query_caller(stack_level=1)
427
508
  version = version_query.predict_caller(2)
428
509
 
429
- Version object can be obtained for any supported path, as well as for any python code
510
+ Version object can be obtained for any supported path, as well as for any Python code
430
511
  currently being executed -- as long as it is located in a supported location.
431
512
 
432
513
 
@@ -491,8 +572,8 @@ Requirements
491
572
 
492
573
  Python version 3.9 or later.
493
574
 
494
- Python libraries as specified in `requirements.txt <https://github.com/mbdevpl/version-query/blob/v1.6.3/requirements.txt>`_.
575
+ Python libraries as specified in `requirements.txt <https://github.com/mbdevpl/version-query/blob/v1.7.0/requirements.txt>`_.
495
576
 
496
- Building and running tests additionally requires packages listed in `requirements_test.txt <https://github.com/mbdevpl/version-query/blob/v1.6.3/requirements_test.txt>`_.
577
+ Building and running tests additionally requires packages listed in `requirements_test.txt <https://github.com/mbdevpl/version-query/blob/v1.7.0/requirements_test.txt>`_.
497
578
 
498
579
  Tested on Linux, macOS and Windows.
@@ -10,6 +10,7 @@ setup.py
10
10
  ./test/examples.py
11
11
  ./test/test_cli.py
12
12
  ./test/test_git.py
13
+ ./test/test_local_git_version.py
13
14
  ./test/test_packaging.py
14
15
  ./test/test_query.py
15
16
  ./test/test_version.py
@@ -17,6 +18,7 @@ setup.py
17
18
  ./version_query/__main__.py
18
19
  ./version_query/_version.py
19
20
  ./version_query/git_query.py
21
+ ./version_query/local_git_version.py
20
22
  ./version_query/main.py
21
23
  ./version_query/parser.py
22
24
  ./version_query/patterns.py
@@ -28,6 +30,7 @@ test/__init__.py
28
30
  test/examples.py
29
31
  test/test_cli.py
30
32
  test/test_git.py
33
+ test/test_local_git_version.py
31
34
  test/test_packaging.py
32
35
  test/test_query.py
33
36
  test/test_version.py
@@ -35,6 +38,7 @@ version_query/__init__.py
35
38
  version_query/__main__.py
36
39
  version_query/_version.py
37
40
  version_query/git_query.py
41
+ version_query/local_git_version.py
38
42
  version_query/main.py
39
43
  version_query/parser.py
40
44
  version_query/patterns.py
File without changes
File without changes
File without changes
File without changes
File without changes