@@ -60,9 +60,9 @@ def _augment_requirement(ln: str, comment_char: str = "#", unfreeze: str = "all"
60
60
Returns:
61
61
adjusted requirement
62
62
63
- >>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # anything", unfreeze="")
63
+ >>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # anything", unfreeze="none ")
64
64
'arrow<=1.2.2,>=1.2.0'
65
- >>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # strict", unfreeze="")
65
+ >>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # strict", unfreeze="none ")
66
66
'arrow<=1.2.2,>=1.2.0 # strict'
67
67
>>> _augment_requirement("arrow<=1.2.2,>=1.2.0 # my name", unfreeze="all")
68
68
'arrow>=1.2.0'
@@ -79,6 +79,7 @@ def _augment_requirement(ln: str, comment_char: str = "#", unfreeze: str = "all"
79
79
>>> _augment_requirement("arrow", unfreeze="major")
80
80
'arrow'
81
81
"""
82
+ assert unfreeze in {"none" , "major" , "all" }
82
83
# filer all comments
83
84
if comment_char in ln :
84
85
comment = ln [ln .index (comment_char ) :]
@@ -88,7 +89,7 @@ def _augment_requirement(ln: str, comment_char: str = "#", unfreeze: str = "all"
88
89
is_strict = False
89
90
req = ln .strip ()
90
91
# skip directly installed dependencies
91
- if not req or req . startswith ( "http" ) or "@" in req :
92
+ if not req or any ( c in req for c in [ "http:" , "https:" , "@" ]) :
92
93
return ""
93
94
# extract the major version from all listed versions
94
95
if unfreeze == "major" :
@@ -99,7 +100,7 @@ def _augment_requirement(ln: str, comment_char: str = "#", unfreeze: str = "all"
99
100
ver_major = None
100
101
101
102
# remove version restrictions unless they are strict
102
- if unfreeze and "<" in req and not is_strict :
103
+ if unfreeze != "none" and "<" in req and not is_strict :
103
104
req = re .sub (r",? *<=? *[\d\.\*]+,? *" , "" , req ).strip ()
104
105
if ver_major is not None and not is_strict :
105
106
# add , only if there are already some versions
@@ -121,6 +122,7 @@ def load_requirements(
121
122
>>> load_requirements(path_req, "docs.txt", unfreeze="major") # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
122
123
['sphinx>=4.0, <6.0 # strict', ...]
123
124
"""
125
+ assert unfreeze in {"none" , "major" , "all" }
124
126
with open (os .path .join (path_dir , file_name )) as file :
125
127
lines = [ln .strip () for ln in file .readlines ()]
126
128
reqs = [_augment_requirement (ln , comment_char = comment_char , unfreeze = unfreeze ) for ln in lines ]
@@ -206,19 +208,23 @@ def _download_frontend(pkg_path: str):
206
208
207
209
208
210
def _load_aggregate_requirements (req_dir : str = "requirements" , freeze_requirements : bool = False ) -> None :
209
- """Load all base requirements from all particular packages and prune duplicates."""
211
+ """Load all base requirements from all particular packages and prune duplicates.
212
+
213
+ >>> _load_aggregate_requirements(os.path.join(_PROJECT_ROOT, "requirements"))
214
+ """
210
215
requires = [
211
- load_requirements (d , file_name = "base.txt" , unfreeze = not freeze_requirements )
216
+ # TODO: consider passing unfreeze as string instead
217
+ load_requirements (d , file_name = "base.txt" , unfreeze = "none" if freeze_requirements else "major" )
212
218
for d in glob .glob (os .path .join (req_dir , "*" ))
213
219
# skip empty folder as git artefacts, and resolving Will's special issue
214
220
if os .path .isdir (d ) and len (glob .glob (os .path .join (d , "*" ))) > 0 and "__pycache__" not in d
215
221
]
216
222
if not requires :
217
223
return None
218
224
# TODO: add some smarter version aggregation per each package
219
- requires = list ( chain (* requires ))
225
+ requires = sorted ( set ( chain (* requires ) ))
220
226
with open (os .path .join (req_dir , "base.txt" ), "w" ) as fp :
221
- fp .writelines ([ln + os .linesep for ln in requires ])
227
+ fp .writelines ([ln + os .linesep for ln in requires ] + [ os . linesep ] )
222
228
223
229
224
230
def _retrieve_files (directory : str , * ext : str ) -> List [str ]:
@@ -333,7 +339,7 @@ def _prune_packages(req_file: str, packages: Sequence[str]) -> None:
333
339
if req .name not in packages :
334
340
final .append (line )
335
341
print (final )
336
- path .write_text ("\n " .join (final ))
342
+ path .write_text ("\n " .join (final ) + " \n " )
337
343
338
344
@staticmethod
339
345
def _replace_min (fname : str ) -> None :
0 commit comments