示例#1
0
def test_iterdir_non_recursive_tarball(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'sdist.tar.gz'),
        cache_path=Path(str(tmpdir)),
    )
    paths = [str(subpath) for subpath in path.iterdir(_recursive=False)]
    assert paths == ['dephell-0.2.0']
示例#2
0
def test_glob_dir(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'sdist.tar.gz'),
        cache_path=Path(str(tmpdir)),
    )
    paths = list(path.glob('dephell-*/'))
    assert len(paths) == 1
示例#3
0
def test_iterdir_non_recursive_with_dirs(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'graphviz-0.13.2.zip'),
        cache_path=Path(str(tmpdir)),
    )
    paths = [str(subpath) for subpath in path.iterdir(_recursive=False)]
    assert paths == ['graphviz-0.13.2']
示例#4
0
def test_iterdir_non_recursive(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'dnspython-1.16.0.zip'),
        cache_path=Path(str(tmpdir)),
    )
    paths = [str(subpath) for subpath in path.iterdir(_recursive=False)]
    assert paths == ['dnspython-1.16.0']
示例#5
0
def test_glob_dir(tmpdir):
    path = ArchivePath(
        archive_path=sdist_path,
        cache_path=Path(str(tmpdir)),
    )
    paths = list(path.glob('dephell-*/'))
    assert len(paths) == 1
示例#6
0
def test_glob_zip(tmpdir):
    path = ArchivePath(
        archive_path=wheel_path,
        cache_path=Path(str(tmpdir)),
    )
    paths = list(path.glob('*/__init__.py'))
    assert len(paths) == 1
    assert paths[0].member_path.as_posix() == 'dephell/__init__.py'
示例#7
0
def test_glob_tar(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'sdist.tar.gz'),
        cache_path=Path(str(tmpdir)),
    )
    paths = list(path.glob('*/setup.py'))
    assert len(paths) == 1
    assert paths[0].as_posix() == 'dephell-0.2.0/setup.py'
示例#8
0
def test_glob_zip(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'wheel.whl'),
        cache_path=Path(str(tmpdir)),
    )
    paths = list(path.glob('*/__init__.py'))
    assert len(paths) == 1
    assert paths[0].as_posix() == 'dephell/__init__.py'
示例#9
0
def test_glob(tmpdir):
    path = ArchivePath(
        archive_path=sdist_path,
        cache_path=Path(str(tmpdir)),
    )
    paths = list(path.glob('*/setup.py'))
    assert len(paths) == 1
    assert paths[0].member_path.as_posix() == 'dephell-0.2.0/setup.py'
示例#10
0
def test_iterdir_non_recursive_wheel(tmpdir):
    path = ArchivePath(
        archive_path=wheel_path,
        cache_path=Path(str(tmpdir)),
    )
    paths = [str(subpath) for subpath in path.iterdir(_recursive=False)]
    assert len(paths) == 2
    assert 'dephell' in paths
    assert 'dephell-0.2.0.dist-info' in paths
示例#11
0
def test_iterdir(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'sdist.tar.gz'),
        cache_path=Path(str(tmpdir)),
    )
    paths = [str(subpath) for subpath in path.iterdir(recursive=True)]

    for path in paths:
        assert paths.count(path) == 1, 'duplicate dir: ' + path
    assert 'dephell-0.2.0' in paths
示例#12
0
def test_iterdir_recursive_with_dirs(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'graphviz-0.13.2.zip'),
        cache_path=Path(str(tmpdir)),
    )
    paths = [str(subpath) for subpath in path.iterdir(_recursive=True)]

    assert 'graphviz-0.13.2' in paths
    assert str(Path('graphviz-0.13.2', 'setup.py')) in paths
    assert str(Path('graphviz-0.13.2', 'graphviz', '__init__.py')) in paths

    for path in paths:
        assert paths.count(path) == 1, 'duplicate dir: ' + path
示例#13
0
def test_iterdir_recursive_tarball(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'sdist.tar.gz'),
        cache_path=Path(str(tmpdir)),
    )
    paths = [str(subpath) for subpath in path.iterdir(_recursive=True)]

    assert 'dephell-0.2.0' in paths
    assert str(Path('dephell-0.2.0', 'setup.py')) in paths
    assert str(Path('dephell-0.2.0', 'dephell', '__init__.py')) in paths

    for path in paths:
        assert paths.count(path) == 1, 'duplicate dir: ' + path
