Пример #1
0
    def test_initialize_dev_cmd_exe(self):
        with env_vars({'CONDA_DRY_RUN': 'true', 'CONDA_VERBOSITY': '0'}, reset_context):
            with tempdir() as conda_temp_prefix:
                new_py = abspath(join(conda_temp_prefix, get_python_short_path()))
                mkdir_p(dirname(new_py))
                create_link(abspath(sys.executable), new_py, LinkType.hardlink if on_win else LinkType.softlink)
                with captured() as c:
                    initialize_dev('cmd.exe', dev_env_prefix=conda_temp_prefix, conda_source_root=dirname(CONDA_PACKAGE_ROOT))

        print(c.stdout)
        print(c.stderr, file=sys.stderr)

        if on_win:
            modified_files = (
                'conda.exe',
                'conda-env.exe',
                'conda-script.py',
                'conda-env-script.py',
                'conda.bat',
                '_conda_activate.bat',
                'conda_auto_activate.bat',
                'conda_hook.bat',
                'activate.bat',
                'activate.bat',
                'deactivate.bat',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'conda.xsh',
                'conda.csh',
                'site-packages',  # remove conda in site-packages dir
                'conda.egg-link',
                'easy-install.pth',
                'conda.egg-info',

            )
        else:
            modified_files = (
                'conda',
                'conda-env',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'conda.xsh',
                'conda.csh',
                'site-packages',  # remove conda in site-packages dir
                'conda.egg-link',
                'easy-install.pth',
                'conda.egg-info',

            )

        stderr = c.stderr.replace('no change', 'modified')
        assert stderr.count('modified') == len(modified_files)

        for fn in modified_files:
            line = next(line for line in stderr.splitlines() if line.strip().endswith(fn))
            assert line.strip().startswith('modified'), line
Пример #2
0
    def test_initialize_dev_cmd_exe(self):
        with env_vars({'CONDA_DRY_RUN': 'true', 'CONDA_VERBOSITY': '0'}, reset_context):
            with tempdir() as conda_temp_prefix:
                new_py = abspath(join(conda_temp_prefix, get_python_short_path()))
                mkdir_p(dirname(new_py))
                create_link(abspath(sys.executable), new_py, LinkType.hardlink if on_win else LinkType.softlink)
                with captured() as c:
                    initialize_dev('cmd.exe', dev_env_prefix=conda_temp_prefix, conda_source_root=dirname(CONDA_PACKAGE_ROOT))

        print(c.stdout)
        print(c.stderr, file=sys.stderr)

        if on_win:
            modified_files = (
                'conda.exe',
                'conda-env.exe',
                'conda-script.py',
                'conda-env-script.py',
                'conda.bat',
                '_conda_activate.bat',
                'conda_auto_activate.bat',
                'conda_hook.bat',
                'activate.bat',
                'activate.bat',
                'deactivate.bat',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'conda.xsh',
                'conda.csh',
                'site-packages',  # remove conda in site-packages dir
                'conda.egg-link',
                'easy-install.pth',
                'conda.egg-info',

            )
        else:
            modified_files = (
                'conda',
                'conda-env',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'conda.xsh',
                'conda.csh',
                'site-packages',  # remove conda in site-packages dir
                'conda.egg-link',
                'easy-install.pth',
                'conda.egg-info',

            )

        stderr = c.stderr.replace('no change', 'modified')
        assert stderr.count('modified') == len(modified_files)

        for fn in modified_files:
            line = next(line for line in stderr.splitlines() if line.strip().endswith(fn))
            assert line.strip().startswith('modified'), line
Пример #3
0
    def test_initialize_dev_bash(self):
        with pytest.raises(CondaValueError):
            initialize_dev('bash', conda_source_root=join('a', 'b', 'c'))

        with env_var('CONDA_DRY_RUN', 'true', reset_context):
            with tempdir() as conda_temp_prefix:
                new_py = abspath(
                    join(conda_temp_prefix, get_python_short_path()))
                mkdir_p(dirname(new_py))
                create_link(abspath(sys.executable), new_py,
                            LinkType.hardlink if on_win else LinkType.softlink)
                with captured() as c:
                    initialize_dev('bash', dev_env_prefix=conda_temp_prefix)

        print(c.stdout)
        print(c.stderr, file=sys.stderr)

        if on_win:
            modified_files = (
                'conda.exe',
                'conda-env.exe',
                'conda-script.py',
                'conda-env-script.py',
                'conda.bat',
                'conda.bat',
                'conda-hook.bat',
                'activate.bat',
                'deactivate.bat',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'conda.xsh',
                'conda.csh',
                'site-packages',
                'conda-dev.pth',
            )
        else:
            modified_files = (
                'conda',
                'conda-env',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'conda.xsh',
                'conda.csh',
                'site-packages',  # remove conda in site-packages dir
                'conda-dev.pth',
            )

        stderr = c.stderr.replace('no change', 'modified')
        assert stderr.count('modified') == len(modified_files)

        stderr = "".join(s.strip('\n\r') for s in stderr.splitlines())
        for fn in modified_files:
            assert '%s  modified' % fn in stderr

        assert "unset CONDA_SHLVL" in c.stdout
