Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated pkg_resources with packaging #726

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions binstar_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import defusedxml.ElementTree as ET
import requests
from pkg_resources import parse_version as pv
from tqdm import tqdm

from . import errors
Expand Down Expand Up @@ -186,15 +185,6 @@ def remove_authentication(self, auth_name=None, organization=None):

def _check_response(self, res, allowed=None):
allowed = [200] if allowed is None else allowed
api_version = res.headers.get('x-binstar-api-version', '0.2.1')
if pv(api_version) > pv(__version__):
# pylint: disable=implicit-str-concat
logger.warning(
'The api server is running the binstar-api version %s. you are using %s\n'
'Please update your client with pip install -U binstar or conda update binstar',
api_version,
__version__,
)

if not self._token_warning_sent and 'Conda-Token-Warning' in res.headers:
logger.warning('Token warning: %s', res.headers['Conda-Token-Warning'])
Expand Down
60 changes: 24 additions & 36 deletions binstar_client/inspect_package/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from email.parser import Parser
from os import path

import pkg_resources
from packaging.requirements import Requirement

from binstar_client import errors
from binstar_client.inspect_package.uitls import extract_first, pop_key
Expand Down Expand Up @@ -145,12 +145,19 @@ def python_version_check(filedata):


def parse_requirement(line, deps, extras, extra):
req = pkg_resources.Requirement.parse(line)
req.specs.sort(key=sort_ver)
parsed_req = Requirement(line)
name = parsed_req.name.lower()
specs = sorted(
(
(spec.operator, spec.version) for spec in parsed_req.specifier
),
key=sort_ver,
)

if extra:
extras[extra].append({'name': req.key, 'specs': req.specs or []})
extras[extra].append({'name': name, 'specs': specs})
else:
deps.append({'name': req.key, 'specs': req.specs or []})
deps.append({'name': name, 'specs': specs})

deps.sort(key=sort_key)
for extra_item in extras.values():
Expand Down Expand Up @@ -197,37 +204,18 @@ def parse_requires_txt(requires_txt):
def format_requirements(requires):
obj = []
for req in requires:
req = req.strip()

# Get environment marker
marker = None
if ';' in req:
req, marker = req.split(';', 1)
marker = marker.strip()
else:
marker = None

req_spec = req.split(' ', 1)
if len(req_spec) == 1:
# Note: req.lower() was introduced here to enforce the same parsing
# using metadata.json and METADATA
obj.append({'name': req.lower(), 'specs': []})
else:
req, spec = req_spec
spec = spec.strip()

if spec[0] == '(':
spec = spec[1:]

if spec[-1] == ')':
spec = spec[:-1]

req = pkg_resources.Requirement.parse('%s %s' % (req, spec))
req.specs.sort(key=sort_ver)
obj.append({
'name': req.key,
'specs': req.specs or [],
})
parsed_req = Requirement(req)
name = parsed_req.name.lower()
specs = sorted(
(
(spec.operator, spec.version) for spec in parsed_req.specifier
),
key=sort_ver,
)
obj.append({
'name': name,
'specs': specs,
})
return obj


Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,6 @@ redefining-builtins-modules=past.builtins,future.builtins,builtins,io
[tool:pytest]
addopts=--durations 10 --cov=binstar_client --cov-report term-missing
cache_dir=.cache/pytest
# Treat all warnings errors: https://til.simonwillison.net/pytest/treat-warnings-as-errors
filterwarnings =
error
Loading