We version all our company packages with a simple datetime version. Now we are considering moving to pyproject.toml instead of setup.py. Is it possible to do flexible versioning there as well?
version = datetime.datetime.now().strftime('%Y.%m.%d.%H%M')
# Actual setup
setup(
name="some-package",
version=version,
description='Some description',
packages=find_namespace_packages(where='src', include=['company.project.*']),
package_dir={'': 'src'},
python_requires='>=3.6',
install_requires=[
'numpy',
'numba'
],
)
What syntax do I need to adjust the versioning in the pyproject.toml? This one is using poetry but there is no need for that.
[tool.poetry]
name = "some-package"
version = "0.1.0"
description = ""
readme = "README.md"
Poetry does not seem to support that, see issue #4299 for example.
But Flit does. Flit allows us to declare the version as "dynamic" in pyproject.toml:
[project]
name = 'some_package'
dynamic = ['version']
description = 'Description of the package.'
[build-system]
requires = ['flit_core>=3.2,<4']
build-backend = 'flit_core.buildapi'
The version is then determined by the package's __version__ attribute. For example, __init__.py could contain this:
import datetime
__version__ = datetime.datetime.now().strftime('%Y.%m.%d.%H%M')
Note, however, that in your specific case, when building the package with flit build, Flit will observe that the version number does not comply with PEP 440 and normalize it accordingly, i.e. remove leading zeros from day and month numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With