Skip to content

Commit ffe686a

Browse files
committed
Add topic to read version from file
Fix python-semver#340
1 parent 54a1af6 commit ffe686a

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

changelog.d/340.doc.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Describe how to get version from a file

docs/advanced/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Advanced topics
99
display-deprecation-warnings
1010
combine-pydantic-and-semver
1111
convert-pypi-to-semver
12+
version-from-file

docs/advanced/version-from-file.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. _sec_reading_versions_from_file:
2+
3+
Reading versions from file
4+
==========================
5+
6+
In cases where a version is stored inside a file, one possible solution
7+
is to use the following function:
8+
9+
.. code-block:: python
10+
11+
from semver.version import Version
12+
13+
def get_version(path: str = "version") -> Version:
14+
"""
15+
Construct a Version from a file
16+
17+
:param path: A text file only containing the semantic version
18+
:return: A :class:`Version` object containing the semantic
19+
version from the file.
20+
"""
21+
with open(path,"r") as fh:
22+
version = fh.read().strip()
23+
return Version.parse(version)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy