Skip to content

Commit 6ce9323

Browse files
committed
fix
1 parent 9f3a424 commit 6ce9323

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

metaflow/plugins/pypi/parsers.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from packaging.requirements import Requirement, InvalidRequirement
2+
from metaflow._vendor.packaging.requirements import Requirement, InvalidRequirement
33

44
# this file can be overridden by extensions as is (e.g. metaflow-nflx-extensions)
55

@@ -124,7 +124,7 @@ def pyproject_toml_parser(content: str):
124124
# If present, store verbatim; note that PEP 621 does not necessarily
125125
# require "python" to be a dependency in the usual sense.
126126
# Example: "requires-python" = ">=3.7,<4"
127-
parsed["python"] = requires_python.strip()
127+
parsed["python"] = requires_python.lstrip("=").strip()
128128

129129
for dep_line in requirements:
130130
dep_line_stripped = dep_line.strip()
@@ -144,7 +144,7 @@ def pyproject_toml_parser(content: str):
144144
if req.url:
145145
dep_key += f"@{req.url}"
146146

147-
dep_spec = str(req.specifier).lstrip(" =")
147+
dep_spec = str(req.specifier).lstrip("=")
148148

149149
if req.name.lower() == "python":
150150
if parsed["python"] is not None and dep_spec:
@@ -196,24 +196,30 @@ def conda_environment_yml_parser(content: str):
196196
# Group 2: optional operator + version (could be "=1.21.2", "==1.21.2", etc.)
197197
line_regex = re.compile(r"^([A-Za-z0-9_\-\.]+)([=<>!~].+)?$")
198198

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
201203
if not line or line.startswith("#"):
202204
continue
203205

206+
# Mark the start of dependencies
204207
if line.lower().startswith("dependencies:"):
205208
inside_dependencies = True
206209
continue
207210

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
210216
continue
211217

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
216221

222+
# Now parse each dependency line
217223
dep_line = line.lstrip("-").strip()
218224
if dep_line.endswith(":"):
219225
raise ValueError(f"Unsupported subsection '{dep_line}' in environment.yml.")

0 commit comments

Comments
 (0)