Skip to content

Commit

Permalink
Add ParsedRequirement class to parse requirement strings
Browse files Browse the repository at this point in the history
  • Loading branch information
elikoga committed May 7, 2024
1 parent ceafac4 commit 716a935
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/appenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ def ensure_best_python(base):
sys.exit(65)


class ParsedRequirement:

def __init__(self, name, url=None):
self.name = name
self.url = url

def __str__(self):
return self.name


def parse_requirement_string(requirement_string):
"""Parse a requirement from a requirement string.
Expand Down Expand Up @@ -268,11 +278,7 @@ def parse_requirement_string(requirement_string):
f"(?:{whitespace_regex})?;?", requirement_string)
url = url_match.group('url') if url_match else None

# now we want an object with .name, .url and str(obj) == requirement_string
return type('ParsedRequirement', (), {
'name': name,
'url': url,
'__str__': lambda self: requirement_string})()
return ParsedRequirement(name, url)


class AppEnv(object):
Expand Down

0 comments on commit 716a935

Please sign in to comment.