Skip to content

Commit 164c522

Browse files
committed
First working commit
0 parents  commit 164c522

File tree

8 files changed

+690
-0
lines changed

8 files changed

+690
-0
lines changed

.gitignore

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
db.sqlite3
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/
105+
106+
# VS Code
107+
.vscode
108+
109+
110+
.node_modules
111+
node_modules

README.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
==============
2+
single-version
3+
==============
4+
5+
.. image:: https://madewithlove.now.sh/vn?heart=true&colorA=%23ffcd00&colorB=%23da251d
6+
.. image:: https://badgen.net/pypi/v/single-version
7+
8+
Utility to let you have a single source of version in your code base.
9+
10+
This utility targets modern Python projects which have layout generated by `Poetry`_, with a *pyproject.toml* file in place of *setup.py*. With this layout, the project initially has two places to maintain version string: one in *pyproject.toml* file and one in some *\*.py* file (normally *__init__.py*):
11+
12+
.. code-block:: toml
13+
14+
# pyproject.toml
15+
[tool.poetry]
16+
name = "your-package"
17+
version = "0.1.0"
18+
19+
.. code-block:: python
20+
21+
# your_package/__init__.py
22+
__version__ = "0.1.0"
23+
24+
This duplicity often leads to inconsistency when you, the author, forget to update both.
25+
26+
*single-version* is born to solve that headache circumstance. By convention, it chooses the *pyproject.toml* file as original source of version string. Your project's ``__version__`` variable then is computed from it. When your package is already deployed and installed to some system, the version string will be retrieved from that Python environment (the *pyproject.toml* is not included in distribution file).
27+
28+
Years ago, to retrieve version for an installed package, ones often used `pkg_resources`_, which has well-known issue of causing slow import. Learning from that mistake, *single-version* use |importlib.metadata|_, which becomes standard from Python 3.8, instead.
29+
30+
31+
Usage
32+
-----
33+
34+
Add ``single_version`` as your project dependency:
35+
36+
.. code-block:: sh
37+
38+
poetry add single-version
39+
40+
41+
Assume that you define ``__version__`` variable in `your_package/__init__.py` file:
42+
43+
.. code-block:: python
44+
45+
from pathlib import Path
46+
47+
from single_version import get_version
48+
49+
50+
__version__ = get_version('your_package', Path(__file__).parent.parent)
51+
52+
53+
.. _Poetry: https://python-poetry.org/
54+
.. _pkg_resources: https://setuptools.readthedocs.io/en/latest/pkg_resources.html
55+
.. |importlib.metadata| replace:: ``importlib.metadata``
56+
.. _importlib.metadata: https://docs.python.org/3.8/library/importlib.metadata.html

0 commit comments

Comments
 (0)