Exemple #1
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)
    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)
Exemple #3
0
    def test_noarch_python_package_without_entry_points(self):
        # regression test for #4546
        with make_temp_env("-c conda-test itsdangerous") as prefix:
            py_ver = get_python_version_for_prefix(prefix)
            sp_dir = get_python_site_packages_short_path(py_ver)
            py_file = sp_dir + "/itsdangerous.py"
            pyc_file = pyc_path(py_file, py_ver)
            assert isfile(join(prefix, py_file))
            assert isfile(join(prefix, pyc_file))

            run_command(Commands.REMOVE, prefix, "itsdangerous")

            assert not isfile(join(prefix, py_file))
            assert not isfile(join(prefix, pyc_file))
Exemple #4
0
    def test_noarch_python_package_without_entry_points(self):
        # regression test for #4546
        with make_temp_env("-c conda-test itsdangerous") as prefix:
            py_ver = get_python_version_for_prefix(prefix)
            sp_dir = get_python_site_packages_short_path(py_ver)
            py_file = sp_dir + "/itsdangerous.py"
            pyc_file = pyc_path(py_file, py_ver)
            assert isfile(join(prefix, py_file))
            assert isfile(join(prefix, pyc_file))

            run_command(Commands.REMOVE, prefix, "itsdangerous")

            assert not isfile(join(prefix, py_file))
            assert not isfile(join(prefix, pyc_file))
Exemple #5
0
    def test_noarch_package(self):
        with make_temp_env("-c scastellarin flask") as prefix:
            py_ver = get_python_version_for_prefix(prefix)
            sp_dir = get_python_site_packages_short_path(py_ver)
            py_file = sp_dir + "/flask/__init__.py"
            pyc_file = pyc_path(py_file, py_ver)
            assert isfile(join(prefix, py_file))
            assert isfile(join(prefix, pyc_file))
            exe_path = join(prefix, get_bin_directory_short_path(), 'flask')
            if on_win:
                exe_path += ".exe"
            assert isfile(exe_path)

            run_command(Commands.REMOVE, prefix, "flask")

            assert not isfile(join(prefix, py_file))
            assert not isfile(join(prefix, pyc_file))
            assert not isfile(exe_path)
Exemple #6
0
    def test_noarch_python_package_with_entry_points(self):
        with make_temp_env("-c conda-test flask") as prefix:
            py_ver = get_python_version_for_prefix(prefix)
            sp_dir = get_python_site_packages_short_path(py_ver)
            py_file = sp_dir + "/flask/__init__.py"
            pyc_file = pyc_path(py_file, py_ver)
            assert isfile(join(prefix, py_file))
            assert isfile(join(prefix, pyc_file))
            exe_path = join(prefix, get_bin_directory_short_path(), 'flask')
            if on_win:
                exe_path += ".exe"
            assert isfile(exe_path)

            run_command(Commands.REMOVE, prefix, "flask")

            assert not isfile(join(prefix, py_file))
            assert not isfile(join(prefix, pyc_file))
            assert not isfile(exe_path)
    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)