Skip to content

Commit

Permalink
Obtain package architecture via hackily hack.
Browse files Browse the repository at this point in the history
  • Loading branch information
amdei committed Apr 8, 2023
1 parent d3a2368 commit 16b5a4f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
3 changes: 3 additions & 0 deletions lib/fpm/package/pyfpm/get_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ def run(self):

if self.load_requirements_txt:
requirement = open(self.requirements_txt).readlines()
# print('REQ-SETUP-PY-REQ-TXT:', requirement, file=sys.stderr)
for dep in pkg_resources.parse_requirements(requirement):
final_deps.extend(self.process_dep(dep))
else:
if getattr(self.distribution, 'install_requires', None):
# print('REQ-SETUP-PY-INSTALL:', self.distribution.install_requires, file=sys.stderr)
for dep in pkg_resources.parse_requirements(
self.distribution.install_requires):
final_deps.extend(self.process_dep(dep))
if getattr(self.distribution, 'extras_require', None):
# print('REQ-SETUP-PY-EXTRA:', self.distribution.extras_require, file=sys.stderr)
for dep in pkg_resources.parse_requirements(
v for k, v in self.distribution.extras_require.items()
if k.startswith(':') and pkg_resources.evaluate_marker(k[1:])):
Expand Down
44 changes: 28 additions & 16 deletions lib/fpm/package/pyfpm_wheel/get_metadata_wheel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import sys
import pkg_resources
import zipfile
from pkginfo import Wheel
import traceback

Expand All @@ -12,7 +13,10 @@ class get_metadata_wheel:
wheel_path = None

def __init__(self, wheel_path):
self.wheel_path = wheel_path
fqn = os.path.abspath(os.path.normpath(wheel_path))
if not fqn.endswith('.whl'):
raise ValueError('Wheel file must hav .whl extension!')
self.wheel_path = fqn

def process_dep(self, dep):
deps = []
Expand All @@ -32,7 +36,24 @@ def process_dep(self, dep):

def get_home_url(self, project_urls):
res = dict([i.strip() for i in x.split(',')] for x in project_urls)
return res.get('Home', None)
if 'Home' in res:
return res.get('Home', None)
return res.get('Homepage', None)


def __wheel_root_is_pure(self):
with zipfile.ZipFile(self.wheel_path, mode="r") as archive:
names = archive.namelist()
for name in names:
if name.endswith('.dist-info/WHEEL'):
for line in archive.read(name).split(b"\n"):
line_lower = str(line).lower().strip()
if line_lower.startswith('root-is-purelib') and \
line_lower.endswith('true'):
return True

return False


def run(self, output_path):

Expand All @@ -54,36 +75,27 @@ def run(self, output_path):
else:
data["url"] = self.get_home_url(fpm_wheel.project_urls)

# @todo FIXME!!!
if fpm_wheel.requires_external:
# @todo Can anyone provide a package, where fpm_wheel.requires_external is 'true'?
if fpm_wheel.requires_external or not self.__wheel_root_is_pure():
data["architecture"] = "native"
else:
data["architecture"] = "all"

print('REQ-TOML:', fpm_wheel.requires, file=sys.stderr)
print('REQ-TOML DIST:', fpm_wheel.requires_dist, file=sys.stderr)

# print('REQ-TOML:', fpm_wheel.requires, file=sys.stderr)
# print('REQ-TOML DIST:', fpm_wheel.requires_dist, file=sys.stderr)

final_deps = []

# @todo FIXME!!!

try:
if fpm_wheel.requires_dist:
for dep in pkg_resources.parse_requirements(fpm_wheel.requires_dist):
final_deps.extend(self.process_dep(dep))

# if fpm_wheel.requires_dist:
# for dep in pkg_resources.parse_requirements(
# v for k, v in fpm_wheel.requires_dist
# if k.startswith(':') and pkg_resources.evaluate_marker(k[1:])):
# final_deps.extend(self.process_dep(dep))
except Exception as e:
print('REQ-TOML-DEPS-EXCEPTION:', str(e), '\n', repr(traceback.format_exc()), file=sys.stderr)
raise


print('REQ-TOML-FINAL-DEPS:', final_deps, file=sys.stderr)
# print('REQ-TOML-FINAL-DEPS:', final_deps, file=sys.stderr)
data["dependencies"] = final_deps

with open(output_path, "w") as output:
Expand Down
2 changes: 1 addition & 1 deletion lib/fpm/package/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def build_py_wheel(setup_data)
prefix = "/"
prefix = attributes[:prefix] unless attributes[:prefix].nil?

wheel_dir = "./fpm-wheel"
wheel_dir = ".fpm-wheel"
# Some assume $PWD == current directory of package, so let's
# chdir first.
::Dir.chdir(project_dir) do
Expand Down

0 comments on commit 16b5a4f

Please sign in to comment.