Пример #4
0
    def test_CompilePycAction_noarch_python(self):
        if not softlink_supported(__file__, self.prefix) and on_win:
            pytest.skip("softlink not supported")

        target_python_version = '%d.%d' % sys.version_info[:2]
        sp_dir = get_python_site_packages_short_path(target_python_version)
        transaction_context = {
            'target_python_version': target_python_version,
            'target_site_packages_short_path': sp_dir,
        }
        package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict(type=NoarchType.python)))

        file_link_actions = [
            AttrDict(
                source_short_path='site-packages/something.py',
                target_short_path=get_python_noarch_target_path('site-packages/something.py', sp_dir),
            ),
            AttrDict(
                # this one shouldn't get compiled
                source_short_path='something.py',
                target_short_path=get_python_noarch_target_path('something.py', sp_dir),
            ),
        ]
        axns = CompilePycAction.create_actions(transaction_context, package_info, self.prefix,
                                               None, file_link_actions)

        assert len(axns) == 1
        axn = axns[0]
        assert axn.source_full_path == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/something.py', sp_dir)))
        assert axn.target_full_path == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/something.py', sp_dir),
                     target_python_version)))

        # make .py file in prefix that will be compiled
        mkdir_p(dirname(axn.source_full_path))
        with open(axn.source_full_path, 'w') as fh:
            fh.write("value = 42\n")

        # symlink the current python
        python_full_path = join(self.prefix, get_python_short_path(target_python_version))
        mkdir_p(dirname(python_full_path))
        create_link(sys.executable, python_full_path, LinkType.softlink)

        axn.execute()
        assert isfile(axn.target_full_path)

        # remove the source .py file so we're sure we're importing the pyc file below
        rm_rf(axn.source_full_path)
        assert not isfile(axn.source_full_path)

        if (3,) > sys.version_info >= (3, 5):
            # we're probably dropping py34 support soon enough anyway
            imported_pyc_file = load_python_file(axn.target_full_path)
            assert imported_pyc_file.value == 42

        axn.reverse()
        assert not isfile(axn.target_full_path)
Пример #5
0
    def test_CompilePycAction_noarch_python(self):
        target_python_version = '%d.%d' % sys.version_info[:2]
        sp_dir = get_python_site_packages_short_path(target_python_version)
        transaction_context = {
            'target_python_version': target_python_version,
            'target_site_packages_short_path': sp_dir,
        }
        package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict(type=NoarchType.python)))

        file_link_actions = [
            AttrDict(
                source_short_path='site-packages/something.py',
                target_short_path=get_python_noarch_target_path('site-packages/something.py', sp_dir),
            ),
            AttrDict(
                # this one shouldn't get compiled
                source_short_path='something.py',
                target_short_path=get_python_noarch_target_path('something.py', sp_dir),
            ),
        ]
        axns = CompilePycAction.create_actions(transaction_context, package_info, self.prefix,
                                               None, file_link_actions)

        assert len(axns) == 1
        axn = axns[0]
        assert axn.source_full_path == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/something.py', sp_dir)))
        assert axn.target_full_path == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/something.py', sp_dir), target_python_version)))

        # make .py file in prefix that will be compiled
        mkdir_p(dirname(axn.source_full_path))
        with open(axn.source_full_path, 'w') as fh:
            fh.write("value = 42\n")

        # symlink the current python
        python_full_path = join(self.prefix, get_python_short_path(target_python_version))
        mkdir_p(dirname(python_full_path))
        create_link(sys.executable, python_full_path, LinkType.softlink)

        axn.execute()
        assert isfile(axn.target_full_path)

        # remove the source .py file so we're sure we're importing the pyc file below
        rm_rf(axn.source_full_path)
        assert not isfile(axn.source_full_path)

        if (3, ) > sys.version_info >= (3, 5):
            # we're probably dropping py34 support soon enough anyway
            imported_pyc_file = load_python_file(axn.target_full_path)
            assert imported_pyc_file.value == 42

        axn.reverse()
        assert not isfile(axn.target_full_path)
