def test_can_understand_wheel_dependecies( current_platform: TargetPlatform, requirement_parser: RequirementParser): runtime_dependencies = RequirementSet(current_platform) runtime_dependency = requirement_parser.parse("runtime_dependency") runtime_dependencies.add(runtime_dependency) build_dependencies = RequirementSet(current_platform) build_dependency = requirement_parser.parse("build_dependency") build_dependencies.add(build_dependency) wheel = Wheel( name="testpackage", version="", deps=runtime_dependencies, target_platform=current_platform, license="", homepage="", description="", build_dependencies=build_dependencies, ) requirement = requirement_parser.parse("testpackage") dependency_graph = DependencyGraph() dependency_graph.import_wheel(wheel, requirement_parser) assert dependency_graph.is_buildtime_dependency(requirement, build_dependency) assert dependency_graph.is_runtime_dependency(requirement, runtime_dependency)
def run(self) -> None: requirements = self.requirements_collector().requirements() self.logger().info("pypi2nix v{} running ...".format(pypi2nix_version)) if not requirements: self.logger().info( "No requirements were specified. Ending program.") return setup_requirements = self.setup_requirements_collector().requirements() requirements_name = os.path.join(self.configuration.target_directory, self.configuration.output_basename) sources = Sources() sources.update(setup_requirements.sources()) sources.update(requirements.sources()) sources.update(self.setup_requirements_collector().sources()) sources.update(self.requirements_collector().sources()) self.logger().info("Downloading wheels and creating wheelhouse ...") pip = NixPip( nix=self.nix(), project_directory=self.configuration.project_directory, extra_env=self.configuration.extra_environment, extra_build_inputs=self._extra_build_inputs(), wheels_cache=self.configuration.wheels_caches, target_platform=self.target_platform(), logger=self.logger(), requirement_parser=self.requirement_parser(), ) wheel_builder = WheelBuilder( pip=pip, download_directory=self.configuration.project_directory / "downloads", lib_directory=self.configuration.project_directory / "lib", extracted_wheel_directory=self.configuration.project_directory / "extracted-wheels", wheel_directory=self.configuration.project_directory / "wheels", logger=self.logger(), requirement_parser=self.requirement_parser(), target_platform=self.target_platform(), base_dependency_graph=self.base_dependency_graph(), ) wheels = wheel_builder.build(requirements=requirements, setup_requirements=setup_requirements) requirements_frozen = wheel_builder.get_frozen_requirements() source_distributions = wheel_builder.source_distributions self.logger().info("Extracting metadata from pypi.python.org ...") metadata_fetcher = MetadataFetcher( sources=sources, logger=self.logger(), requirement_parser=self.requirement_parser(), pypi=Pypi(logger=self.logger()), ) packages_metadata = metadata_fetcher.main( wheel_paths=wheels, target_platform=self.target_platform(), source_distributions=source_distributions, ) self.logger().info("Generating Nix expressions ...") renderers: List[ExpressionRenderer] = [] renderers.append( RequirementsRenderer( requirements_name=requirements_name, extra_build_inputs=self.extra_build_inputs(), python_version=self.configuration.python_version, target_directory=self.configuration.target_directory, logger=self.logger(), common_overrides=self.configuration.overrides, target_platform=self.target_platform(), requirements_frozen=requirements_frozen, code_formatter=self.code_formatter(), )) renderers.append( FlakeRenderer( target_path=Path(self.configuration.target_directory) / "flake.nix", target_platform=self.target_platform(), logger=self.logger(), overrides=self.configuration.overrides, extra_build_inputs=self.extra_build_inputs(), code_formatter=self.code_formatter(), )) for renderer in renderers: renderer.render_expression( packages_metadata=packages_metadata, sources=sources, ) if self.configuration.dependency_graph_output_location: dependency_graph = DependencyGraph() for wheel in packages_metadata: dependency_graph.import_wheel(wheel, self.requirement_parser()) with open(str(self.configuration.dependency_graph_output_location), "w") as output_file: output_file.write(dependency_graph.serialize()) self.print_user_information()