def from_archive(
     source_distribution,
     archive: Archive,
     logger: Logger,
     requirement_parser: RequirementParser,
 ) -> "SourceDistribution":
     with archive.extracted_files() as extraction_directory:
         extracted_files = [
             os.path.join(directory_path, file_name) for directory_path, _,
             file_names in os.walk(extraction_directory)
             for file_name in file_names
         ]
         metadata = source_distribution.metadata_from_uncompressed_distribution(
             extracted_files, archive)
         name: str = metadata.get("name")
         if isinstance(name, Header):
             raise DistributionNotDetected(
                 "Could not parse source distribution metadata, name detection failed"
             )
         pyproject_toml = source_distribution.get_pyproject_toml(
             name, extracted_files, logger, requirement_parser)
         setup_cfg = source_distribution.get_setup_cfg(
             name, extracted_files, logger, requirement_parser)
     return source_distribution(
         name=name,
         pyproject_toml=pyproject_toml,
         setup_cfg=setup_cfg,
         logger=logger,
         requirement_parser=requirement_parser,
     )
Exemple #2
0
def setupcfg_package_wheel(
    setupcfg_package_wheel_path: str,
    logger: Logger,
    requirement_parser: RequirementParser,
    current_platform: TargetPlatform,
) -> Wheel:
    archive = Archive(path=setupcfg_package_wheel_path)
    with archive.extracted_files() as directory:
        return Wheel.from_wheel_directory_path(
            os.path.join(directory, "setupcfg_package-1.0.dist-info"),
            current_platform,
            logger,
            requirement_parser,
        )
 def from_archive(
     source_distribution,
     archive: Archive,
     logger: Logger,
     requirement_parser: RequirementParser,
 ) -> "SourceDistribution":
     with archive.extracted_files() as extraction_directory:
         first_level_paths = os.listdir(extraction_directory)
         if len(first_level_paths) != 1:
             raise DistributionNotDetected(
                 f"Multiple package directories or files extracted from {archive}"
             )
         package_dir = os.path.join(extraction_directory, first_level_paths[0])
         if not os.path.isdir(package_dir):
             raise DistributionNotDetected(
                 f"No package directory could be extracted from source distribution {archive}"
             )
         extracted_files = [
             os.path.join(package_dir, file_name)
             for file_name in os.listdir(package_dir)
             if os.path.isfile(os.path.join(package_dir, file_name))
         ]
         setup_cfg = source_distribution.get_setup_cfg(
             extracted_files, logger, requirement_parser
         )
         metadata = source_distribution._get_package_metadata(package_dir)
         name = source_distribution._get_name(setup_cfg, metadata, archive)
         pyproject_toml = source_distribution.get_pyproject_toml(
             name, extracted_files, logger, requirement_parser
         )
     return source_distribution(
         name=name,
         pyproject_toml=pyproject_toml,
         setup_cfg=setup_cfg,
         logger=logger,
         requirement_parser=requirement_parser,
     )
def test_that_we_can_inspect_the_content_of_a_wheel(
        setupcfg_package_wheel_path: str):
    archive = Archive(path=setupcfg_package_wheel_path)
    with archive.extracted_files() as directory:
        assert "setupcfg_package-1.0.dist-info" in os.listdir(directory)
def test_that_we_can_inspect_the_content_of_an_archive(archive: Archive):
    with archive.extracted_files() as directory:
        files = tuple(os.listdir(directory))
        assert files == ("test.txt", )