Skip to content

Commit 3512a8a

Browse files
committed
Reduce dependence on external libraries
1 parent ca98887 commit 3512a8a

File tree

5 files changed

+12
-25
lines changed

5 files changed

+12
-25
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ This utility targets modern Python projects which have layout generated by `Poet
2323
2424
This duplicity often leads to inconsistency when you, the author, forget to update both.
2525

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).
26+
*single-version* was 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).
2727

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.
28+
Years ago, to retrieve version for an installed package, people 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.
2929

3030

3131
Usage

poetry.lock

Lines changed: 1 addition & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "single-version"
3-
version = "1.4.1"
3+
version = "1.5"
44
description = "Small utility to define version string for Poetry-style Python project."
55
authors = ["Nguyễn Hồng Quân <ng.hong.quan@gmail.com>"]
66
maintainers = [
@@ -19,7 +19,6 @@ classifiers = [
1919
[tool.poetry.dependencies]
2020
python = "^3.6"
2121
importlib_metadata = { version = "^2.0", python = "< 3.8" }
22-
first = "^2.0"
2322

2423
[tool.poetry.dev-dependencies]
2524
pytest = "^5.2"

single_version/ver.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
import sys
33
from pathlib import Path
44

5-
from first import first
6-
75

86
__all__ = ('get_version',)
97

108

119
_REGEX_VERSION = re.compile(r'\s*version\s*=\s*["\']([.0-9a-z-+]+)["\']\s*$')
10+
FALLBACK_VERSION = '0.0.0'
1211

1312
pyver = sys.version_info[:2]
1413
if pyver <= (3, 7):
@@ -33,12 +32,13 @@ def get_version(package_name: str, looked_path: Path) -> str:
3332
# so, if we see that file, its mean that the package is imported from development folder.
3433
filepath = looked_path / 'pyproject.toml' # type: Path
3534
if filepath.exists():
36-
found = first(_REGEX_VERSION.match(line) for line in filepath.open())
37-
if not found:
38-
return '0.0'
39-
return found.group(1)
35+
for line in filepath.open():
36+
found = _REGEX_VERSION.match(line)
37+
if found:
38+
return found.group(1)
39+
return FALLBACK_VERSION
4040
try:
4141
return importlib_metadata.version(package_name)
4242
except importlib_metadata.PackageNotFoundError:
4343
pass
44-
return '0.0'
44+
return FALLBACK_VERSION

tests/test_single_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
def test_version():
6-
assert __version__ == '1.4.1'
6+
assert __version__ == '1.5'
77

88

99
def test_version_regex():

0 commit comments

Comments
 (0)