Example #1
0
 def __init__(
     self,
     name: str,
     logger: Logger,
     pyproject_toml: Any = None,
     setup_cfg: Any = None,
 ) -> None:
     self.name = canonicalize_name(name)
     self.pyproject_toml = pyproject_toml
     self.setup_cfg = setup_cfg
     self.logger = logger
Example #2
0
 def __init__(
         self,
         name: str,
         version: str,
         deps: Iterable[str],
         homepage: str,
         license: str,
         description: str,
         build_dependencies: Set[str] = set(),
 ):
     self.name = canonicalize_name(name)
     self.version = version
     self.deps = set(map(canonicalize_name, deps))
     self.homepage = homepage
     self.license = license
     self.description = description
     self.build_dependencies = set(
         map(canonicalize_name, build_dependencies))
Example #3
0
 def valid_dependency(self, dependency: str) -> bool:
     canonicalized_dependency = canonicalize_name(dependency)
     return all([
         canonicalized_dependency != self.name,
         canonicalized_dependency not in TO_IGNORE,
     ])
Example #4
0
 def add_build_dependencies(self, dependencies: Iterable[str]) -> None:
     for dependency in dependencies:
         if self.valid_dependency(dependency):
             self.build_dependencies.add(canonicalize_name(dependency))
Example #5
0
 def __getitem__(self, key: str) -> Requirement:
     return self.requirements[canonicalize_name(key)]
Example #6
0
def main(
    packages_metadata: Iterable[Wheel],
    sources: Sources,
    requirements_name: str,
    requirements_frozen: str,
    extra_build_inputs: Iterable[str],
    enable_tests: bool,
    python_version: str,
    current_dir: str,
    common_overrides: Iterable[AnyOverrides] = [],
) -> None:
    """Create Nix expressions.
    """

    default_file = os.path.join(current_dir,
                                "{}.nix".format(requirements_name))
    overrides_file = os.path.join(current_dir,
                                  "{}_override.nix".format(requirements_name))
    frozen_file = os.path.join(current_dir,
                               "{}_frozen.txt".format(requirements_name))

    version_file = os.path.join(os.path.dirname(__file__), "VERSION")
    with open(version_file) as f:
        version = f.read()
    version = version.strip()

    metadata_by_name = {x.name: x for x in packages_metadata}

    generated_packages_metadata = []
    for item in sorted(packages_metadata, key=lambda x: x.name):
        if item.build_dependencies:
            buildInputs = "\n".join(
                sorted([
                    '        self."{}"'.format(name)
                    for name in item.build_dependencies
                ]))
            buildInputs = "[\n" + buildInputs + "\n      ]"
        else:
            buildInputs = "[ ]"
        propagatedBuildInputs = "[ ]"
        if item.deps:
            deps = [
                canonicalize_name(x) for x in item.deps
                if canonicalize_name(x) in metadata_by_name.keys()
            ]
            if deps:
                propagatedBuildInputs = "[\n%s\n      ]" % ("\n".join(
                    sorted([
                        '        self."%s"' % (metadata_by_name[x].name)
                        for x in deps if x != item.name
                    ])))
        source = sources[item.name]
        fetch_expression = source.nix_expression()
        generated_packages_metadata.append(
            dict(
                name=item.name,
                version=item.version,
                fetch_expression=fetch_expression,
                buildInputs=buildInputs,
                propagatedBuildInputs=propagatedBuildInputs,
                homepage=item.homepage,
                license=item.license,
                description=item.description,
            ))

    templates = jinja2.Environment(
        loader=jinja2.FileSystemLoader(HERE + "/templates"))

    generated_template = templates.get_template("generated.nix.j2")
    generated = "\n\n".join(
        generated_template.render(**x) for x in generated_packages_metadata)

    overrides = templates.get_template("overrides.nix.j2").render()

    common_overrides_expressions = [
        "    (" + override.nix_expression() + ")"
        for override in common_overrides
    ]

    default_template = templates.get_template("requirements.nix.j2")
    overrides_file_nix_path = os.path.join(".",
                                           os.path.split(overrides_file)[1])
    default = default_template.render(
        version=version,
        command_arguments=" ".join(map(shlex.quote, sys.argv[1:])),
        python_version=python_version,
        extra_build_inputs=(extra_build_inputs and "with pkgs; [ %s ]" %
                            (" ".join(extra_build_inputs)) or "[]"),
        overrides_file=overrides_file_nix_path,
        enable_tests=str(enable_tests).lower(),
        generated_package_nix=generated,
        common_overrides="\n".join(common_overrides_expressions),
        paths_to_remove="paths_to_remove.remove(auto_confirm)",
        self_uninstalled="self.uninstalled = paths_to_remove",
        python_major_version=python_version.replace("python", "")[0],
    )

    if not os.path.exists(overrides_file):
        with open(overrides_file, "w+") as f:
            f.write(overrides.strip())
            click.echo("|-> writing %s" % overrides_file)

    with open(default_file, "w+") as f:
        f.write(default.strip())

    with open(frozen_file, "w+") as f:
        f.write(requirements_frozen)
Example #7
0
 def name(self) -> str:
     return canonicalize_name(self._name)