Ejemplo n.º 1
0
def venv_test_dir():
    skipif.no_network()
    dirs = AppDirs('reproman')

    ssp = os.getenv("REPROMAN_TESTS_ASSUME_SSP")
    # Encode the SSP value in the directory name so that the caller doesn't
    # have to worry about deleting the cached venvs before setting the flag..
    test_dir = os.path.join(dirs.user_cache_dir,
                            'venv_test{}'.format("_ssp" if ssp else ""))
    if os.path.exists(test_dir):
        return test_dir

    os.makedirs(test_dir)
    pymod_dir = os.path.join(test_dir, "minimal_pymodule")
    create_pymodule(pymod_dir)

    runner = Runner(cwd=test_dir)
    pip0 = op.join("venv0", "bin", "pip")
    pip1 = op.join("venv1", "bin", "pip")
    runner.run(["virtualenv", "--python", PY_VERSION, "venv0"])
    runner.run(["virtualenv", "--python", PY_VERSION, "venv1"])
    runner.run([pip0, "install", "pyyaml"])
    runner.run([pip0, "install", "-e", pymod_dir])
    runner.run([pip1, "install", "attrs"])
    # Make sure we're compatible with older pips.
    runner.run([pip1, "install", "pip==9.0.3"])

    if ssp:
        # The testing environment supports --system_site_packages.
        pip2 = op.join("venv-nonlocal", "bin", "pip")
        runner.run(["virtualenv", "--python", PY_VERSION,
                    "--system-site-packages", "venv-nonlocal"])
        runner.run([pip2, "install", "attrs"])

    return test_dir
Ejemplo n.º 2
0
def venv_test_dir():
    dirs = AppDirs('reproman')
    test_dir = os.path.join(dirs.user_cache_dir, 'venv_test')
    if os.path.exists(test_dir):
        return test_dir

    runner = Runner()
    runner.run(["mkdir", "-p", test_dir])

    pymod_dir = os.path.join(test_dir, "minimal_pymodule")
    create_pymodule(pymod_dir)

    with chpwd(test_dir):
        runner.run(["virtualenv", "--python", PY_VERSION, "venv0"])
        runner.run(["virtualenv", "--python", PY_VERSION, "venv1"])
        runner.run(["./venv0/bin/pip", "install", "pyyaml"])
        runner.run(["./venv0/bin/pip", "install", "-e", pymod_dir])
        runner.run(["./venv1/bin/pip", "install", "attrs"])
        # Make sure we're compatible with older pips.
        runner.run(["./venv1/bin/pip", "install", "pip==9.0.3"])
    return test_dir
Ejemplo n.º 3
0
def venv_test_dir():
    skipif.no_network()
    dirs = AppDirs('reproman')
    test_dir = os.path.join(dirs.user_cache_dir, 'venv_test')
    if os.path.exists(test_dir):
        return test_dir

    os.makedirs(test_dir)
    pymod_dir = os.path.join(test_dir, "minimal_pymodule")
    create_pymodule(pymod_dir)

    runner = Runner(cwd=test_dir)
    pip0 = op.join("venv0", "bin", "pip")
    pip1 = op.join("venv1", "bin", "pip")
    runner.run(["virtualenv", "--python", PY_VERSION, "venv0"])
    runner.run(["virtualenv", "--python", PY_VERSION, "venv1"])
    runner.run([pip0, "install", "pyyaml"])
    runner.run([pip0, "install", "-e", pymod_dir])
    runner.run([pip1, "install", "attrs"])
    # Make sure we're compatible with older pips.
    runner.run([pip1, "install", "pip==9.0.3"])
    return test_dir
