plexus-python-setup 1.1.24__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
plexus/setup/__init__.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import importlib.metadata
|
|
2
|
+
import os
|
|
3
|
+
import pathlib
|
|
4
|
+
|
|
5
|
+
import setuptools
|
|
6
|
+
|
|
7
|
+
try:
|
|
8
|
+
__version__ = importlib.metadata.version("plexus-python-setup")
|
|
9
|
+
except importlib.metadata.PackageNotFoundError:
|
|
10
|
+
__version__ = "unknown"
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"version_string_local",
|
|
14
|
+
"version_string_scm",
|
|
15
|
+
"version_string",
|
|
16
|
+
"setup",
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def read_version_tuple(
|
|
21
|
+
cwd: str | os.PathLike[str] | None,
|
|
22
|
+
*,
|
|
23
|
+
version_file: str,
|
|
24
|
+
patch_env_var: str,
|
|
25
|
+
) -> tuple[int, int, int]:
|
|
26
|
+
cwd = pathlib.Path(os.getcwd()) if cwd is None else pathlib.Path(cwd)
|
|
27
|
+
|
|
28
|
+
with open(cwd / version_file, "r", encoding="utf-8") as fh:
|
|
29
|
+
major_str, minor_str, *patch_strs = fh.read().strip().split(".")
|
|
30
|
+
|
|
31
|
+
major = max(0, int(major_str))
|
|
32
|
+
minor = max(0, int(minor_str))
|
|
33
|
+
|
|
34
|
+
patch_str = patch_strs[0] if len(patch_strs) > 0 else os.getenv(patch_env_var)
|
|
35
|
+
patch = 0 if patch_str is None else min(999999, max(0, int(patch_str)))
|
|
36
|
+
|
|
37
|
+
return major, minor, patch
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def version_string_local(
|
|
41
|
+
cwd: str | os.PathLike[str] | None,
|
|
42
|
+
*,
|
|
43
|
+
version_file: str,
|
|
44
|
+
patch_env_var: str,
|
|
45
|
+
) -> str:
|
|
46
|
+
major, minor, patch = read_version_tuple(cwd, version_file=version_file, patch_env_var=patch_env_var)
|
|
47
|
+
return f"{major}.{minor}.{patch}"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def version_string_scm(
|
|
51
|
+
cwd: str | os.PathLike[str] | None,
|
|
52
|
+
*,
|
|
53
|
+
version_file: str,
|
|
54
|
+
patch_env_var: str,
|
|
55
|
+
scm_branch_name: str,
|
|
56
|
+
scm_branch_env_var: str,
|
|
57
|
+
) -> str:
|
|
58
|
+
import setuptools_scm
|
|
59
|
+
cwd = pathlib.Path(os.getcwd()) if cwd is None else pathlib.Path(cwd)
|
|
60
|
+
|
|
61
|
+
def find_scm_root(cd: pathlib.Path) -> pathlib.Path:
|
|
62
|
+
cd = cd.absolute()
|
|
63
|
+
for item in cd.iterdir():
|
|
64
|
+
if item.is_dir() and item.name == ".git":
|
|
65
|
+
return cd
|
|
66
|
+
if cd.parent == cd:
|
|
67
|
+
raise ValueError("cannot find SCM root")
|
|
68
|
+
return find_scm_root(cd.parent)
|
|
69
|
+
|
|
70
|
+
def version_scheme_callback(scm_version: setuptools_scm.ScmVersion) -> str:
|
|
71
|
+
major, minor, patch = read_version_tuple(cwd, version_file=version_file, patch_env_var=patch_env_var)
|
|
72
|
+
if scm_version.branch == scm_branch_name or os.getenv(scm_branch_env_var) == scm_branch_name:
|
|
73
|
+
return f"{major}.{minor}.{patch}"
|
|
74
|
+
return f"{major}.{minor}.{0}"
|
|
75
|
+
|
|
76
|
+
def local_scheme_callback(scm_version: setuptools_scm.ScmVersion) -> str:
|
|
77
|
+
if scm_version.branch == scm_branch_name or os.getenv(scm_branch_env_var) == scm_branch_name:
|
|
78
|
+
return ""
|
|
79
|
+
if scm_version.dirty:
|
|
80
|
+
return scm_version.format_with("+{node}.dirty")
|
|
81
|
+
return scm_version.format_with("+{node}")
|
|
82
|
+
|
|
83
|
+
return setuptools_scm.get_version(root=find_scm_root(cwd),
|
|
84
|
+
version_scheme=version_scheme_callback,
|
|
85
|
+
local_scheme=local_scheme_callback,
|
|
86
|
+
normalize=True)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def version_string(
|
|
90
|
+
cwd: str | os.PathLike[str] | None = None,
|
|
91
|
+
default: str = "0.0.0",
|
|
92
|
+
*,
|
|
93
|
+
version_file: str = "VERSION",
|
|
94
|
+
patch_env_var: str = "BUILD_NUMBER",
|
|
95
|
+
scm_branch_name: str = "master",
|
|
96
|
+
scm_branch_env_var: str = "GIT_BRANCH",
|
|
97
|
+
strict: bool = False,
|
|
98
|
+
) -> str:
|
|
99
|
+
try:
|
|
100
|
+
return version_string_scm(cwd,
|
|
101
|
+
version_file=version_file,
|
|
102
|
+
patch_env_var=patch_env_var,
|
|
103
|
+
scm_branch_name=scm_branch_name,
|
|
104
|
+
scm_branch_env_var=scm_branch_env_var)
|
|
105
|
+
except Exception as e:
|
|
106
|
+
if strict:
|
|
107
|
+
raise e
|
|
108
|
+
|
|
109
|
+
try:
|
|
110
|
+
return version_string_local(cwd,
|
|
111
|
+
version_file=version_file,
|
|
112
|
+
patch_env_var=patch_env_var)
|
|
113
|
+
except Exception as e:
|
|
114
|
+
pass
|
|
115
|
+
return default
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def setup(cwd: str | os.PathLike[str] | None = None, **kwargs):
|
|
119
|
+
setuptools.setup(version=version_string(cwd, **kwargs), **kwargs)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: plexus-python-setup
|
|
3
|
+
Version: 1.1.24
|
|
4
|
+
Classifier: Programming Language :: Python :: 3
|
|
5
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
6
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
7
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
9
|
+
Requires-Python: <3.15,>=3.11
|
|
10
|
+
Requires-Dist: setuptools>=80.0
|
|
11
|
+
Requires-Dist: setuptools-scm>=9.0
|
|
12
|
+
Provides-Extra: all
|
|
13
|
+
Requires-Dist: plexus-python-setup; extra == "all"
|
|
14
|
+
Provides-Extra: test
|
|
15
|
+
Requires-Dist: pytest-cov>=5.0; extra == "test"
|
|
16
|
+
Requires-Dist: pytest-order>=1.3; extra == "test"
|
|
17
|
+
Requires-Dist: pytest>=8.3; extra == "test"
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
plexus/setup/__init__.py,sha256=CYcDZv9BjJu0alqy1Qt3g0se1AdAdGyi46-L7JJXkwQ,3866
|
|
2
|
+
plexus_python_setup-1.1.24.dist-info/METADATA,sha256=HrzLIuFu9gC293FU89DdH8OB9aIgRqYvl5LWASA-jbo,647
|
|
3
|
+
plexus_python_setup-1.1.24.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
4
|
+
plexus_python_setup-1.1.24.dist-info/top_level.txt,sha256=ug_g7CVwaMQuas5UzAXbHUrQvKGCn8ezc6ZNvvRlJOE,7
|
|
5
|
+
plexus_python_setup-1.1.24.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
plexus
|