1
1
import re
2
- from packaging .requirements import Requirement , InvalidRequirement
2
+ from metaflow . _vendor . packaging .requirements import Requirement , InvalidRequirement
3
3
4
4
# this file can be overridden by extensions as is (e.g. metaflow-nflx-extensions)
5
5
@@ -124,7 +124,7 @@ def pyproject_toml_parser(content: str):
124
124
# If present, store verbatim; note that PEP 621 does not necessarily
125
125
# require "python" to be a dependency in the usual sense.
126
126
# Example: "requires-python" = ">=3.7,<4"
127
- parsed ["python" ] = requires_python .strip ()
127
+ parsed ["python" ] = requires_python .lstrip ( "=" ). strip ()
128
128
129
129
for dep_line in requirements :
130
130
dep_line_stripped = dep_line .strip ()
@@ -144,7 +144,7 @@ def pyproject_toml_parser(content: str):
144
144
if req .url :
145
145
dep_key += f"@{ req .url } "
146
146
147
- dep_spec = str (req .specifier ).lstrip (" =" )
147
+ dep_spec = str (req .specifier ).lstrip ("=" )
148
148
149
149
if req .name .lower () == "python" :
150
150
if parsed ["python" ] is not None and dep_spec :
@@ -196,24 +196,30 @@ def conda_environment_yml_parser(content: str):
196
196
# Group 2: optional operator + version (could be "=1.21.2", "==1.21.2", etc.)
197
197
line_regex = re .compile (r"^([A-Za-z0-9_\-\.]+)([=<>!~].+)?$" )
198
198
199
- for line in content .splitlines ():
200
- line = line .strip ()
199
+ for raw_line in content .splitlines ():
200
+ line = raw_line .strip ()
201
+
202
+ # Ignore empty lines or comment lines
201
203
if not line or line .startswith ("#" ):
202
204
continue
203
205
206
+ # Mark the start of dependencies
204
207
if line .lower ().startswith ("dependencies:" ):
205
208
inside_dependencies = True
206
209
continue
207
210
208
- if not inside_dependencies :
209
- # skip 'name:', 'channels:', or anything before 'dependencies:'.
211
+ # If we're already parsing dependencies but see a line that doesn't
212
+ # start with '-', that means we're done with the dependencies section.
213
+ if inside_dependencies and not line .startswith ("-" ):
214
+ # Stop processing dependencies entirely.
215
+ inside_dependencies = False
210
216
continue
211
217
212
- if not line .startswith ("-" ):
213
- raise ValueError (
214
- f"Unsupported or malformed line in 'dependencies:' section: '{ line } '"
215
- )
218
+ # If we're not inside 'dependencies:' yet or are done with it, just ignore
219
+ if not inside_dependencies :
220
+ continue
216
221
222
+ # Now parse each dependency line
217
223
dep_line = line .lstrip ("-" ).strip ()
218
224
if dep_line .endswith (":" ):
219
225
raise ValueError (f"Unsupported subsection '{ dep_line } ' in environment.yml." )
0 commit comments