示例#14
0
def test_iterdir_recursive_wheel(tmpdir):
    path = ArchivePath(
        archive_path=wheel_path,
        cache_path=Path(str(tmpdir)),
    )
    paths = [str(subpath) for subpath in path.iterdir(_recursive=True)]

    assert 'dephell' in paths
    assert str(Path('dephell', '__init__.py')) in paths
    assert 'dephell-0.2.0.dist-info' in paths
    assert str(Path('dephell-0.2.0.dist-info', 'WHEEL')) in paths

    for path in paths:
        assert paths.count(path) == 1, 'duplicate dir: ' + path
示例#15
0
def test_iterdir_recursive(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'dnspython-1.16.0.zip'),
        cache_path=Path(str(tmpdir)),
    )
    paths = [str(subpath) for subpath in path.iterdir(_recursive=True)]

    assert 'dnspython-1.16.0' in paths
    assert str(Path('dnspython-1.16.0', 'setup.py')) in paths
    assert str(Path('dnspython-1.16.0', 'dns', '__init__.py')) in paths
    assert str(Path('dnspython-1.16.0', 'dns', 'rdtypes')) in paths
    assert str(Path('dnspython-1.16.0', 'dns', 'rdtypes', 'ANY')) in paths

    for path in paths:
        assert paths.count(path) == 1, 'duplicate dir: ' + path
示例#16
0
def test_iterdir_subpath_non_recursive(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'sdist.tar.gz'),
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'dephell-0.2.0'
    paths = set(str(item) for item in subpath.iterdir(_recursive=False))
    assert paths == {
        'dephell',
        'dephell.egg-info',
        'PKG-INFO',
        'README.md',
        'setup.cfg',
        'setup.py',
    }
    subpath = subpath / 'dephell.egg-info'
    paths = set(str(item) for item in subpath.iterdir(_recursive=False))
    assert paths == {
        'dependency_links.txt',
        'entry_points.txt',
        'PKG-INFO',
        'requires.txt',
        'SOURCES.txt',
        'top_level.txt',
    }
示例#17
0
    def load(self, path) -> RootDependency:
        """Parse wheel

        Supported path format:
            + *.whl archive,
            + extracted *.whl (*.dist-info)
            + METADATA file from *.whl
        """
        path = Path(str(path))
        paths = None

        # if passed METADATA, just parse and return it
        if path.is_file() and path.suffix not in ('.whl', '.zip'):
            return self.loads(content=path.read_text())

        with TemporaryDirectory() as cache:
            if path.is_file() and path.suffix in ('.whl', '.zip'):
                path = ArchivePath(archive_path=path, cache_path=Path(cache))

            if not (path / 'METADATA').exists():
                paths = list(path.glob('*.dist-info/METADATA'))
                if not paths:
                    raise FileNotFoundError('cannot find METADATA in dir',
                                            str(path))
                # maybe it's possible, so we will have to process it
                if len(paths) > 1:
                    raise FileExistsError('too many METADATA in dir')
                path = paths[0].parent

            return self.load_dir(path)
示例#18
0
def test_iterdir_subpath_non_recursive_with_dirs(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'graphviz-0.13.2.zip'),
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'graphviz-0.13.2'
    paths = [str(item) for item in subpath.iterdir(_recursive=False)]
    assert 'graphviz' in paths
    assert 'graphviz.egg-info' in paths
    assert 'setup.py' in paths

    for path in paths:
        assert paths.count(path) == 1, 'duplicate dir: ' + path

    subpath = subpath / 'graphviz.egg-info'
    paths = [str(item) for item in subpath.iterdir(_recursive=False)]

    for path in paths:
        assert paths.count(path) == 1, 'duplicate dir: ' + path

    assert set(paths) == {
        'dependency_links.txt',
        'PKG-INFO',
        'requires.txt',
        'SOURCES.txt',
        'top_level.txt',
    }
