MCPcopy Create free account
hub / github.com/StackStorm/st2 / fetch_requirements

Function fetch_requirements

scripts/dist_utils.py:60–111  ·  view source on GitHub ↗

Return a list of requirements and links by parsing the provided requirements file.

(requirements_file_path)

Source from the content-addressed store, hash-verified

58
59
60def fetch_requirements(requirements_file_path):
61 """
62 Return a list of requirements and links by parsing the provided requirements file.
63 """
64 links = []
65 reqs = []
66
67 def _get_link(line):
68 vcs_prefixes = ["git+", "svn+", "hg+", "bzr+"]
69
70 for vcs_prefix in vcs_prefixes:
71 if line.startswith(vcs_prefix) or line.startswith("-e %s" % (vcs_prefix)):
72 req_name = re.findall(".*#egg=(.+)([&|@]).*$", line)
73
74 if not req_name:
75 req_name = re.findall(".*#egg=(.+?)$", line)
76 else:
77 req_name = req_name[0]
78
79 if not req_name:
80 raise ValueError(
81 'Line "%s" is missing "#egg=<package name>"' % (line)
82 )
83
84 link = line.replace("-e ", "").strip()
85 return link, req_name[0]
86 elif vcs_prefix in line and line.count("@") == 2:
87 # PEP 440 direct reference: <package name>@ <url>@version
88 req_name, link = line.split("@", 1)
89 req_name = req_name.strip()
90 link = f"{link.strip()}#egg={req_name}"
91 return link, req_name
92
93 return None, None
94
95 with open(requirements_file_path, "r") as fp:
96 for line in fp.readlines():
97 line = line.strip()
98
99 if line.startswith("#") or not line:
100 continue
101
102 link, req_name = _get_link(line=line)
103
104 if link:
105 links.append(link)
106 else:
107 req_name = line
108
109 reqs.append(req_name)
110
111 return (reqs, links)
112
113
114def apply_vagrant_workaround():

Callers

nothing calls this directly

Calls 1

_get_linkFunction · 0.70

Tested by

no test coverage detected