File tree Expand file tree Collapse file tree 2 files changed +37
-9
lines changed Expand file tree Collapse file tree 2 files changed +37
-9
lines changed Original file line number Diff line number Diff line change 1
- # overrides
1
+ # Overrides
2
+
3
+ ## pretend versions
4
+
5
+ setuptools_scm provides a mechanism to override the version number build time.
6
+
7
+ the environment variable ` SETUPTOOLS_SCM_PRETEND_VERSION ` is used
8
+ as the override source for the version number unparsed string.
9
+
10
+ to be specific about the package this applies for, one can use ` SETUPTOOLS_SCM_PRETEND_VERSION_FOR_${NORMALIZED_DIST_NAME} `
11
+ where the dist name normalization follows adapted PEP 503 semantics.
12
+
13
+ ## config overrides
14
+
15
+ setuptools_scm parses the environment variable ` SETUPTOOLS_SCM_OVERRIDES_FOR_${NORMALIZED_DIST_NAME} `
16
+ as a toml inline map to override the configuration data from ` pyproject.toml ` .
Original file line number Diff line number Diff line change 3
3
import os
4
4
import re
5
5
from typing import Any
6
+ from typing import cast
7
+ from typing import TypedDict
6
8
7
9
from . import _config
8
10
from . import _log
18
20
def read_named_env (
19
21
* , tool : str = "SETUPTOOLS_SCM" , name : str , dist_name : str | None
20
22
) -> str | None :
23
+ """ """
21
24
if dist_name is not None :
22
25
# Normalize the dist name as per PEP 503.
23
26
normalized_dist_name = re .sub (r"[-_.]+" , "-" , dist_name )
@@ -48,13 +51,23 @@ def _read_pretended_version_for(
48
51
return None
49
52
50
53
54
+ class _CheatTomlData (TypedDict ):
55
+ cheat : dict [str , Any ]
56
+
57
+
58
+ def load_toml_or_inline_map (data : str | None ) -> dict [str , Any ]:
59
+ """
60
+ load toml data - with a special hack if only a inline map is given
61
+ """
62
+ if not data :
63
+ return {}
64
+ elif data [0 ] == "{" :
65
+ data = "cheat=" + data
66
+ loaded : _CheatTomlData = cast (_CheatTomlData , lazy_toml_load (data ))
67
+ return loaded ["cheat" ]
68
+ return lazy_toml_load (data )
69
+
70
+
51
71
def read_toml_overrides (dist_name : str | None ) -> dict [str , Any ]:
52
72
data = read_named_env (name = "OVERRIDES" , dist_name = dist_name )
53
- if data :
54
- if data [0 ] == "{" :
55
- data = "cheat=" + data
56
- loaded = lazy_toml_load (data )
57
- return loaded ["cheat" ] # type: ignore[no-any-return]
58
- return lazy_toml_load (data )
59
- else :
60
- return {}
73
+ return load_toml_or_inline_map (data )
You can’t perform that action at this time.
0 commit comments