示例#19
0
def test_open_zip(tmpdir):
    path = ArchivePath(
        archive_path=wheel_path,
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'dephell' / '__init__.py'
    with subpath.open() as stream:
        content = stream.read()
    assert 'from .controllers' in content
示例#20
0
def test_open_write(tmpdir):
    path = ArchivePath(
        archive_path=sdist_path,
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'dephell-0.2.0'
    with pytest.raises(NotImplementedError):
        with subpath.open('w'):
            pass
示例#21
0
def test_open_missing_cache_path(tmpdir):
    path = ArchivePath(
        archive_path=sdist_path,
        cache_path=Path(str(tmpdir), 'missing'),
    )
    subpath = path / 'dephell-0.2.0' / 'setup.py'
    with subpath.open() as stream:
        content = stream.read()
    assert 'from setuptools import' in content
示例#22
0
def test_open_tar_gz(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'sdist.tar.gz'),
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'dephell-0.2.0' / 'setup.py'
    with subpath.open() as stream:
        content = stream.read()
    assert 'from setuptools import' in content
示例#23
0
def test_is_file(tmpdir):
    path = ArchivePath(
        archive_path=wheel_path,
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'dephell' / '__init__.py'
    assert subpath.is_file() is True

    subpath = path / 'dephell'
    assert subpath.is_file() is False
示例#24
0
def test_exists(tmpdir):
    path = ArchivePath(
        archive_path=wheel_path,
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'dephell' / '__init__.py'
    assert subpath.exists() is True

    subpath = path / 'dephell' / 'some_junk.py'
    assert subpath.exists() is False
示例#25
0
def test_exists(tmpdir):
    path = ArchivePath(
        archive_path=sdist_path,
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'dephell-0.2.0' / 'setup.py'
    assert subpath.exists() is True

    subpath = path / 'dephell-0.2.0' / 'not-a-setup.py'
    assert subpath.exists() is False
示例#26
0
def test_is_dir(tmpdir):
    path = ArchivePath(
        archive_path=sdist_path,
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'dephell-0.2.0' / 'setup.py'
    assert subpath.is_dir() is False

    subpath = path / 'dephell-0.2.0'
    assert subpath.is_dir() is True
示例#27
0
def test_is_dir_explicit_entry(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'graphviz-0.13.2.zip'),
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'graphviz-0.13.2'
    assert subpath.is_dir() is True

    subpath = subpath / 'graphviz'
    assert subpath.exists() is True
    assert subpath.is_dir() is True

    subpath = subpath / '__init__.py'
    assert subpath.is_dir() is False
示例#28
0
def test_iterdir_subpath_recursive(tmpdir):
    path = ArchivePath(
        archive_path=Path('tests', 'requirements', 'dnspython-1.16.0.zip'),
        cache_path=Path(str(tmpdir)),
    )
    subpath = path / 'dnspython-1.16.0'
    paths = [str(item) for item in subpath.iterdir(_recursive=True)]

    assert 'setup.py' in paths
    assert Path('dnspython-1.16.0', 'dns') not in paths
    assert 'dns' in paths
    assert str(Path('dns', '__init__.py')) in paths

    for path in paths:
        assert paths.count(path) == 1, 'duplicate dir: ' + path
示例#29
0
    def load(self, path) -> RootDependency:
        path = Path(str(path))
        if path.suffix not in ('.zip', '.gz', '.tar', '.tgz', '.bz2'):
            raise ValueError('invalid file extension: ' + path.suffix)
        root = None
        converter = EggInfoConverter()
        with TemporaryDirectory() as cache:
            archive = ArchivePath(archive_path=path, cache_path=Path(cache))

            # read *.egg-info
            paths = chain(
                archive.glob('*.egg-info'),
                archive.glob('*/*.egg-info'),
                archive.glob('src/*.egg-info'),
                archive.glob('src/*/*.egg-info'),
            )
            paths = [
                path for path in paths if 'tests' not in path.member_path.parts
            ]
            if paths:
                root = converter.load_dir(*paths)
                root.readme = Readme.discover(path=archive)
                return root

            # read metainfo from PKG-INFO
            paths = archive.glob('**/PKG-INFO')
            paths = [path for path in paths if 'tests' not in path.parts]
            if paths:
                with paths[0].open('r') as stream:
                    root = converter.parse_info(content=stream.read())

            # read dependencies from requires.txt
            if root is None or not root.dependencies:
                paths = list(archive.glob('**/requires.txt'))
                paths = [path for path in paths if 'tests' not in path.parts]
                if paths:
                    with paths[0].open('r') as stream:
                        root = converter.parse_requires(content=stream.read(),
                                                        root=root)

        if root is None:
            msg = 'cannot find any metainfo in the archive: '
            raise FileNotFoundError(msg + str(archive.archive_path))
        return root
示例#30
0
def test_toplevel(tmpdir):
    path = ArchivePath(
        archive_path=sdist_path,
        cache_path=Path(str(tmpdir)),
    )
    assert path.is_dir()
    assert not path.is_file()
    assert path.exists()

    with pytest.raises(IsADirectoryError):
        with path.open():
            pass