@@ -29,6 +29,13 @@ class _Registry:
29
29
_register = _Registry ()
30
30
31
31
32
+ def build_requirements_name (layer , extension ):
33
+ if layer is None :
34
+ return "requirements." + extension
35
+
36
+ return layer + "-requirements." + extension
37
+
38
+
32
39
@_register
33
40
def clean (cfg ):
34
41
"""Remove extraneous files."""
@@ -52,20 +59,20 @@ def init(cfg):
52
59
subprocess .run (
53
60
["virtualenv" , "--python" , sys .executable , str (cfg .venv_path )], check = True
54
61
)
55
- if not pathlib .Path ("requirements. txt" ).exists ():
62
+ if not pathlib .Path (build_requirements_name ( None , " txt") ).exists ():
56
63
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 ():
58
65
subprocess .run (
59
66
[
60
67
cfg .venv_path / "bin/pip" ,
61
68
"install" ,
62
69
"--requirement" ,
63
- "dev-requirements. txt" ,
70
+ build_requirements_name ( "dev" , " txt") ,
64
71
],
65
72
check = True ,
66
73
)
67
74
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") ],
69
76
check = True ,
70
77
)
71
78
subprocess .run (
@@ -78,18 +85,18 @@ def lock(cfg):
78
85
"""Use pip-compile to generate package hashes from setup.py and write them into requirements.txt."""
79
86
subprocess .run ([cfg .venv_path / "bin/pip" , "install" , "pip-tools" ], check = True )
80
87
combined = []
81
- for prefix in [None , 'test' , 'dev' ]:
82
- combined .append (prefix )
88
+ for layer in [None , 'test' , 'dev' ]:
89
+ combined .append (layer )
83
90
84
91
subprocess .run (
85
92
[
86
93
cfg .venv_path / "bin/pip-compile" ,
87
94
"--generate-hashes" ,
88
95
"--output-file" ,
89
- f" { '' if prefix is None else prefix + '-' } requirements. txt" ,
96
+ build_requirements_name ( layer , ' txt' ) ,
90
97
* (
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
93
100
)
94
101
],
95
102
check = True ,
@@ -116,7 +123,7 @@ def upload(cfg):
116
123
def bundle (cfg ):
117
124
"""Bundle the package into a standalone unix executable."""
118
125
lock (cfg )
119
- with open ("requirements. txt" ) as f :
126
+ with open (build_requirements_name ( None , " txt") ) as f :
120
127
requirements = [line .split ()[0 ] for line in f if line [0 ].isalpha ()]
121
128
122
129
subprocess .run (
0 commit comments