forked from pydata/xarray
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure-testpypi-version.py
More file actions
50 lines (36 loc) · 1.14 KB
/
configure-testpypi-version.py
File metadata and controls
50 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import copy
import pathlib
import tomli
import tomli_w
def split_path(path, sep="/"):
if isinstance(path, str):
return [part for part in path.split(sep) if part]
else:
return path
def extract(mapping, path, sep="/"):
parts = split_path(path, sep=sep)
cur = mapping
for part in parts:
cur = cur[part]
return cur
def update(mapping, path, value, sep="/"):
new = copy.deepcopy(mapping)
parts = split_path(path, sep=sep)
parent = extract(new, parts[:-1])
parent[parts[-1]] = value
return new
parser = argparse.ArgumentParser()
parser.add_argument("path", type=pathlib.Path)
args = parser.parse_args()
content = args.path.read_text()
decoded = tomli.loads(content)
with_local_scheme = update(
decoded, "tool.setuptools_scm.local_scheme", "no-local-version", sep="."
)
# work around a bug in setuptools / setuptools-scm
with_setuptools_pin = copy.deepcopy(with_local_scheme)
requires = extract(with_setuptools_pin, "build-system.requires", sep=".")
requires[0] = "setuptools>=42,<60"
new_content = tomli_w.dumps(with_setuptools_pin)
args.path.write_text(new_content)