예제 #1
0
파일: command.py 프로젝트: rowhit/pynixify
    async def write_package_expression(package: PyPIPackage):
        reqs: ChosenPackageRequirements
        reqs = ChosenPackageRequirements.from_package_requirements(
            await evaluate_package_requirements(package),
            version_chooser=version_chooser,
            load_tests=version_chooser.should_load_tests(package.pypi_name),
        )

        sha256 = await get_path_hash(await package.source())
        meta = await package.metadata()
        try:
            (pname, ext) = await get_pypi_data(package.download_url,
                                               str(package.version), sha256)
        except RuntimeError:
            expr = build_nix_expression(package, reqs, meta, sha256)
        else:
            expr = build_nix_expression(package,
                                        reqs,
                                        meta,
                                        sha256,
                                        fetchPypi=(pname, ext))
        expression_dir = (packages_path / f'{package.pypi_name}/')
        expression_dir.mkdir(exist_ok=True)
        expression_path = expression_dir / 'default.nix'
        with expression_path.open('w') as fp:
            fp.write(await nixfmt(expr))
        expression_path = expression_path.relative_to(base_path)
        overlays[package.attr] = expression_path
예제 #2
0
async def test_compiles(version_chooser):
    await version_chooser.require(Requirement("sampleproject"))
    result = build_nix_expression(version_chooser.package_for('sampleproject'),
                                  NO_REQUIREMENTS,
                                  NO_METADATA,
                                  sha256='aaaaaa')
    assert await is_valid_nix(result), "Invalid Nix expression"
async def test_build_sampleproject_expression(fetchPypi):
    data = await load_nixpkgs_data(PINNED_NIXPKGS_ARGS)
    nixpkgs = NixpkgsData(data)
    pypi = PyPIData(PyPICache())

    async def f(pkg):
        return await evaluate_package_requirements(pkg, PINNED_NIXPKGS_ARGS)

    c = VersionChooser(nixpkgs, pypi, f)
    await c.require(Requirement('sampleproject==1.3.1'))
    package: PyPIPackage = c.package_for('sampleproject')  # type: ignore
    sha256 = await get_path_hash(await package.source())
    reqs = ChosenPackageRequirements(
        build_requirements=[],
        test_requirements=[],
        runtime_requirements=[c.package_for('peppercorn')]  # type: ignore
    )
    meta = await package.metadata()
    expr = build_nix_expression(package, reqs, meta, sha256, fetchPypi)

    print(expr)
    wrapper_expr = f'(import <nixpkgs> {{}}).python3.pkgs.callPackage ({expr}) {{}}'
    print(wrapper_expr)

    result = await run_nix_build(wrapper_expr)
    proc = await asyncio.create_subprocess_shell(
        f'{result}/bin/sample', stdout=asyncio.subprocess.PIPE)
    stdout, stderr = await proc.communicate()
    assert (await proc.wait()) == 0
    assert b'Call your main application code here' in stdout
예제 #4
0
async def test_duplicate_parameter(version_chooser):
    await version_chooser.require(Requirement('pytest'))
    await version_chooser.require(Requirement("sampleproject"))
    pytest = version_chooser.package_for('pytest')  # type: ignore
    requirements = ChosenPackageRequirements(build_requirements=[pytest],
                                             test_requirements=[pytest],
                                             runtime_requirements=[pytest])
    result = build_nix_expression(version_chooser.package_for('sampleproject'),
                                  requirements,
                                  NO_METADATA,
                                  sha256='aaaaaa')
    assert await is_valid_nix(result), "Invalid Nix expression"
예제 #5
0
async def test_metadata(version_chooser):
    await version_chooser.require(Requirement("sampleproject"))
    desc = "${builtins.abort builtins.currentSystem}"
    result = build_nix_expression(version_chooser.package_for('sampleproject'),
                                  NO_REQUIREMENTS,
                                  sha256='aaaaaa',
                                  metadata=PackageMetadata(
                                      description=desc,
                                      url=None,
                                      license=None,
                                  ))
    assert await nix_instantiate(result,
                                 attr='meta.description',
                                 **DEFAULT_ARGS) == desc
async def test_build_sampleproject_nixpkgs():
    data = await load_nixpkgs_data(PINNED_NIXPKGS_ARGS)
    nixpkgs = NixpkgsData(data)
    pypi = PyPIData(PyPICache())

    async def f(pkg):
        return await evaluate_package_requirements(pkg, PINNED_NIXPKGS_ARGS)

    c = VersionChooser(nixpkgs, pypi, f)
    await c.require(Requirement('pytest'))
    await c.require(Requirement('sampleproject==1.3.1'))
    package: PyPIPackage = c.package_for('sampleproject')  # type: ignore
    sha256 = await get_path_hash(await package.source())
    reqs = ChosenPackageRequirements(
        build_requirements=[],
        test_requirements=[c.package_for('pytest')],  # type: ignore
        runtime_requirements=[c.package_for('peppercorn')]  # type: ignore
    )
    package.version = Version('1.2.3')
    meta = await package.metadata()
    assert package.version == Version('1.3.1')
    sampleproject_expr = build_nix_expression(package, reqs, meta, sha256)

    with tempfile.NamedTemporaryFile(suffix='.nix') as fp:
        fp.write(sampleproject_expr.encode())
        fp.flush()
        nixpkgs_expr = build_overlayed_nixpkgs(
            {'sampleproject': Path(fp.name)})
        print(nixpkgs_expr)
        wrapper_expr = f"""(({nixpkgs_expr}) {{}}).python3.pkgs.sampleproject"""
        result = await run_nix_build(wrapper_expr)

    assert 'default.nix' not in nixpkgs_expr

    proc = await asyncio.create_subprocess_shell(
        f'{result}/bin/sample', stdout=asyncio.subprocess.PIPE)
    stdout, stderr = await proc.communicate()
    assert (await proc.wait()) == 0
    assert b'Call your main application code here' in stdout
async def test_build_textwrap3_expression():
    data = await load_nixpkgs_data(PINNED_NIXPKGS_ARGS)
    nixpkgs = NixpkgsData(data)
    pypi = PyPIData(PyPICache())

    async def f(pkg):
        return await evaluate_package_requirements(pkg, PINNED_NIXPKGS_ARGS)

    c = VersionChooser(nixpkgs, pypi, f)
    await c.require(Requirement('textwrap3==0.9.1'))
    package: PyPIPackage = c.package_for('textwrap3')  # type: ignore
    sha256 = await get_path_hash(await package.source())
    reqs = ChosenPackageRequirements(
        build_requirements=[],
        test_requirements=[],
        runtime_requirements=[],
    )
    meta = await package.metadata()
    expr = build_nix_expression(package, reqs, meta, sha256,
                                ('textwrap3', 'zip'))
    print(expr)
    wrapper_expr = f'(import <nixpkgs> {{}}).python3.pkgs.callPackage ({expr}) {{}}'
    print(wrapper_expr)
    result = await run_nix_build(wrapper_expr)