Пример #6
0
def test_rm_rf_does_not_follow_symlinks():
    with TemporaryDirectory() as tmp:
        # make a file in some temp folder
        real_file = os.path.join(tmp, 'testfile')
        with open(real_file, 'w') as f:
            f.write('weee')
        # make a subfolder
        subdir = os.path.join(tmp, 'subfolder')
        os.makedirs(subdir)
        # link to the file in the subfolder
        link_path = join(subdir, 'file_link')
        create_link(real_file, link_path, link_type=LinkType.softlink)
        assert islink(link_path)
        # rm_rf the subfolder
        rm_rf(subdir)
        # assert that the file still exists in the root folder
        assert os.path.isfile(real_file)
    def test_initialize_dev_bash(self):
        with pytest.raises(CondaValueError):
            initialize_dev('bash', conda_source_root=join('a', 'b', 'c'))

        with env_vars({'CONDA_DRY_RUN': 'true', 'CONDA_VERBOSITY': '0'}, stack_callback=conda_tests_ctxt_mgmt_def_pol):
            with tempdir() as conda_temp_prefix:
                new_py = abspath(join(conda_temp_prefix, get_python_short_path()))
                mkdir_p(dirname(new_py))
                create_link(abspath(sys.executable), new_py, LinkType.hardlink if on_win else LinkType.softlink)
                with captured() as c:
                    initialize_dev('bash', dev_env_prefix=conda_temp_prefix, conda_source_root=dirname(CONDA_PACKAGE_ROOT))

        print(c.stdout)
        print(c.stderr, file=sys.stderr)

        if on_win:
            modified_files = (
                'conda.exe',
                'conda-env.exe',
                'conda-script.py',
                'conda-env-script.py',
                'conda.bat',  # condabin/conda.bat
                'conda.bat',  # Library/bin/conda.bat
                '_conda_activate.bat',
                'rename_tmp.bat',
                'conda_auto_activate.bat',
                'conda_hook.bat',
                'activate.bat',
                'activate.bat',
                'deactivate.bat',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'Conda.psm1',
                'conda-hook.ps1',
                'conda.xsh',
                'conda.csh',
                'site-packages',  # remove conda in site-packages dir
                'conda.egg-link',
                'easy-install.pth',
                'conda.egg-info',
            )
        else:
            modified_files = (
                'conda',  # condabin/conda
                'conda',  # bin/conda
                'conda-env',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'Conda.psm1',
                'conda-hook.ps1',
                'conda.xsh',
                'conda.csh',
                'site-packages',  # remove conda in site-packages dir
                'conda.egg-link',
                'easy-install.pth',
                'conda.egg-info',
            )

        stderr = c.stderr.replace('no change', 'modified')
        assert stderr.count('modified') == len(modified_files)

        for fn in modified_files:
            line = next(line for line in stderr.splitlines() if line.strip().endswith(fn))
            assert line.strip().startswith('modified'), line

        assert "unset CONDA_SHLVL" in c.stdout
