def parse_package_file(file_name, package): """Builds a parsed package requirement object from a filename. Args: file_name: a string filename or boto Key object package: parsed package requirement object this file is part of """ if isinstance(file_name, Key): file_name = file_name.name.partition("/")[2] if not file_name or package.project_name not in safe_name(file_name): return for ext in SUPPORTED_EXTENSIONS: if not file_name.endswith(ext): continue # specifically not using os.path.split to get .tar.gz file_ = file_name.rsplit(ext)[0] if ext == wheel_ext: wheel = Wheel(file_name) # wheel won't consider -alpha -dev, etc.. in the version ver = wheel.version for tag_group in wheel.file_tags: for tag in tag_group: try: ver = SetuptoolsVersion("{}-{}".format(ver, tag)) except: break break return parse_package("{}=={}".format(wheel.name, ver)) else: pkg_name = package.project_name firstrun = True while "-" in file_ or firstrun: firstrun = False try: return parse_package("{}=={}".format( pkg_name, egg_info_matches(file_, pkg_name, pkg_name), )) except Exception: file_ = file_.rpartition("-")[0]
def find_downloaded(packages, storage_dir): """Filters out the requested packages' dependencies in storage_dir. Args:: packages: list of package names, perhaps version specific storage_dir: full string filepath to the temporary storage Returns: a list of string full file paths of package releases to upload """ to_upload = [] files_on_disk = os.listdir(storage_dir) for package in packages: parsed = list(parse_requirements(package))[0] for file_ in files_on_disk: if parsed.project_name not in file_: continue for ext in SUPPORTED_EXTENSIONS: if file_.endswith(ext): file_ver = SetuptoolsVersion(egg_info_matches( file_.split(ext)[0], parsed.project_name, file_, )) break else: logging.info("file %s skipped, unsupported extension", file_) continue for spec in parsed.specs: req_ver = SetuptoolsVersion(spec[1]) if not OPERATORS[spec[0]](file_ver, req_ver): logging.info("downloaded file %s is not %s %s", file_, spec[0], spec[1]) break else: to_upload.append(os.path.join(storage_dir, file_)) break return to_upload