Skip to content

Commit 43040b1

Browse files
committed
add build_requirements_name() to pycli
1 parent de413b8 commit 43040b1

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

pycli

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ class _Registry:
2929
_register = _Registry()
3030

3131

32+
def build_requirements_name(layer, extension):
33+
if layer is None:
34+
return "requirements." + extension
35+
36+
return layer + "-requirements." + extension
37+
38+
3239
@_register
3340
def clean(cfg):
3441
"""Remove extraneous files."""
@@ -52,20 +59,20 @@ def init(cfg):
5259
subprocess.run(
5360
["virtualenv", "--python", sys.executable, str(cfg.venv_path)], check=True
5461
)
55-
if not pathlib.Path("requirements.txt").exists():
62+
if not pathlib.Path(build_requirements_name(None, "txt")).exists():
5663
raise FileNotFoundError("Run `lock` first, to create requirements.txt.")
57-
if pathlib.Path("dev-requirements.txt").exists():
64+
if pathlib.Path(build_requirements_name("dev", "txt")).exists():
5865
subprocess.run(
5966
[
6067
cfg.venv_path / "bin/pip",
6168
"install",
6269
"--requirement",
63-
"dev-requirements.txt",
70+
build_requirements_name("dev", "txt"),
6471
],
6572
check=True,
6673
)
6774
subprocess.run(
68-
[cfg.venv_path / "bin/pip", "install", "--requirement", "requirements.txt"],
75+
[cfg.venv_path / "bin/pip", "install", "--requirement", build_requirements_name(None, "txt")],
6976
check=True,
7077
)
7178
subprocess.run(
@@ -78,18 +85,18 @@ def lock(cfg):
7885
"""Use pip-compile to generate package hashes from setup.py and write them into requirements.txt."""
7986
subprocess.run([cfg.venv_path / "bin/pip", "install", "pip-tools"], check=True)
8087
combined = []
81-
for prefix in [None, 'test', 'dev']:
82-
combined.append(prefix)
88+
for layer in [None, 'test', 'dev']:
89+
combined.append(layer)
8390

8491
subprocess.run(
8592
[
8693
cfg.venv_path / "bin/pip-compile",
8794
"--generate-hashes",
8895
"--output-file",
89-
f"{'' if prefix is None else prefix + '-'}requirements.txt",
96+
build_requirements_name(layer, 'txt'),
9097
*(
91-
f"{'' if each is None else each + '-'}requirements.in"
92-
for each in combined
98+
build_requirements_name(prefix, 'in')
99+
for prefix in combined
93100
)
94101
],
95102
check=True,
@@ -116,7 +123,7 @@ def upload(cfg):
116123
def bundle(cfg):
117124
"""Bundle the package into a standalone unix executable."""
118125
lock(cfg)
119-
with open("requirements.txt") as f:
126+
with open(build_requirements_name(None, "txt")) as f:
120127
requirements = [line.split()[0] for line in f if line[0].isalpha()]
121128

122129
subprocess.run(

0 commit comments

Comments
 (0)