File tree Expand file tree Collapse file tree 3 files changed +25
-0
lines changed
Expand file tree Collapse file tree 3 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 1+ Describe how to get version from a file
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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)
You can’t perform that action at this time.
0 commit comments