Skip to content

Commit

Permalink
Merge pull request #464 from mkb79/patch-wheels
Browse files Browse the repository at this point in the history
patch wheels to take care of additional requirements
  • Loading branch information
bennr01 authored Jan 20, 2023
2 parents b722d71 + d50811a commit 7d378c3
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 27 deletions.
8 changes: 8 additions & 0 deletions lib/libversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,14 @@ def parse_requirement(requirement):
extras = []
else:
extras = extra_s.split(",")
elif "[" in name:
si = name.find("[")
extra_s = name[si + 1:-1]
name = name[:si]
if len(extra_s) == 0:
extras = []
else:
extras = extra_s.split(",")
else:
extras = []
splitted = specs_s.split(",")
Expand Down
71 changes: 44 additions & 27 deletions lib/stashutils/wheels.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,34 +336,51 @@ def read_dependencies_from_METADATA(self, p):
if ";" in t:
es = t[t.find(";") + 1:].replace('"', "").replace("'", "")
t = t[:t.find(";")].strip()
if VersionSpecifier is None:
# libversion not found
print(
"Warning: could not import libversion.VersionSpecifier! Ignoring version and extra dependencies."
)
rq, v, extras = "<libversion not found>", "???", []
else:
rq, v, extras = VersionSpecifier.parse_requirement(es)
if rq == "python_version":
# handle python version dependencies
if not v.match(platform.python_version()):
# dependency NOT required
continue
elif rq == "extra":
# handle extra dependencies
matched = any([v.match(e) for e in self.wheel.extras])
if not matched:
# dependency NOT required
continue
for sub_es in es.split(' and '):
if VersionSpecifier is None:
# libversion not found
print(
"Warning: could not import libversion.VersionSpecifier! Ignoring version and extra dependencies."
)
rq, v, extras = "<libversion not found>", "???", []
else:
rq, v, extras = VersionSpecifier.parse_requirement(sub_es)

if rq == "python_version":
# handle python version dependencies
if not v.match(platform.python_version()):
# dependency NOT required
break
elif rq == "extra":
# handle extra dependencies
matched = any([v.match(e) for e in self.wheel.extras])
if not matched:
# dependency NOT required
break
else:
if self.verbose:
print("Adding dependencies for extras...")
elif rq == "platform_python_implementation":
if not v.match(platform.python_implementation()):
break
elif rq == "platform_system":
if v.match(platform.system()):
break
elif rq == "sys_platform":
if not v.match(sys.platform):
break
else:
if self.verbose:
print("Adding dependencies for extras...")
# unknown requirement for dependency
# warn user and register the dependency
print("Warning: unknown dependency requirement: '{}'".format(rq))
print("Warning: Adding dependency '{}', ignoring requirements for dependency.".format(t))
# do not do anything here- As long as we dont use 'continue', 'break', ... the dependency will be added.
else:
# unknown requirement for dependency
# warn user and register the dependency
print("Warning: unknown dependency requirement: '{}'".format(rq))
print("Warning: Adding dependency '{}', ignoring requirements for dependency.".format(t))
# do not do anything here- As long as we dont use 'continue', 'break', ... the dependency will be added.
# no 'break' happens
continue
# a 'break' happens, don't add dependencies and go to next 'line'
break

dependencies.append(t)
return dependencies

Expand Down Expand Up @@ -449,4 +466,4 @@ def extract_into_temppath(self):
print("dependencies:")
print(dep)
if len(dep) > 0:
print("WARNING: Dependencies were not installed.")
print("WARNING: Dependencies were not installed.")

0 comments on commit 7d378c3

Please sign in to comment.