From a2a20135e7c7d5409bfe15293e87320e12fc5e5f Mon Sep 17 00:00:00 2001 From: u Date: Wed, 8 Jan 2025 22:42:23 +0300 Subject: [PATCH] update --- py2pack/__init__.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/py2pack/__init__.py b/py2pack/__init__.py index a35c838..be06cfd 100755 --- a/py2pack/__init__.py +++ b/py2pack/__init__.py @@ -35,7 +35,7 @@ from py2pack.utils import (_get_archive_filelist, get_pyproject_table, parse_pyproject, get_setuptools_scripts, get_metadata) - +import io from email import parser try: import libarchive @@ -53,8 +53,6 @@ except ModuleNotFoundError: pass -import io - def replace_string(output_string, replaces): for name, replacement in replaces.items(): @@ -455,6 +453,23 @@ def generate(args): outfile.close() +def fix_data(data): + extra_from_req = re.compile(r'''\bextra\s+==\s+["']([^"']+)["']''') + extras = [] + data_info = data["info"] + requires_dist = data_info["requires_dist"] or [] + provides_extra = data_info["provides_extra"] or [] + if requires_dist is not None: + for required_dist in requires_dist: + req = Requirement(required_dist) + if found := re.search(extra_from_req, str(req.marker)): + extras.add(found.group(1)) + provides_extra = list(sorted(set([*extras, *provides_extra]))) + data_info["requires_dist"] = requires_dist + data_info["provides_extra"] = provides_extra + data_info["classifiers"] = (data_info["classifiers"] or []) + + def fetch_local_data(args): localfile = args.localfile local = args.local @@ -470,18 +485,20 @@ def fetch_local_data(args): data = pypi_text_file(localfile) args.fetched_data = data args.version = args.fetched_data['info']['version'] - return - fetch_data(args) + fix_data(data) + else: + fetch_data(args) def fetch_data(args): - args.fetched_data = pypi_json(args.name, args.version) - urls = args.fetched_data.get('urls', []) + data = args.fetched_data = pypi_json(args.name, args.version) + urls = data.get('urls', []) if len(urls) == 0: print(f"unable to find a suitable release for {args.name}!") sys.exit(1) else: - args.version = args.fetched_data['info']['version'] # return current release number + args.version = data['info']['version'] # return current release number + fix_data(data) def newest_download_url(args):