hatch-env-plus 1.0.0__tar.gz → 1.0.1__tar.gz
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.
- {hatch_env_plus-1.0.0 → hatch_env_plus-1.0.1}/PKG-INFO +8 -6
- {hatch_env_plus-1.0.0 → hatch_env_plus-1.0.1}/README.md +7 -5
- {hatch_env_plus-1.0.0 → hatch_env_plus-1.0.1}/pyproject.toml +4 -4
- hatch_env_plus-1.0.1/src/hatch_env_plus/plugin.py +16 -0
- {hatch_env_plus-1.0.0 → hatch_env_plus-1.0.1}/tests/test_plugin.py +30 -21
- hatch_env_plus-1.0.0/src/hatch_env_plus/plugin.py +0 -16
- {hatch_env_plus-1.0.0 → hatch_env_plus-1.0.1}/.gitignore +0 -0
- {hatch_env_plus-1.0.0 → hatch_env_plus-1.0.1}/LICENSE +0 -0
- {hatch_env_plus-1.0.0 → hatch_env_plus-1.0.1}/src/hatch_env_plus/__init__.py +0 -0
- {hatch_env_plus-1.0.0 → hatch_env_plus-1.0.1}/src/hatch_env_plus/hooks.py +0 -0
- {hatch_env_plus-1.0.0 → hatch_env_plus-1.0.1}/tests/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hatch-env-plus
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.1
|
|
4
4
|
Summary: A version source for Hatchling that reads the version from a given environment variable, but also allows for a fallback if the variable is not populated.
|
|
5
5
|
Project-URL: homepage, https://github.com/jenskeiner/hatch_env_plus/
|
|
6
6
|
Project-URL: repository, https://github.com/jenskeiner/hatch_env_plus.git
|
|
@@ -27,8 +27,9 @@ Description-Content-Type: text/markdown
|
|
|
27
27
|
|
|
28
28
|
# Hatchling Environment Variable Version Source
|
|
29
29
|
|
|
30
|
-
A Hatchling version source plugin that reads the version from an environment variable
|
|
31
|
-
since the built-in `env`
|
|
30
|
+
A [Hatchling](https://github.com/pypa/hatch) version source plugin that reads the version from an environment variable
|
|
31
|
+
with a configurable fallback value, since the built-in [`env`](https://hatch.pypa.io/latest/plugins/version-source/env/)
|
|
32
|
+
version source does not allow to define a fallback.
|
|
32
33
|
|
|
33
34
|
## Installation
|
|
34
35
|
|
|
@@ -62,12 +63,13 @@ fallback = "0.0.0dev0" # optional, default shown
|
|
|
62
63
|
|
|
63
64
|
Use the `variable` field to set the environment variable to use, and set `fallback` to the desired fallback version.
|
|
64
65
|
|
|
65
|
-
**Note: An empty string, whether from the configured environment variable or from the fallback, is an
|
|
66
|
+
**Note: An empty string, whether from the configured environment variable or from the fallback, is an
|
|
66
67
|
undefined version.**
|
|
67
68
|
|
|
68
69
|
If you explicitly set the configured environment variable to the empty string, your build will fail as no valid version
|
|
69
|
-
is set. If you explicitly set `fallback` to an empty string, your build will fail when the configured environment
|
|
70
|
-
variable is not set. This is the default behavior of Hatchling's built-in
|
|
70
|
+
is set. If you explicitly set `fallback` to an empty string, your build will fail when the configured environment
|
|
71
|
+
variable is not set. This is the default behavior of [Hatchling]([Hatchling](https://github.com/pypa/hatch))'s built-in
|
|
72
|
+
enviroment variable version source [`env`](https://hatch.pypa.io/latest/plugins/version-source/env/).
|
|
71
73
|
|
|
72
74
|
## Usage
|
|
73
75
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# Hatchling Environment Variable Version Source
|
|
2
2
|
|
|
3
|
-
A Hatchling version source plugin that reads the version from an environment variable
|
|
4
|
-
since the built-in `env`
|
|
3
|
+
A [Hatchling](https://github.com/pypa/hatch) version source plugin that reads the version from an environment variable
|
|
4
|
+
with a configurable fallback value, since the built-in [`env`](https://hatch.pypa.io/latest/plugins/version-source/env/)
|
|
5
|
+
version source does not allow to define a fallback.
|
|
5
6
|
|
|
6
7
|
## Installation
|
|
7
8
|
|
|
@@ -35,12 +36,13 @@ fallback = "0.0.0dev0" # optional, default shown
|
|
|
35
36
|
|
|
36
37
|
Use the `variable` field to set the environment variable to use, and set `fallback` to the desired fallback version.
|
|
37
38
|
|
|
38
|
-
**Note: An empty string, whether from the configured environment variable or from the fallback, is an
|
|
39
|
+
**Note: An empty string, whether from the configured environment variable or from the fallback, is an
|
|
39
40
|
undefined version.**
|
|
40
41
|
|
|
41
42
|
If you explicitly set the configured environment variable to the empty string, your build will fail as no valid version
|
|
42
|
-
is set. If you explicitly set `fallback` to an empty string, your build will fail when the configured environment
|
|
43
|
-
variable is not set. This is the default behavior of Hatchling's built-in
|
|
43
|
+
is set. If you explicitly set `fallback` to an empty string, your build will fail when the configured environment
|
|
44
|
+
variable is not set. This is the default behavior of [Hatchling]([Hatchling](https://github.com/pypa/hatch))'s built-in
|
|
45
|
+
enviroment variable version source [`env`](https://hatch.pypa.io/latest/plugins/version-source/env/).
|
|
44
46
|
|
|
45
47
|
## Usage
|
|
46
48
|
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.21.1", "hatch-env-plus>=1.0.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
1
5
|
[project]
|
|
2
6
|
name = "hatch-env-plus"
|
|
3
7
|
dynamic = ["version"]
|
|
@@ -40,10 +44,6 @@ dev = [
|
|
|
40
44
|
"pytest-cov>=7,<8",
|
|
41
45
|
]
|
|
42
46
|
|
|
43
|
-
[build-system]
|
|
44
|
-
requires = ["hatchling>=1.21.1", "hatch-env-plus>=0.1.0"]
|
|
45
|
-
build-backend = "hatchling.build"
|
|
46
|
-
|
|
47
47
|
[tool.hatch.build.targets.sdist]
|
|
48
48
|
include = [
|
|
49
49
|
"src/hatch_env_plus/**",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from hatchling.version.source.plugin.interface import VersionSourceInterface
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class EnvironmentVariableVersionSource(VersionSourceInterface):
|
|
7
|
+
PLUGIN_NAME = "env-plus"
|
|
8
|
+
|
|
9
|
+
def get_version_data(self) -> dict:
|
|
10
|
+
variable = self.config.get("variable", "PACKAGE_VERSION")
|
|
11
|
+
fallback = self.config.get("fallback", "0.0.0dev0") or None
|
|
12
|
+
version = os.environ.get(variable, None) or fallback
|
|
13
|
+
return {"version": version}
|
|
14
|
+
|
|
15
|
+
def set_version(self, version: str, version_data: dict) -> None:
|
|
16
|
+
version_data["version"] = version
|
|
@@ -9,64 +9,73 @@ def test_plugin_is_version_source():
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def test_plugin_name():
|
|
12
|
-
assert EnvironmentVariableVersionSource.PLUGIN_NAME ==
|
|
12
|
+
assert EnvironmentVariableVersionSource.PLUGIN_NAME == "env-plus"
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
def test_version_from_env_var():
|
|
16
16
|
"""Version is read from environment variable when set."""
|
|
17
|
-
plugin = EnvironmentVariableVersionSource(
|
|
17
|
+
plugin = EnvironmentVariableVersionSource("", {})
|
|
18
18
|
with pytest.MonkeyPatch().context() as m:
|
|
19
|
-
m.setenv(
|
|
19
|
+
m.setenv("PACKAGE_VERSION", "2.0.0")
|
|
20
20
|
data = plugin.get_version_data()
|
|
21
|
-
assert data == {
|
|
21
|
+
assert data == {"version": "2.0.0"}
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
def test_fallback_when_env_var_not_set():
|
|
25
25
|
"""Fallback value is used when environment variable is not set."""
|
|
26
|
-
plugin = EnvironmentVariableVersionSource(
|
|
26
|
+
plugin = EnvironmentVariableVersionSource("", {})
|
|
27
27
|
with pytest.MonkeyPatch().context() as m:
|
|
28
|
-
m.delenv(
|
|
28
|
+
m.delenv("PACKAGE_VERSION", raising=False)
|
|
29
29
|
data = plugin.get_version_data()
|
|
30
|
-
assert data == {
|
|
30
|
+
assert data == {"version": "0.0.0dev0"}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def test_fallback_when_env_var_empty_string():
|
|
34
|
+
"""Fallback value is used when environment variable is set to the empty string."""
|
|
35
|
+
plugin = EnvironmentVariableVersionSource("", {})
|
|
36
|
+
with pytest.MonkeyPatch().context() as m:
|
|
37
|
+
m.setenv("PACKAGE_VERSION", "")
|
|
38
|
+
data = plugin.get_version_data()
|
|
39
|
+
assert data == {"version": "0.0.0dev0"}
|
|
31
40
|
|
|
32
41
|
|
|
33
42
|
def test_custom_env_var_name():
|
|
34
43
|
"""Custom environment variable name is respected."""
|
|
35
|
-
plugin = EnvironmentVariableVersionSource(
|
|
44
|
+
plugin = EnvironmentVariableVersionSource("", {"variable": "MY_VERSION"})
|
|
36
45
|
with pytest.MonkeyPatch().context() as m:
|
|
37
|
-
m.setenv(
|
|
46
|
+
m.setenv("MY_VERSION", "3.5.0")
|
|
38
47
|
data = plugin.get_version_data()
|
|
39
|
-
assert data == {
|
|
48
|
+
assert data == {"version": "3.5.0"}
|
|
40
49
|
|
|
41
50
|
|
|
42
51
|
def test_custom_fallback_value():
|
|
43
52
|
"""Custom fallback value is used when configured."""
|
|
44
|
-
plugin = EnvironmentVariableVersionSource(
|
|
53
|
+
plugin = EnvironmentVariableVersionSource("", {"fallback": "1.0.0"})
|
|
45
54
|
with pytest.MonkeyPatch().context() as m:
|
|
46
|
-
m.delenv(
|
|
55
|
+
m.delenv("PACKAGE_VERSION", raising=False)
|
|
47
56
|
data = plugin.get_version_data()
|
|
48
|
-
assert data == {
|
|
57
|
+
assert data == {"version": "1.0.0"}
|
|
49
58
|
|
|
50
59
|
|
|
51
60
|
def test_env_var_takes_precedence_over_fallback():
|
|
52
61
|
"""Environment variable takes precedence over fallback when both are set."""
|
|
53
62
|
plugin = EnvironmentVariableVersionSource(
|
|
54
|
-
|
|
63
|
+
"", {"variable": "CUSTOM_VER", "fallback": "0.1.0"}
|
|
55
64
|
)
|
|
56
65
|
with pytest.MonkeyPatch().context() as m:
|
|
57
66
|
# Not set - uses fallback
|
|
58
|
-
m.delenv(
|
|
59
|
-
assert plugin.get_version_data() == {
|
|
67
|
+
m.delenv("CUSTOM_VER", raising=False)
|
|
68
|
+
assert plugin.get_version_data() == {"version": "0.1.0"}
|
|
60
69
|
|
|
61
70
|
# Set - uses env var
|
|
62
|
-
m.setenv(
|
|
63
|
-
assert plugin.get_version_data() == {
|
|
71
|
+
m.setenv("CUSTOM_VER", "5.0.0")
|
|
72
|
+
assert plugin.get_version_data() == {"version": "5.0.0"}
|
|
64
73
|
|
|
65
74
|
|
|
66
75
|
def test_empty_fallback_string_treated_as_none():
|
|
67
76
|
"""Empty fallback string is converted to None."""
|
|
68
|
-
plugin = EnvironmentVariableVersionSource(
|
|
77
|
+
plugin = EnvironmentVariableVersionSource("", {"fallback": ""})
|
|
69
78
|
with pytest.MonkeyPatch().context() as m:
|
|
70
|
-
m.delenv(
|
|
79
|
+
m.delenv("PACKAGE_VERSION", raising=False)
|
|
71
80
|
data = plugin.get_version_data()
|
|
72
|
-
assert data == {
|
|
81
|
+
assert data == {"version": None}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
from hatchling.version.source.plugin.interface import VersionSourceInterface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class EnvironmentVariableVersionSource(VersionSourceInterface):
|
|
7
|
-
PLUGIN_NAME = 'env-plus'
|
|
8
|
-
|
|
9
|
-
def get_version_data(self) -> dict:
|
|
10
|
-
variable = self.config.get('variable', 'PACKAGE_VERSION')
|
|
11
|
-
fallback = self.config.get('fallback', '0.0.0dev0') or None
|
|
12
|
-
version = os.environ.get(variable, fallback)
|
|
13
|
-
return {'version': version}
|
|
14
|
-
|
|
15
|
-
def set_version(self, version: str, version_data: dict) -> None:
|
|
16
|
-
version_data['version'] = version
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|