Пример #8
0
    def test_initialize_dev_bash(self):
        with pytest.raises(CondaValueError):
            initialize_dev('bash', conda_source_root=join('a', 'b', 'c'))

        with env_vars({'CONDA_DRY_RUN': 'true', 'CONDA_VERBOSITY': '0'}, conda_tests_ctxt_mgmt_def_pol):
            with tempdir() as conda_temp_prefix:
                new_py = abspath(join(conda_temp_prefix, get_python_short_path()))
                mkdir_p(dirname(new_py))
                create_link(abspath(sys.executable), new_py, LinkType.hardlink if on_win else LinkType.softlink)
                with captured() as c:
                    initialize_dev('bash', dev_env_prefix=conda_temp_prefix, conda_source_root=dirname(CONDA_PACKAGE_ROOT))

        print(c.stdout)
        print(c.stderr, file=sys.stderr)

        if on_win:
            modified_files = (
                'conda.exe',
                'conda-env.exe',
                'conda-script.py',
                'conda-env-script.py',
                'conda.bat',  # condabin/conda.bat
                'conda.bat',  # Library/bin/conda.bat
                '_conda_activate.bat',
                'rename_tmp.bat',
                'conda_auto_activate.bat',
                'conda_hook.bat',
                'activate.bat',
                'activate.bat',
                'deactivate.bat',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'Conda.psm1',
                'conda-hook.ps1',
                'conda.xsh',
                'conda.csh',
                'site-packages',  # remove conda in site-packages dir
                'conda.egg-link',
                'easy-install.pth',
                'conda.egg-info',
            )
        else:
            modified_files = (
                'conda',  # condabin/conda
                'conda',  # bin/conda
                'conda-env',
                'activate',
                'deactivate',
                'conda.sh',
                'conda.fish',
                'Conda.psm1',
                'conda-hook.ps1',
                'conda.xsh',
                'conda.csh',
                'site-packages',  # remove conda in site-packages dir
                'conda.egg-link',
                'easy-install.pth',
                'conda.egg-info',
            )

        stderr = c.stderr.replace('no change', 'modified')
        assert stderr.count('modified') == len(modified_files)

        for fn in modified_files:
            line = next(line for line in stderr.splitlines() if line.strip().endswith(fn))
            assert line.strip().startswith('modified'), line

        assert "unset CONDA_SHLVL" in c.stdout
Пример #9
0
    def test_CompileMultiPycAction_noarch_python(self):
        if not softlink_supported(__file__, self.prefix) and on_win:
            pytest.skip("softlink not supported")
        target_python_version = '%d.%d' % sys.version_info[:2]
        sp_dir = get_python_site_packages_short_path(target_python_version)
        transaction_context = {
            'target_python_version': target_python_version,
            'target_site_packages_short_path': sp_dir,
        }
        package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict(type=NoarchType.python)))

        file_link_actions = [
            AttrDict(
                source_short_path='site-packages/something.py',
                target_short_path=get_python_noarch_target_path('site-packages/something.py', sp_dir),
            ),
            AttrDict(
                source_short_path='site-packages/another.py',
                target_short_path=get_python_noarch_target_path('site-packages/another.py', sp_dir),
            ),
            AttrDict(
                # this one shouldn't get compiled
                source_short_path='something.py',
                target_short_path=get_python_noarch_target_path('something.py', sp_dir),
            ),
            AttrDict(
                # this one shouldn't get compiled
                source_short_path='another.py',
                target_short_path=get_python_noarch_target_path('another.py', sp_dir),
            ),
        ]
        axns = CompileMultiPycAction.create_actions(transaction_context, package_info, self.prefix,
                                                    None, file_link_actions)

        assert len(axns) == 1
        axn = axns[0]
        source_full_paths = tuple(axn.source_full_paths)
        source_full_path0 = source_full_paths[0]
        source_full_path1 = source_full_paths[1]
        assert len(source_full_paths) == 2
        assert source_full_path0 == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/something.py', sp_dir)))
        assert source_full_path1 == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/another.py', sp_dir)))
        target_full_paths = tuple(axn.target_full_paths)
        target_full_path0 = target_full_paths[0]
        target_full_path1 = target_full_paths[1]
        assert len(target_full_paths) == 2
        assert target_full_path0 == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/something.py', sp_dir),
                     target_python_version)))
        assert target_full_path1 == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/another.py', sp_dir),
                     target_python_version)))

        # make .py file in prefix that will be compiled
        mkdir_p(dirname(source_full_path0))
        with open(source_full_path0, 'w') as fh:
            fh.write("value = 42\n")
        mkdir_p(dirname(source_full_path1))
        with open(source_full_path1, 'w') as fh:
            fh.write("value = 43\n")

        # symlink the current python
        python_full_path = join(self.prefix, get_python_short_path(target_python_version))
        mkdir_p(dirname(python_full_path))
        create_link(sys.executable, python_full_path, LinkType.softlink)

        axn.execute()
        assert isfile(target_full_path0)
        assert isfile(target_full_path1)

        # remove the source .py file so we're sure we're importing the pyc file below
        rm_rf(source_full_path0)
        assert not isfile(source_full_path0)
        rm_rf(source_full_path1)
        assert not isfile(source_full_path1)

        imported_pyc_file = load_python_file(target_full_path0)
        assert imported_pyc_file.value == 42
        imported_pyc_file = load_python_file(target_full_path1)
        assert imported_pyc_file.value == 43

        axn.reverse()
        assert not isfile(target_full_path0)
        assert not isfile(target_full_path1)