You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6 KiB

#!/usr/bin/env python3
import sys
try:
import requests
except ImportError as e:
sys.exit(f"Error: {str(e)}. Try 'sudo python3 -m pip install <module-name>'")
def check_restriction(p, r):
# See: https://www.python.org/dev/peps/pep-0496/
# Hopefully we don't need to parse the whole microlanguage
if "extra" in r and "[" not in p:
return False
for marker in ["os_name", "platform_release", "sys_platform", "platform_system"]:
if marker in r:
return True
for p in sys.stdin.read().split():
p = p.strip()
if not p:
continue
assert "==" in p, "This script expects a list of packages with pinned version, e.g. package==1.2.3, not {}".format(p)
p, v = p.rsplit("==", 1)
try:
data = requests.get("https://pypi.org/pypi/{}/{}/json".format(p, v)).json()["info"]
except ValueError:
raise Exception("Package could not be found: {}=={}".format(p, v))
try:
contrib: fix find_restricted_dependencies for deps with version range New release of pyinstaller (4.3) broke the script (which is used by freeze_packages.sh). ----- Compare: $ wget https://pypi.org/pypi/pyinstaller/4.3/json $ cat json | jq &#34;.info.requires_dist&#34; [ &#34;setuptools&#34;, &#34;altgraph&#34;, &#34;pyinstaller-hooks-contrib (&gt;=2020.6)&#34;, &#34;importlib-metadata ; python_version &lt; \&#34;3.8\&#34;&#34;, &#34;macholib (&gt;=1.8) ; sys_platform == \&#34;darwin\&#34;&#34;, &#34;pefile (&gt;=2017.8.1) ; sys_platform == \&#34;win32\&#34;&#34;, &#34;pywin32-ctypes (&gt;=0.2.0) ; sys_platform == \&#34;win32\&#34;&#34;, &#34;tinyaes (&gt;=1.0.0) ; extra == &#39;encryption&#39;&#34;, &#34;pytest (&gt;=2.7.3) ; extra == &#39;hook_testing&#39;&#34;, &#34;execnet (&gt;=1.5.0) ; extra == &#39;hook_testing&#39;&#34;, &#34;psutil ; extra == &#39;hook_testing&#39;&#34; ] $ wget https://pypi.org/pypi/pyinstaller/4.2/json | jq . $ cat json | jq &#34;.info.requires_dist&#34; null $ wget https://pypi.org/pypi/qrcode/6.1/json $ cat json | jq &#34;.info.requires_dist&#34; [ &#34;six&#34;, &#34;colorama ; platform_system == \&#34;Windows\&#34;&#34;, &#34;tox ; extra == &#39;dev&#39;&#34;, &#34;pytest ; extra == &#39;dev&#39;&#34;, &#34;mock ; (python_version &lt; \&#34;3\&#34;) and extra == &#39;dev&#39;&#34;, &#34;zest.releaser[recommended] ; extra == &#39;maintainer&#39;&#34;, &#34;pillow ; extra == &#39;pil&#39;&#34;, &#34;pytest ; extra == &#39;test&#39;&#34;, &#34;pytest-cov ; extra == &#39;test&#39;&#34;, &#34;mock ; (python_version &lt; \&#34;3\&#34;) and extra == &#39;test&#39;&#34; ]
4 years ago
for r in data["requires_dist"]: # type: str
if ";" not in r:
continue
contrib: fix find_restricted_dependencies for deps with version range New release of pyinstaller (4.3) broke the script (which is used by freeze_packages.sh). ----- Compare: $ wget https://pypi.org/pypi/pyinstaller/4.3/json $ cat json | jq &#34;.info.requires_dist&#34; [ &#34;setuptools&#34;, &#34;altgraph&#34;, &#34;pyinstaller-hooks-contrib (&gt;=2020.6)&#34;, &#34;importlib-metadata ; python_version &lt; \&#34;3.8\&#34;&#34;, &#34;macholib (&gt;=1.8) ; sys_platform == \&#34;darwin\&#34;&#34;, &#34;pefile (&gt;=2017.8.1) ; sys_platform == \&#34;win32\&#34;&#34;, &#34;pywin32-ctypes (&gt;=0.2.0) ; sys_platform == \&#34;win32\&#34;&#34;, &#34;tinyaes (&gt;=1.0.0) ; extra == &#39;encryption&#39;&#34;, &#34;pytest (&gt;=2.7.3) ; extra == &#39;hook_testing&#39;&#34;, &#34;execnet (&gt;=1.5.0) ; extra == &#39;hook_testing&#39;&#34;, &#34;psutil ; extra == &#39;hook_testing&#39;&#34; ] $ wget https://pypi.org/pypi/pyinstaller/4.2/json | jq . $ cat json | jq &#34;.info.requires_dist&#34; null $ wget https://pypi.org/pypi/qrcode/6.1/json $ cat json | jq &#34;.info.requires_dist&#34; [ &#34;six&#34;, &#34;colorama ; platform_system == \&#34;Windows\&#34;&#34;, &#34;tox ; extra == &#39;dev&#39;&#34;, &#34;pytest ; extra == &#39;dev&#39;&#34;, &#34;mock ; (python_version &lt; \&#34;3\&#34;) and extra == &#39;dev&#39;&#34;, &#34;zest.releaser[recommended] ; extra == &#39;maintainer&#39;&#34;, &#34;pillow ; extra == &#39;pil&#39;&#34;, &#34;pytest ; extra == &#39;test&#39;&#34;, &#34;pytest-cov ; extra == &#39;test&#39;&#34;, &#34;mock ; (python_version &lt; \&#34;3\&#34;) and extra == &#39;test&#39;&#34; ]
4 years ago
# example value for "r" at this point: "pefile (>=2017.8.1) ; sys_platform == \"win32\""
dep, restricted = r.split(";", 1)
dep = dep.strip()
restricted = restricted.strip()
dep_basename = dep.split(" ")[0]
if check_restriction(dep, restricted):
print(dep_basename, sep=" ")
print("Installing {} from {} although it is only needed for {}".format(dep, p, restricted), file=sys.stderr)
except TypeError:
# Has no dependencies at all
continue