From 2160d59f52fcaf17c284d5f1d7a0b59305f98284 Mon Sep 17 00:00:00 2001 From: Facundo Batista Date: Fri, 24 May 2024 22:24:29 -0300 Subject: [PATCH] Stopped using pkg_resources, as it's deprecated. --- README.rst | 15 +------- fades/cache.py | 36 ++++++++++-------- fades/envbuilder.py | 4 +- fades/helpers.py | 37 +++++++++--------- fades/parsing.py | 46 ++++++++++++++++++----- pkg/debian/control | 2 +- pkg/snap/snapcraft.yaml | 3 +- requirements.txt | 1 + setup.py | 8 ++-- tests/__init__.py | 8 ++-- tests/test_cache/__init__.py | 6 +-- tests/test_envbuilder.py | 8 ++-- tests/test_helpers.py | 27 ++++++++----- tests/test_infra.py | 9 ++++- tests/test_main.py | 33 ++++++++-------- tests/test_parsing/test_vcs_dependency.py | 6 +-- 16 files changed, 137 insertions(+), 112 deletions(-) diff --git a/README.rst b/README.rst index 9c94541..cea9e95 100644 --- a/README.rst +++ b/README.rst @@ -596,20 +596,7 @@ Else, keep reading to know how to install the dependencies first, and Dependencies ------------ -Besides needing Python 3.3 or greater, fades depends also on the -``pkg_resources`` package, that comes in with ``setuptools``. -It's installed almost everywhere, but in any case, -you can install it in Ubuntu/Debian with:: - - apt-get install python3-setuptools - -And on Arch Linux with:: - - pacman -S python-setuptools - -It also depends on ``python-xdg`` package. This package should be -installed on any GNU/Linux OS wiht a freedesktop.org GUI. However it -is an **optional** dependency. +Besides needing Python 3.3 or greater, fades depends on the ``python-xdg`` package. This package should be installed on any GNU/Linux OS wiht a freedesktop.org GUI. However it is an **optional** dependency. You can install it in Ubuntu/Debian with:: diff --git a/fades/cache.py b/fades/cache.py index 45add13..efde6a1 100644 --- a/fades/cache.py +++ b/fades/cache.py @@ -1,4 +1,4 @@ -# Copyright 2015-2016 Facundo Batista, Nicolás Demarchi +# Copyright 2015-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General @@ -23,11 +23,8 @@ import time from fades import REPO_VCS - -from pkg_resources import Distribution - from fades.multiplatform import filelock -from fades.parsing import VCSDependency +from fades.parsing import VCSDependency, NameVerDependency logger = logging.getLogger(__name__) @@ -44,9 +41,10 @@ def __init__(self, filepath): def _venv_match(self, installed, requirements): """Return True if what is installed satisfies the requirements. - This method has multiple exit-points, but only for False (because + This method has multiple exit-points, but only for None (because if *anything* is not satisified, the venv is no good). Only after - all was checked, and it didn't exit, the venv is ok so return True. + all was checked, and it didn't exit, the venv is ok and it so + returns the satisfying dependencies. """ if not requirements: # special case for no requirements, where we can't actually @@ -61,22 +59,28 @@ def _venv_match(self, installed, requirements): return None if repo == REPO_VCS: - inst_deps = {VCSDependency(url) for url in installed[repo].keys()} + inst_namevers = {(url, None) for url in installed[repo].keys()} else: - inst_deps = {Distribution(project_name=dep, version=ver) - for (dep, ver) in installed[repo].items()} + inst_namevers = {(dep, ver) for (dep, ver) in installed[repo].items()} + for req in req_deps: - for inst in inst_deps: - if inst in req: - useful_inst.add(inst) + for inst_name, inst_ver in inst_namevers: + if req.name == inst_name and req.specifier.contains(inst_ver): + useful_inst.add((inst_name, inst_ver)) break else: # nothing installed satisfied that requirement return None # assure *all* that is installed is useful for the requirements - if useful_inst == inst_deps: - satisfying_deps.extend(inst_deps) + if useful_inst == inst_namevers: + inst_reqs = set() + for name, ver in inst_namevers: + if ver is None: + inst_reqs.add(VCSDependency(name)) + else: + inst_reqs.add(NameVerDependency(name, ver)) + satisfying_deps.extend(inst_reqs) else: return None @@ -106,7 +110,7 @@ def _select_better_fit(self, matching_venvs): # position of the winner scores = [0] * len(venvs) for dependencies in zip(*to_compare): - if not isinstance(dependencies[0], Distribution): + if not isinstance(dependencies[0], NameVerDependency): # only distribution URLs can be compared continue diff --git a/fades/envbuilder.py b/fades/envbuilder.py index 2c12388..57a19aa 100644 --- a/fades/envbuilder.py +++ b/fades/envbuilder.py @@ -1,4 +1,4 @@ -# Copyright 2014-2016 Facundo Batista, Nicolás Demarchi +# Copyright 2014-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -169,7 +169,7 @@ def create_venv(requested_deps, interpreter, is_current, options, pip_options, a # always store the installed dependency, as in the future we'll select the venv # based on what is installed, not what used requested (remember that user may # request >, >=, etc!) - project = dependency.project_name + project = dependency.name version = mgr.get_version(project) installed[repo][project] = version diff --git a/fades/helpers.py b/fades/helpers.py index 941ea09..035b4ba 100644 --- a/fades/helpers.py +++ b/fades/helpers.py @@ -1,4 +1,4 @@ -# Copyright 2014-2015 Facundo Batista, Nicolás Demarchi +# Copyright 2014-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -22,11 +22,11 @@ import logging import subprocess import tempfile - from urllib import request, parse from urllib.error import HTTPError -import pkg_resources +from packaging.requirements import Requirement +from packaging.version import Version from fades import FadesError, HTTP_STATUS_NOT_FOUND, HTTP_STATUS_OK, _version @@ -183,32 +183,32 @@ def check_pypi_updates(dependencies): for dependency in dependencies.get('pypi', []): # get latest version from PyPI api try: - latest_version = get_latest_version_number(dependency.project_name) + latest_version = Version(get_latest_version_number(dependency.name)) except Exception as error: logger.warning("--check-updates command will be aborted. Error: %s", error) return dependencies # get required version - required_version = None - if dependency.specs: - _, required_version = dependency.specs[0] - if required_version: + if dependency.specifier: + spec = list(dependency.specifier)[0] + required_version = Version(spec.version) + dependencies_up_to_date.append(dependency) if latest_version > required_version: logger.info("There is a new version of %s: %s", - dependency.project_name, latest_version) + dependency.name, latest_version) elif latest_version < required_version: logger.warning("The requested version for %s is greater " "than latest found in PyPI: %s", - dependency.project_name, latest_version) + dependency.name, latest_version) else: logger.info("The requested version for %s is the latest one in PyPI: %s", - dependency.project_name, latest_version) + dependency.name, latest_version) else: - project_name_plus = "{}=={}".format(dependency.project_name, latest_version) - dependencies_up_to_date.append(pkg_resources.Requirement.parse(project_name_plus)) + name_plus = "{}=={}".format(dependency.name, latest_version) + dependencies_up_to_date.append(Requirement(name_plus)) logger.info("The latest version of %r is %s and will use it.", - dependency.project_name, latest_version) + dependency.name, latest_version) dependencies["pypi"] = dependencies_up_to_date return dependencies @@ -216,11 +216,12 @@ def check_pypi_updates(dependencies): def _pypi_head_package(dependency): """Hit pypi with a http HEAD to check if pkg_name exists.""" - if dependency.specs: - _, version = dependency.specs[0] - url = BASE_PYPI_URL_WITH_VERSION.format(name=dependency.project_name, version=version) + if dependency.specifier: + spec = list(dependency.specifier)[0] + version = spec.version + url = BASE_PYPI_URL_WITH_VERSION.format(name=dependency.name, version=version) else: - url = BASE_PYPI_URL.format(name=dependency.project_name) + url = BASE_PYPI_URL.format(name=dependency.name) logger.debug("Doing HEAD requests against %s", url) req = request.Request(url, method='HEAD') try: diff --git a/fades/parsing.py b/fades/parsing.py index 230f576..b0c1f64 100644 --- a/fades/parsing.py +++ b/fades/parsing.py @@ -1,4 +1,4 @@ -# Copyright 2014-2019 Facundo Batista, Nicolás Demarchi +# Copyright 2014-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -20,7 +20,8 @@ import os import re -from pkg_resources import parse_requirements +from packaging.requirements import Requirement +from packaging.version import Version from fades import REPO_PYPI, REPO_VCS from fades.pkgnamesdb import MODULE_TO_PACKAGE @@ -28,6 +29,14 @@ logger = logging.getLogger(__name__) +class _VCSSpecifier: + """A simple specifier that works with VCSDependency.""" + + def contains(self, other): + """VCS dependency does not handle versions.""" + return other is None + + class VCSDependency: """A dependency object for VCS urls (git, bzr, etc.). @@ -39,7 +48,8 @@ class VCSDependency: def __init__(self, url): """Init.""" - self.url = url + self.url = self.name = self.project_name = self.version = url + self.specifier = _VCSSpecifier() def __str__(self): """Return the URL as this is the interface to get what pip will use.""" @@ -49,10 +59,6 @@ def __repr__(self): """Repr.""" return "".format(self.url) - def __contains__(self, other): - """Tell if requirement is satisfied.""" - return other.url == self.url - def __eq__(self, other): """Tell if one VCSDependency is equal to other.""" if not isinstance(other, VCSDependency): @@ -64,6 +70,24 @@ def __hash__(self): return hash(self.url) +class NameVerDependency: + """A dependency indicated by name and version.""" + + def __init__(self, name, version): + self.name = name + self.version = Version(version) + + def __eq__(self, other): + return self.name == other.name and self.version == other.version + + def __hash__(self): + return hash((self.name, self.version)) + + def __lt__(self, other): + assert not isinstance(self.version, str) + return (self.name, self.version) < (other.name, other.version) + + def parse_fade_requirement(text): """Return a requirement and repo from the given text, already parsed and converted.""" text = text.strip() @@ -85,7 +109,7 @@ def parse_fade_requirement(text): if repo == REPO_VCS: dependency = VCSDependency(requirement) else: - dependency = list(parse_requirements(requirement))[0] + dependency = Requirement(requirement) return repo, dependency @@ -147,7 +171,7 @@ def _parse_content(fh): else: package = module - # To match the "safe" name that pkg_resources creates: + # To match the "safe" name package = package.replace('_', '-') # get the fades info after 'fades' mark, if any @@ -218,7 +242,9 @@ def _parse_requirement(iterable): deps = {} for line in iterable: line = line.strip() - if not line or line[0] == '#': + if "#" in line: + line = line[:line.index("#")] + if not line: continue parsed_req = parse_fade_requirement(line) diff --git a/pkg/debian/control b/pkg/debian/control index 41cd073..deee0fd 100644 --- a/pkg/debian/control +++ b/pkg/debian/control @@ -4,7 +4,7 @@ Priority: extra Build-Depends: debhelper (>= 9), dh-python, dh-translations | dh-python, - python3-setuptools, + python3-packaging, python3-all (>= 3.4), python3-xdg Maintainer: Facundo Batista diff --git a/pkg/snap/snapcraft.yaml b/pkg/snap/snapcraft.yaml index 28017b6..f0dd6bc 100644 --- a/pkg/snap/snapcraft.yaml +++ b/pkg/snap/snapcraft.yaml @@ -40,9 +40,8 @@ parts: - python3.8-minimal - python3-distutils - python3-minimal - - python3-pkg-resources - python3-pip - - python3-setuptools + - python3-packaging - python3-venv - python3-wheel diff --git a/requirements.txt b/requirements.txt index 85b3b9e..dc2009e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ flake8 logassert +packaging pydocstyle pytest pyuca diff --git a/setup.py b/setup.py index c1d8249..bd85897 100755 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2014-2017 Facundo Batista, Nicolás Demarchi +# Copyright 2014-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -22,8 +22,6 @@ python3 python3-xdg (optional) - python3-pkg-resources - python3-setuptools """ import os @@ -53,7 +51,7 @@ def get_version(): """Retrieves package version from the file.""" with open('fades/_version.py') as fh: - m = re.search("\(([^']*)\)", fh.read()) + m = re.search(r"\(([^']*)\)", fh.read()) if m is None: raise ValueError("Unrecognized version in 'fades/_version.py'") return m.groups()[0].replace(', ', '.') @@ -127,7 +125,7 @@ def finalize_options(self): extras_require={ 'pyxdg': 'pyxdg', 'virtualenv': 'virtualenv', - 'setuptools': 'setuptools', + 'packaging': 'packaging', }, # https://pypi.python.org/pypi?%3Aaction=list_classifiers diff --git a/tests/__init__.py b/tests/__init__.py index f139766..da2b531 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2017-2019 Facundo Batista, Nicolás Demarchi +# Copyright 2017-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -19,7 +19,7 @@ import os from tempfile import mkstemp -from pkg_resources import parse_requirements +from packaging.requirements import Requirement def get_tempfile(testcase): @@ -59,5 +59,5 @@ def get_python_filepaths(roots): def get_reqs(*items): - """Transform text requirements into pkg_resources objects.""" - return list(parse_requirements(items)) + """Transform text requirements into Requirement objects.""" + return [Requirement(item) for item in items] diff --git a/tests/test_cache/__init__.py b/tests/test_cache/__init__.py index e7f0994..48cdde7 100644 --- a/tests/test_cache/__init__.py +++ b/tests/test_cache/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2015-2019 Facundo Batista, Nicolás Demarchi +# Copyright 2015-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -16,9 +16,9 @@ """Helpers for the Cache tests collection.""" -from pkg_resources import Distribution +from fades.parsing import NameVerDependency def get_distrib(*dep_ver_pairs): """Build some Distributions with indicated info.""" - return [Distribution(project_name=dep, version=ver) for dep, ver in dep_ver_pairs] + return [NameVerDependency(dep, ver) for dep, ver in dep_ver_pairs] diff --git a/tests/test_envbuilder.py b/tests/test_envbuilder.py index 393c6d3..e517fcf 100644 --- a/tests/test_envbuilder.py +++ b/tests/test_envbuilder.py @@ -1,4 +1,4 @@ -# Copyright 2015-2016 Facundo Batista, Nicolás Demarchi +# Copyright 2015-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -23,7 +23,7 @@ from datetime import datetime, timedelta from unittest.mock import Mock, patch, call -from pkg_resources import parse_requirements +from packaging.requirements import Requirement import logassert @@ -33,8 +33,8 @@ def get_req(text): - """Transform a text requirement into the pkg_resources object.""" - return list(parse_requirements(text))[0] + """Transform a text requirement into the Requirement object.""" + return Requirement(text) class EnvCreationTestCase(unittest.TestCase): diff --git a/tests/test_helpers.py b/tests/test_helpers.py index d4232d8..be54f0a 100644 --- a/tests/test_helpers.py +++ b/tests/test_helpers.py @@ -1,4 +1,4 @@ -# Copyright 2015 Facundo Batista, Nicolás Demarchi +# Copyright 2015-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -183,9 +183,6 @@ class CheckPyPIUpdatesTestCase(unittest.TestCase): def setUp(self): logassert.setup(self, 'fades.helpers') - self.deps = parsing.parse_manual(["django==1.7.5", "requests"]) - self.deps_higher = parsing.parse_manual(["django==100.1.1"]) - self.deps_same_than_latest = parsing.parse_manual(["django==1.9"]) def test_check_pypi_updates_with_and_without_version(self): with patch('urllib.request.urlopen') as mock_urlopen: @@ -193,29 +190,39 @@ def test_check_pypi_updates_with_and_without_version(self): mock_http_response.read.side_effect = [b'{"info": {"version": "1.9"}}', b'{"info": {"version": "2.1"}}'] mock_urlopen.return_value = mock_http_response - dependencies = helpers.check_pypi_updates(self.deps) + requested = parsing.parse_manual(["django==1.7.5", "requests"]) + dependencies = helpers.check_pypi_updates(requested) dep_django = dependencies['pypi'][0] dep_request = dependencies['pypi'][1] self.assertLoggedInfo('There is a new version of django: 1.9') - self.assertEqual(dep_request.specs, [('==', '2.1')]) - self.assertEqual(dep_django.specs, [('==', '1.7.5')]) + self.assertEqual(str(dep_request.specifier), "==2.1") + self.assertEqual(str(dep_django.specifier), "==1.7.5") self.assertLoggedInfo("The latest version of 'requests' is 2.1 and will use it.") - def test_check_pypi_updates_with_a_higher_version_of_a_package(self): + def test_check_pypi_updates_with_a_higher_version_of_a_package_simple(self): with patch('urllib.request.urlopen') as mock_urlopen: with patch('http.client.HTTPResponse') as mock_http_response: mock_http_response.read.side_effect = [b'{"info": {"version": "1.9"}}'] mock_urlopen.return_value = mock_http_response - helpers.check_pypi_updates(self.deps_higher) + helpers.check_pypi_updates(parsing.parse_manual(["django==100.1.1"])) self.assertLoggedWarning( "The requested version for django is greater than latest found in PyPI: 1.9") + def test_check_pypi_updates_with_a_higher_version_of_a_package_real_order(self): + with patch('urllib.request.urlopen') as mock_urlopen: + with patch('http.client.HTTPResponse') as mock_http_response: + mock_http_response.read.side_effect = [b'{"info": {"version": "2.9"}}'] + mock_urlopen.return_value = mock_http_response + helpers.check_pypi_updates(parsing.parse_manual(["django==10.1"])) + self.assertLoggedWarning( + "The requested version for django is greater than latest found in PyPI: 2.9") + def test_check_pypi_updates_with_the_latest_version_of_a_package(self): with patch('urllib.request.urlopen') as mock_urlopen: with patch('http.client.HTTPResponse') as mock_http_response: mock_http_response.read.side_effect = [b'{"info": {"version": "1.9"}}'] mock_urlopen.return_value = mock_http_response - helpers.check_pypi_updates(self.deps_same_than_latest) + helpers.check_pypi_updates(parsing.parse_manual(["django==1.9"])) self.assertLoggedInfo( "The requested version for django is the latest one in PyPI: 1.9") diff --git a/tests/test_infra.py b/tests/test_infra.py index f4a3d5b..a91edd7 100644 --- a/tests/test_infra.py +++ b/tests/test_infra.py @@ -1,4 +1,4 @@ -# Copyright 2017-2022 Facundo Batista, Nicolás Demarchi +# Copyright 2017-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -49,7 +49,12 @@ def test_flake8_pytest(capsys): def test_pep257_pytest(): python_filepaths = get_python_filepaths(PEP257_ROOTS) - result = list(pydocstyle.check(python_filepaths)) + to_ignore = { + "D105", # Missing docstring in magic method + "D107", # Missing docstring in __init__ + } + to_include = pydocstyle.violations.conventions.pep257 - to_ignore + result = list(pydocstyle.check(python_filepaths, select=to_include)) assert len(result) == 0, "There are issues!\n" + '\n'.join(map(str, result)) diff --git a/tests/test_main.py b/tests/test_main.py index 1da364c..ff890c7 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,4 +1,4 @@ -# Copyright 2015-2019 Facundo Batista, Nicolás Demarchi +# Copyright 2015-2024 Facundo Batista, Nicolás Demarchi # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License version 3, as published @@ -20,7 +20,7 @@ import unittest from unittest.mock import patch -from pkg_resources import Requirement +from packaging.requirements import Requirement from fades import VERSION, FadesError, __version__, main, parsing, REPO_PYPI, REPO_VCS from tests import create_tempfile @@ -53,7 +53,7 @@ def test_needs_ipython(self): d = main.consolidate_dependencies(needs_ipython=True, child_program=None, requirement_files=None, manual_dependencies=None) - self.assertDictEqual(d, {'pypi': {Requirement.parse('ipython')}}) + self.assertDictEqual(d, {'pypi': {Requirement('ipython')}}) def test_child_program(self): child_program = 'tests/test_files/req_module.py' @@ -61,7 +61,7 @@ def test_child_program(self): d = main.consolidate_dependencies(needs_ipython=False, child_program=child_program, requirement_files=None, manual_dependencies=None) - self.assertDictEqual(d, {'pypi': {Requirement.parse('foo'), Requirement.parse('bar')}}) + self.assertDictEqual(d, {'pypi': {Requirement('foo'), Requirement('bar')}}) def test_requirement_files(self): requirement_files = [create_tempfile(self, ['dep'])] @@ -70,7 +70,7 @@ def test_requirement_files(self): requirement_files=requirement_files, manual_dependencies=None) - self.assertDictEqual(d, {'pypi': {Requirement.parse('dep')}}) + self.assertDictEqual(d, {'pypi': {Requirement('dep')}}) def test_manual_dependencies(self): manual_dependencies = ['dep'] @@ -79,7 +79,7 @@ def test_manual_dependencies(self): requirement_files=None, manual_dependencies=manual_dependencies) - self.assertDictEqual(d, {'pypi': {Requirement.parse('dep')}}) + self.assertDictEqual(d, {'pypi': {Requirement('dep')}}) class DepsMergingTestCase(unittest.TestCase): @@ -94,7 +94,7 @@ def test_two_different(self): manual_dependencies=manual_dependencies) self.assertEqual(d, { - 'pypi': {Requirement.parse('1'), Requirement.parse('2')}, + 'pypi': {Requirement('1'), Requirement('2')}, 'vcs': {parsing.VCSDependency('3'), parsing.VCSDependency('4')} }) @@ -107,8 +107,7 @@ def test_two_same_repo(self): manual_dependencies=manual_dependencies) self.assertDictEqual(d, { - 'pypi': {Requirement.parse('1'), Requirement.parse('2'), Requirement.parse('3'), - Requirement.parse('4')} + 'pypi': {Requirement('1'), Requirement('2'), Requirement('3'), Requirement('4')} }) def test_complex_case(self): @@ -121,7 +120,7 @@ def test_complex_case(self): manual_dependencies=manual_dependencies) self.assertEqual(d, { - 'pypi': {Requirement.parse('1'), Requirement.parse('2'), Requirement.parse('3')}, + 'pypi': {Requirement('1'), Requirement('2'), Requirement('3')}, 'vcs': {parsing.VCSDependency('5'), parsing.VCSDependency('4'), parsing.VCSDependency('6')} }) @@ -135,7 +134,7 @@ def test_one_duplicated(self): manual_dependencies=manual_dependencies) self.assertDictEqual(d, { - 'pypi': {Requirement.parse('2')} + 'pypi': {Requirement('2')} }) def test_two_different_with_dups(self): @@ -147,7 +146,7 @@ def test_two_different_with_dups(self): manual_dependencies=manual_dependencies) self.assertEqual(d, { - 'pypi': {Requirement.parse('1'), Requirement.parse('2')}, + 'pypi': {Requirement('1'), Requirement('2')}, 'vcs': {parsing.VCSDependency('1'), parsing.VCSDependency('2'), parsing.VCSDependency('3'), parsing.VCSDependency('4')} }) @@ -250,7 +249,7 @@ def _autoimport_safe_call(*args, **kwargs): def test_autoimport_simple(): """Simplest autoimport call.""" dependencies = { - REPO_PYPI: {Requirement.parse('mymod')}, + REPO_PYPI: {Requirement('mymod')}, } content = _autoimport_safe_call(dependencies, is_ipython=False) @@ -261,7 +260,7 @@ def test_autoimport_simple(): def test_autoimport_several_dependencies(): """Indicate several dependencies.""" dependencies = { - REPO_PYPI: {Requirement.parse('mymod1'), Requirement.parse('mymod2')}, + REPO_PYPI: {Requirement('mymod1'), Requirement('mymod2')}, } content = _autoimport_safe_call(dependencies, is_ipython=False) @@ -274,8 +273,8 @@ def test_autoimport_including_ipython(): """Call with ipython modifier.""" dependencies = { REPO_PYPI: { - Requirement.parse('mymod'), - Requirement.parse('ipython'), # this one is automatically added + Requirement('mymod'), + Requirement('ipython'), # this one is automatically added }, } content = _autoimport_safe_call(dependencies, is_ipython=True) @@ -288,7 +287,7 @@ def test_autoimport_including_ipython(): def test_autoimport_no_pypi_dep(): """Case with no pypi dependencies.""" dependencies = { - REPO_PYPI: {Requirement.parse('my_pypi_mod')}, + REPO_PYPI: {Requirement('my_pypi_mod')}, REPO_VCS: {'my_vcs_dependency'}, } content = _autoimport_safe_call(dependencies, is_ipython=False) diff --git a/tests/test_parsing/test_vcs_dependency.py b/tests/test_parsing/test_vcs_dependency.py index 1960bb3..2668f83 100644 --- a/tests/test_parsing/test_vcs_dependency.py +++ b/tests/test_parsing/test_vcs_dependency.py @@ -11,10 +11,8 @@ def test_string_representation(): def test_contains(): """This is particularly tested because it's how fulfilling is tested.""" dep1 = parsing.VCSDependency("testurl") - dep2 = parsing.VCSDependency("testurl") - dep3 = parsing.VCSDependency("otherurl") - assert dep1 in dep2 - assert dep1 not in dep3 + assert dep1.specifier.contains(None) + assert not dep1.specifier.contains("123") def test_equality():