Ejemplo n.º 4
0
def test_conda_init_install_and_detect(tmpdir):
    # Note: We use a subdirectory of tmpdir because `install_packages` decides
    # to install miniconda based on whether the directory exists.
    test_dir = os.path.join(str(tmpdir), "miniconda")
    dist = CondaDistribution(
        name="conda",
        path=test_dir,
        conda_version="4.8.2",
        python_version="3.8.2",
        platform=get_conda_platform_from_python(sys.platform) + "-64",
        environments=[
            CondaEnvironment(
                name="root",
                path=test_dir,
                packages=[
                    CondaPackage(name="conda",
                                 installer=None,
                                 version="4.8.2",
                                 build=None,
                                 channel_name=None,
                                 md5=None,
                                 size=None,
                                 url=None,
                                 files=None),
                    CondaPackage(name="pip",
                                 installer=None,
                                 version="20.0.2",
                                 build=None,
                                 channel_name=None,
                                 md5=None,
                                 size=None,
                                 url=None,
                                 files=None),
                    CondaPackage(name="pytest",
                                 installer="pip",
                                 version="3.4.0",
                                 build=None,
                                 channel_name=None,
                                 md5=None,
                                 size=None,
                                 url=None,
                                 files=None)
                ],
                channels=[
                    CondaChannel(
                        name="conda-forge",
                        url="https://conda.anaconda.org/conda-forge/linux-64"),
                    CondaChannel(
                        name="defaults",
                        url="https://repo.continuum.io/pkgs/main/linux-64")
                ]),
            CondaEnvironment(
                name="mytest",
                path=os.path.join(test_dir, "envs/mytest"),
                packages=[
                    CondaPackage(name="pip",
                                 installer=None,
                                 version="20.0.2",
                                 build=None,
                                 channel_name=None,
                                 md5=None,
                                 size=None,
                                 url=None,
                                 files=None),
                    CondaPackage(
                        name="xz",
                        installer=None,
                        version="5.2.3",
                        build="0",
                        channel_name="conda-forge",
                        md5="f4e0d30b3caf631be7973cba1cf6f601",
                        size="874292",
                        url=
                        "https://conda.anaconda.org/conda-forge/linux-64/xz-5.2.3-0.tar.bz2",
                        files=[
                            "bin/xz",
                        ]),
                    CondaPackage(
                        name="rpaths",
                        installer="pip",
                        version="0.13",
                        build=None,
                        channel_name=None,
                        md5=None,
                        size=None,
                        url=None,
                        files=["lib/python3.8/site-packages/rpaths.py"])
                ],
                channels=[
                    CondaChannel(
                        name="conda-forge",
                        url="https://conda.anaconda.org/conda-forge/linux-64")
                ])
        ])
    # First install the environment in the temporary directory.
    dist.initiate(None)
    dist.install_packages()
    # Add an empty environment to test detection of them
    if not os.path.exists(os.path.join(test_dir, "envs/empty")):
        call("cd " + test_dir + "; " + "./bin/conda create -y -n empty; ",
             shell=True)

    # Test that editable packages are detected
    pymod_dir = os.path.join(test_dir, "minimal_pymodule")
    if not os.path.exists(pymod_dir):
        create_pymodule(pymod_dir)
        call([
            os.path.join(test_dir, "envs/mytest/bin/pip"), "install", "-e",
            pymod_dir
        ])

    # Now pick some files we know are in the conda install and detect them
    files = [
        os.path.join(test_dir, "bin/pip"),
        os.path.join(test_dir, "envs/mytest/bin/xz"),
        os.path.join(test_dir, "envs/empty/conda-meta/history"),
    ]
    tracer = CondaTracer()
    dists = list(tracer.identify_distributions(files))

    assert len(dists) == 1, "Exactly one Conda distribution expected."

    (distributions, unknown_files) = dists[0]

    # RepromanProvenance.write(sys.stdout, distributions)

    assert distributions.platform.startswith(
        get_conda_platform_from_python(sys.platform)), \
        "A conda platform is expected."

    assert len(distributions.environments) == 3, \
        "Three conda environments are expected."

    out = {
        'environments': [{
            'name': 'root',
            'packages': [{
                'name': 'pip'
            }]
        }, {
            'name':
            'mytest',
            'packages': [{
                'name': 'xz'
            }, {
                'name': 'pip'
            }, {
                'name': 'rpaths',
                'installer': 'pip',
                'editable': False
            }, {
                'name': 'nmtest',
                'files': [],
                'installer': 'pip',
                'editable': True
            }]
        }]
    }
    assert_is_subset_recur(out, attr.asdict(distributions), [dict, list])

    # conda packages are not repeated as "pip" packages.
    for envs in distributions.environments:
        for pkg in envs.packages:
            if pkg.name == "pip":
                assert pkg.installer is None

    # Smoke test to make sure install_packages doesn't choke on the format that
    # is actually returned by the tracer.
    distributions.initiate(None)
    distributions.install_packages()