@@ -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
71
+
72
+ from version_query import predict_version_str
70
73
71
- At development time, the current version number is automatically generated based on:
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,9 +90,43 @@ 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 avialable 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
+ from version_query import predict_version_str
112
+
113
+ setup(
114
+ ... ,
115
+ version = predict_version_str()
116
+ )
117
+
118
+ If you are already using version-query at runtime in your package to set a constant
119
+ (for example ``my_package.VERSION ``, please see "Using at runtime" section above for details),
120
+ you may instead reuse the same constant in your ``setup.py `` file:
121
+
122
+ .. code :: python
123
+
124
+ from my_package import VERSION
125
+
126
+ setup(
127
+ ... ,
128
+ version = VERSION
129
+ )
87
130
88
131
Versioning scheme
89
132
=================
0 commit comments