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 May 31, 2022
1 parent 6369bd7 commit f0eef48
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion conda.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]
- pkginfo
- psutil
Expand All @@ -42,7 +43,6 @@ requirements:
- pyyaml
- requests
- scandir # [py<34]
- setuptools
- six
- glob2 >=0.6
- pytz
Expand Down
16 changes: 8 additions & 8 deletions conda_build/conda_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from os import lstat
from importlib import import_module

from pkg_resources import parse_version
from packaging.version import Version

from conda import __version__ as CONDA_VERSION

Expand All @@ -25,13 +25,13 @@ def try_exports(module, attr):
# no need to patch if it doesn't exist
pass

conda_43 = parse_version(CONDA_VERSION) >= parse_version("4.3.0a0")
conda_44 = parse_version(CONDA_VERSION) >= parse_version("4.4.0a0")
conda_45 = parse_version(CONDA_VERSION) >= parse_version("4.5.0a0")
conda_46 = parse_version(CONDA_VERSION) >= parse_version("4.6.0a0")
conda_47 = parse_version(CONDA_VERSION) >= parse_version("4.7.0a0")
conda_48 = parse_version(CONDA_VERSION) >= parse_version("4.8.0a0")
conda_411 = parse_version(CONDA_VERSION) >= parse_version("4.11.0a0")
conda_43 = Version(CONDA_VERSION) >= Version("4.3.0a0")
conda_44 = Version(CONDA_VERSION) >= Version("4.4.0a0")
conda_45 = Version(CONDA_VERSION) >= Version("4.5.0a0")
conda_46 = Version(CONDA_VERSION) >= Version("4.6.0a0")
conda_47 = Version(CONDA_VERSION) >= Version("4.7.0a0")
conda_48 = Version(CONDA_VERSION) >= Version("4.8.0a0")
conda_411 = Version(CONDA_VERSION) >= Version("4.11.0a0")

if conda_44:
from conda.exports import display_actions, execute_actions, execute_plan, install_actions
Expand Down
18 changes: 9 additions & 9 deletions conda_build/skeletons/cpan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,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 @@ -230,7 +230,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 @@ -437,7 +437,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 @@ -565,7 +565,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 @@ -618,7 +618,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 @@ -706,7 +706,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 @@ -717,7 +717,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 @@ -992,12 +992,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 @@ -10,7 +10,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 @@ -267,7 +267,7 @@ def skeletonize(packages, output_dir=".", version=None, recursive=False,
# Make sure there is always something to pass in for this
pypi_data = {}
else:
sort_by_version = lambda l: sorted(l, key=parse_version)
sort_by_version = lambda l: sorted(l, key=Version)

pypi_resp = requests.get(package_pypi_url, verify=not _ssl_no_verify())

Expand Down
6 changes: 3 additions & 3 deletions conda_build/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from copy import copy
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 @@ -86,9 +86,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 setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"psutil",
"six",
"libarchive-c",
"setuptools",
"packaging",
# "conda-package-handling", # remove comment once released on PyPI
"glob2",
]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

from binstar_client.commands import remove, show
from binstar_client.errors import NotFound
from pkg_resources import parse_version
from packaging.version import Version
import pytest
import yaml
import tarfile
Expand Down Expand Up @@ -798,7 +798,7 @@ def test_about_license_file_and_prelink_message(testing_workdir, testing_config,
# Regardless of the reason for skipping, we should definitely find a better way for tests to look for the packages
# Rather than assuming they will be at $ROOT/pkgs since that can change and we don't care where they are in terms of the
# tests.
@pytest.mark.xfail(parse_version(conda.__version__) < parse_version("4.3.14"),
@pytest.mark.xfail(Version(conda.__version__) < Version("4.3.14"),
reason="new noarch supported starting with conda 4.3.14")
def test_noarch_python_with_tests(testing_config):
recipe = os.path.join(metadata_dir, "_noarch_python_with_tests")
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 @@ -3,7 +3,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 @@ -334,7 +334,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 @@ -351,7 +351,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 @@ -365,7 +365,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 @@ -381,7 +381,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 f0eef48

Please sign in to comment.