def from_wheel_directory_path( wheel_class: "Type[Wheel]", wheel_directory_path: str, default_environment: Dict[str, Any], ) -> "Wheel": metadata_file = os.path.join(wheel_directory_path, "METADATA") if os.path.exists(metadata_file): with open(metadata_file, "r", encoding="ascii", errors="surrogateescape") as headers: metadata = email.parser.Parser().parse(headers) license_string = str_from_message(metadata, "license") if license_string is None: license_string = "" classifiers = list_from_message(metadata, "classifiers") if classifiers is None: classifiers = [] license = find_license(classifiers=classifiers, license_string=license_string) if license is None: license = '"' + safe(license_string) + '"' click.echo( "WARNING: Couldn't recognize license `{}` for `{}`".format( license_string, metadata.get("name"))) name = str_from_message(metadata, "name") if name is None: raise Exception("Could not extract name from wheel metadata") version = str_from_message(metadata, "version") if version is None: raise Exception( "Could not extract version from wheel metadata") dependencies = list_from_message(metadata, "requires-dist") if dependencies is None: dependencies = [] description = str_from_message(metadata, "summary") if description is None: description = "" return wheel_class( name=name, version=version, deps=extract_deps(dependencies, default_environment), homepage=safe(find_homepage(metadata)), license=license, description=safe(description), ) raise click.ClickException("Unable to find METADATA in `%s` folder." % wheel_directory_path)
def first_license_classifier_from_list( classifiers: List[str]) -> Optional[str]: for classifier in classifiers: if classifier in all_classifiers: escaped_classifier: str = safe(classifier) return '"' + escaped_classifier + '"' return None
def find_license(item): license = None classifiers = item.get('classifiers', []) # find first license classifier all_classifiers_keys = all_classifiers.keys() license_classifiers = [ i for i in filter(lambda x: x in all_classifiers_keys, classifiers) ] for license_classifier in license_classifiers: license_nix = all_classifiers[license_classifier] if license_nix is not None: license = license_nix break if license is None: license = item.get('license', '') if license in ['LGPL with exceptions or ZPL', 'ZPL 2.1']: license = "licenses.zpl21" elif license in [ 'MIT', 'MIT License', 'MIT or Apache License, Version 2.0', 'The MIT License' ]: license = "licenses.mit" elif license in ['BSD', 'BSD License', 'BSD-like', 'BSD or Apache License, Version 2.0'] or \ license.startswith('BSD -'): license = "licenses.bsdOriginal" elif license in [ 'Apache 2.0', 'Apache License 2.0', 'Apache 2', 'Apache License, Version 2.0', 'Apache License Version 2.0' ]: license = "licenses.asl20" elif license in [ 'GNU Lesser General Public License (LGPL), Version 3', 'LGPL' ]: license = "licenses.lgpl3" elif license in [ 'MPL2', 'MPL 2.0', 'MPL 2.0 (Mozilla Public License)', 'MPL-2.0' ]: license = "licenses.mpl20" elif license in ['Python Software Foundation License']: license = "licenses.psfl" else: if len(license_classifiers) > 0: license = license_classifiers[0] else: click.echo( "WARNING: Couldn't recognize license `{}` for `{}`".format( license, item.get('name'))) license = '"{}"'.format(safe(license)) return license
def process_metadata(wheel): """Find the actual metadata json file from several possible names. """ for _file in ("metadata.json", "pydist.json"): wheel_file = os.path.join(wheel, _file) if os.path.exists(wheel_file): with open(wheel_file) as f: metadata = json.load(f) if metadata["name"].lower() in TO_IGNORE: return else: return { "name": metadata["name"], "version": metadata["version"], "deps": extract_deps(metadata), "homepage": safe(find_homepage(metadata)), "license": find_license(metadata), "description": safe(metadata.get("summary", "")), } raise click.ClickException("Unable to find metadata.json/pydist.json in `%s` folder." % wheel)
def process_metadata(wheel): """Find the actual metadata json file from several possible names. """ for _file in ('metadata.json', 'pydist.json'): wheel_file = os.path.join(wheel, _file) if os.path.exists(wheel_file): with open(wheel_file) as f: metadata = json.load(f) if metadata['name'].lower() in TO_IGNORE: return else: return { 'name': metadata['name'], 'version': metadata['version'], 'deps': extract_deps(metadata), 'homepage': safe(find_homepage(metadata)), 'license': find_license(metadata), 'description': safe(metadata.get('summary', '')), } raise click.ClickException( "Unable to find metadata.json/pydist.json in `%s` folder." % wheel)
def metadata(wheel): """Find the actual metadata json file from several possible names. """ for _file in ('metadata.json', 'pydist.json'): wheel_file = os.path.join(wheel, _file) if os.path.exists(wheel_file): with open(wheel_file) as f: metadata = json.load(f) if metadata['name'].lower() in TO_IGNORE: return else: return { 'name': metadata['name'], 'version': metadata['version'], 'deps': extract_deps(metadata), 'homepage': safe(find_homepage(metadata)), 'license': safe(metadata.get('license', '')), 'description': safe(metadata.get('summary', '')), } raise click.ClickException( "Unable to find metadata.json/pydist.json in `%s` folder." % wheel)
def process_metadata(wheel_dir, default_environment): """process METADATA file """ build_deps = [] setup_requires_file = os.path.join(wheel_dir, "setup_requires.txt") if os.path.exists(setup_requires_file): with open(setup_requires_file) as f: deps = f.read().split("\n") deps = filter(lambda l: l != "", deps) # remove empty lines build_deps = extract_deps(deps, default_environment) metadata_file = os.path.join(wheel_dir, "METADATA") if os.path.exists(metadata_file): with open(metadata_file, "r", encoding="ascii", errors="surrogateescape") as headers: metadata = email.parser.Parser().parse(headers) return { "name": metadata["name"], "version": metadata["version"], "deps": extract_deps(metadata.get_all("requires-dist", []), default_environment), "build_deps": build_deps, "homepage": safe(find_homepage(metadata)), "license": find_license(metadata), "description": safe(metadata.get("summary", "")), } raise click.ClickException("Unable to find METADATA in `%s` folder." % wheel_dir)
def find_license(item): license = None classifiers = item.get("classifiers", []) # find first license classifier all_classifiers_keys = all_classifiers.keys() license_classifiers = [i for i in filter(lambda x: x in all_classifiers_keys, classifiers)] for license_classifier in license_classifiers: license_nix = all_classifiers[license_classifier] if license_nix is not None: license = license_nix break if license is None: license = item.get("license", "") if license in ["LGPL with exceptions or ZPL", "ZPL 2.1"]: license = "licenses.zpt21" elif license in ["MIT", "MIT License", "MIT or Apache License, Version 2.0"]: license = "licenses.mit" elif license in ["BSD", "BSD License", "BSD-like", "BSD or Apache License, Version 2.0"] or license.startswith( "BSD -" ): license = "licenses.bsdOriginal" elif license in [ "Apache 2.0", "Apache License 2.0", "Apache 2", "Apache License, Version 2.0", "Apache License Version 2.0", ]: license = "licenses.asl20" elif license in ["GNU Lesser General Public License (LGPL), Version 3", "LGPL"]: license = "licenses.lgpl3" elif license in ["MPL 2.0", "MPL 2.0 (Mozilla Public License)"]: license = "licenses.mpl20" elif license in ["Python Software Foundation License"]: license = "licenses.psfl" else: if len(license_classifiers) > 0: license = license_classifiers[0] else: click.echo("WARNING: Couldn't recognize license `{}` for `{}`".format(license, item.get("name"))) license = '"{}"'.format(safe(license)) return license
def _get_license(self) -> None: license_string = str_from_message(self.pkg_info, "license") if license_string is None: license_string = "" classifiers = list_from_message(self.pkg_info, "Classifier") if classifiers is None: classifiers = [] self.license = find_license(classifiers=classifiers, license_string=license_string) if self.license is None: self.license = '"' + safe(license_string) + '"' self.logger.warning( f"Couldn't recognize license `{license_string}` for `{self.name}`" )
def from_wheel_directory_path( wheel_class: "Type[Wheel]", wheel_directory_path: str, target_platform: TargetPlatform, logger: Logger, requirement_parser: RequirementParser, ) -> "Wheel": metadata_file = os.path.join(wheel_directory_path, "METADATA") if os.path.exists(metadata_file): with open(metadata_file, "r", encoding="ascii", errors="surrogateescape") as headers: metadata = email.parser.Parser().parse(headers) license_string = str_from_message(metadata, "license") if license_string is None: license_string = "" classifiers = list_from_message(metadata, "Classifier") if classifiers is None: classifiers = [] license = find_license(classifiers=classifiers, license_string=license_string) if license is None: license = '"' + safe(license_string) + '"' logger.warning( "Couldn't recognize license `{}` for `{}`".format( license_string, metadata.get("name"))) name = str_from_message(metadata, "name") if name is None: raise Exception("Could not extract name from wheel metadata") else: name = canonicalize_name(name) version = str_from_message(metadata, "version") if version is None: raise Exception( "Could not extract version from wheel metadata") dependencies = list_from_message(metadata, "requires-dist") if dependencies is None: dependencies = [] description = str_from_message(metadata, "summary") if description is None: description = "" return wheel_class( name=name, version=version, deps=wheel_class._extract_deps( dependencies, target_platform, requirement_parser, current_wheel_name=name, ), homepage=safe(find_homepage(metadata)), license=license, description=safe(description), build_dependencies=RequirementSet(target_platform), target_platform=target_platform, ) raise click.ClickException("Unable to find METADATA in `%s` folder." % wheel_directory_path)
def find_license(item): license = None classifiers = item.get("classifiers", []) # find first license classifier all_classifiers_keys = all_classifiers.keys() license_classifiers = [ i for i in filter(lambda x: x in all_classifiers_keys, classifiers) ] for license_classifier in license_classifiers: license_nix = all_classifiers[license_classifier] if license_nix is not None: license = license_nix break if license is None: license = item.get("license", "") if license in ["LGPL with exceptions or ZPL", "ZPL 2.1"]: license = "licenses.zpl21" elif license in ["3-Clause BSD License"]: license = "licenses.bsd3" elif license in [ "MIT", "MIT License", "MIT or Apache License, Version 2.0", "The MIT License", ]: license = "licenses.mit" elif license in [ "BSD", "BSD License", "BSD-like", "BSD or Apache License, Version 2.0", ] or license.startswith("BSD -"): license = "licenses.bsdOriginal" elif license in [ "Apache 2.0", "Apache License 2.0", "Apache 2", "Apache License, Version 2.0", "Apache License Version 2.0", ]: license = "licenses.asl20" elif license in [ "GNU Lesser General Public License (LGPL), Version 3", "LGPL" ]: license = "licenses.lgpl3" elif license in ["LGPLv3+"]: license = "licenses.lgpl3Plus" elif license in [ "MPL2", "MPL 2.0", "MPL 2.0 (Mozilla Public License)", "MPL-2.0", ]: license = "licenses.mpl20" elif license in ["Python Software Foundation License"]: license = "licenses.psfl" else: if len(license_classifiers) > 0: license = license_classifiers[0] else: click.echo( "WARNING: Couldn't recognize license `{}` for `{}`".format( license, item.get("name"))) license = '"{}"'.format(safe(license)) return license