def main(): logger = StreamLogger(sys.stdout) pypi = Pypi(logger=logger) requirements = ["pip", "setuptools", "wheel"] for name in requirements: package = pypi.get_package(name) source_release = pypi.get_source_release(name=name, version=package.version) if source_release is None: logger.warning(f"Could not update source for package `{name}`") continue INDEX[name] = INDEX.Entry( url=source_release.url, sha256=source_release.sha256_digest )
def main(): logger = StreamLogger(sys.stdout) pypi = Pypi(logger=logger) pip_requirements: List[str] = ["setuptools", "wheel", "pip"] git_requirements: List[str] = [] index = Index(logger=logger) package_source = PackageSource(index=index, pypi=pypi, logger=logger) for requirement in pip_requirements: package_source.update_package_from_pip(requirement) for requirement in git_requirements: package_source.update_package_from_master(requirement)
def main(): logger = StreamLogger(sys.stdout) pypi = Pypi(logger=logger) pip_requirements = ["setuptools", "wheel"] git_requirements = [("pip", "https://github.com/pypa/pip.git")] index = Index(logger=logger) for name in pip_requirements: insert_pip_requirement(index, name, logger, pypi) for name, url in git_requirements: insert_git_requirement(index, name, url) assert index.is_valid()
def pypi(logger: Logger) -> Pypi: return Pypi(logger=logger)
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.configuration.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, project_directory=self.configuration.project_directory, logger=self.logger(), requirement_parser=self.requirement_parser(), target_platform=self.target_platform(), ) 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 ...") render_expression( packages_metadata=packages_metadata, sources=sources, requirements_name=requirements_name, requirements_frozen=requirements_frozen, extra_build_inputs=(self.configuration.extra_build_inputs if self.configuration.emit_extra_build_inputs else []), enable_tests=self.configuration.enable_tests, python_version=self.configuration.python_version, target_directory=self.configuration.target_directory, logger=self.logger(), common_overrides=self.configuration.overrides, ) self.print_user_information()
def pypi(logger: Logger): return Pypi(logger)
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()