Skip to content

Commit

Permalink
Drop dependency on Setuptools
Browse files Browse the repository at this point in the history
Instead of relying on `setuptools` to get functionality from
`pkg_resources` (which is slowly being refactored away), leverage
`packaging` for the functionality used by Conda-Build.
  • Loading branch information
jakirkham authored and jezdez committed Jan 20, 2023
1 parent c752fc4 commit 86a176f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions conda_build/skeletons/cpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import codecs
import hashlib
from pkg_resources import parse_version
from packaging.version import Version
from glob import glob
import gzip
import json
Expand Down Expand Up @@ -231,7 +231,7 @@ def get_build_dependencies_from_src_archive(package_url, sha256, src_cache):


def loose_version(ver):
return str(parse_version(str(ver)))
return str(Version(str(ver)))


def get_cpan_api_url(url, colons):
Expand Down Expand Up @@ -438,7 +438,7 @@ def skeletonize(packages, output_dir=".", version=None,
release_data = latest_release_data
else:
release_data = get_release_info(meta_cpan_url, cache_dir, core_modules, package,
parse_version(version))
Version(version))

# Check if recipe directory already exists
dir_path = join(output_dir, packagename, release_data['version'])
Expand Down Expand Up @@ -566,7 +566,7 @@ def is_core_version(core_version, version):
if core_version is None:
return False
elif core_version is not None and ((version in [None, '']) or
(core_version >= parse_version(version))):
(core_version >= Version(version))):
return True
else:
return False
Expand Down Expand Up @@ -619,7 +619,7 @@ def latest_pkg_version(pkg):
except:
pkg_list = None
if pkg_list:
pkg_version = parse_version(pkg_list[-1].version)
pkg_version = Version(pkg_list[-1].version)
else:
pkg_version = None
return pkg_version
Expand Down Expand Up @@ -707,7 +707,7 @@ def deps_for_package(package, release_data, output_dir, cache_dir,
# There is a dep version and a pkg_version ... why?
if dep_dict['version'] in {'', 'undef'}:
dep_dict['version'] = '0'
dep_version = parse_version(dep_dict['version'])
dep_version = Version(dep_dict['version'])

# Make sure specified version is valid
# TODO def valid_release_info
Expand All @@ -718,7 +718,7 @@ def deps_for_package(package, release_data, output_dir, cache_dir,
'dependency for %s, %s, is not available on MetaCPAN, ' +
'so we are just assuming the latest version is ' +
'okay.') % (orig_dist, package, str(dep_version)))
dep_version = parse_version('0')
dep_version = Version('0')

# Add version number to dependency, if it's newer than latest
# we have package for.
Expand Down Expand Up @@ -991,12 +991,12 @@ def get_release_info(cpan_url, cache_dir, core_modules, package, version):
if version is not None:
version_str = str(version)
rel_version = str(rel_dict['version'])
loose_str = str(parse_version(version_str))
loose_str = str(Version(version_str))

try:
version_mismatch = (version is not None) and (
loose_version('0') != loose_version(version_str) and
parse_version(rel_version) != loose_version(version_str))
Version(rel_version) != loose_version(version_str))
# print(version_mismatch)
except Exception as e:
print('We have some strange version mismatches. Please investigate.')
Expand Down
4 changes: 2 additions & 2 deletions conda_build/skeletons/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from os import makedirs, listdir, getcwd, chdir
from os.path import join, isdir, exists, isfile, abspath

from pkg_resources import parse_version
from packaging.version import Version
import re
from shutil import copy2
import subprocess
Expand Down Expand Up @@ -277,7 +277,7 @@ def skeletonize(packages, output_dir=".", version=None, recursive=False,

pypi_data = pypi_resp.json()

versions = sorted(pypi_data["releases"].keys(), key=parse_version)
versions = sorted(pypi_data["releases"].keys(), key=Version)

if version_compare:
version_compare(versions)
Expand Down
6 changes: 3 additions & 3 deletions conda_build/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import lru_cache
from itertools import product
import os.path
from pkg_resources import parse_version
from packaging.version import Version
import re
import sys

Expand Down Expand Up @@ -87,9 +87,9 @@
def _get_default_compilers(platform, py_ver):
compilers = DEFAULT_COMPILERS[platform].copy()
if platform == 'win':
if parse_version(py_ver) >= parse_version('3.5'):
if Version(py_ver) >= Version('3.5'):
py_ver = '3.5'
elif parse_version(py_ver) <= parse_version('3.2'):
elif Version(py_ver) <= Version('3.2'):
py_ver = '2.7'
compilers['c'] = compilers['c'][py_ver]
compilers['cxx'] = compilers['cxx'][py_ver]
Expand Down
2 changes: 1 addition & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ requirements:
- filelock
- futures # [py<3]
- jinja2
- packaging
- patchelf # [linux]
- patch >=2.6 # [not win]
- m2-patch >=2.6 # [win]
Expand All @@ -44,7 +45,6 @@ requirements:
- pyyaml
- requests
- scandir # [py<34]
- setuptools
- six
- glob2 >=0.6
- pytz
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"psutil",
"six",
"libarchive-c",
"setuptools",
"packaging",
# "conda-package-handling", # remove comment once released on PyPI
"glob2",
]
Expand Down
10 changes: 5 additions & 5 deletions tests/test_api_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import subprocess
import sys

from pkg_resources import parse_version
from packaging.version import Version
import pytest

from conda_build.skeletons.pypi import get_package_metadata, \
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_pypi_version_sorting(testing_workdir, testing_config):
# any effect.
api.skeletonize(packages='impyla', repo='pypi', config=testing_config)
m = api.render('impyla')[0][0]
assert parse_version(m.version()) >= parse_version("0.13.8")
assert Version(m.version()) >= Version("0.13.8")


def test_list_skeletons():
Expand All @@ -359,7 +359,7 @@ def test_pypi_with_version_arg(testing_workdir):
# regression test for https://github.com/conda/conda-build/issues/1442
api.skeletonize('PrettyTable', 'pypi', version='0.7.2')
m = api.render('prettytable')[0][0]
assert parse_version(m.version()) == parse_version("0.7.2")
assert Version(m.version()) == Version("0.7.2")


@pytest.mark.slow
Expand All @@ -373,7 +373,7 @@ def test_pypi_with_extra_specs(testing_workdir, testing_config):
api.skeletonize('bigfile', 'pypi', extra_specs=extra_specs,
version='0.1.24', python="3.6", config=testing_config)
m = api.render('bigfile')[0][0]
assert parse_version(m.version()) == parse_version("0.1.24")
assert Version(m.version()) == Version("0.1.24")
assert any('cython' in req for req in m.meta['requirements']['host'])
assert any('mpi4py' in req for req in m.meta['requirements']['host'])

Expand All @@ -389,7 +389,7 @@ def test_pypi_with_version_inconsistency(testing_workdir, testing_config):
api.skeletonize('mpi4py_test', 'pypi', extra_specs=extra_specs,
version='0.0.10', python="3.6", config=testing_config)
m = api.render('mpi4py_test')[0][0]
assert parse_version(m.version()) == parse_version("0.0.10")
assert Version(m.version()) == Version("0.0.10")


def test_pypi_with_basic_environment_markers(testing_workdir):
Expand Down

0 comments on commit 86a176f

Please sign in to comment.