From a6854e7ea8ac41bfbe02602422dfc955b084faba Mon Sep 17 00:00:00 2001 From: "A. Reit" Date: Mon, 25 Nov 2024 14:41:23 +0100 Subject: [PATCH] Fix SetuptoolsDeprecationWarning issued by 'python -m build' Fix 'extras_require' in setup.py to fix the warning. This requires fixes for the parsing of dependencies in test_dependencies_in_sync.py: Use the 'packaging' module which simplifies the code. --- .github/scripts/install.sh | 1 + setup.py | 2 +- spyder/tests/test_dependencies_in_sync.py | 74 +++++++++-------------- 3 files changed, 29 insertions(+), 48 deletions(-) diff --git a/.github/scripts/install.sh b/.github/scripts/install.sh index 6155dc3f543..3b4de1a4cb3 100755 --- a/.github/scripts/install.sh +++ b/.github/scripts/install.sh @@ -24,6 +24,7 @@ fi # Install dependencies if [ "$USE_CONDA" = "true" ]; then if [ -n "$QT6_BINDINGS" ]; then + # conda has no PyQt6 package echo "Cannot use Qt 6 with Conda" 1>&2 exit 1 fi diff --git a/setup.py b/setup.py index 181ddd359e2..d4d94577b5d 100644 --- a/setup.py +++ b/setup.py @@ -264,7 +264,6 @@ def run(self): install_requires.append('qtconsole>=5.5.1,<5.7.0') extras_require = { - 'test:platform_system == "Windows"': ['pywin32'], 'test': [ 'coverage', 'cython', @@ -279,6 +278,7 @@ def run(self): 'pytest-order', 'pytest-qt', 'pytest-timeout', + 'pywin32;platform_system=="Windows"', 'pyyaml', 'scipy', 'sympy', diff --git a/spyder/tests/test_dependencies_in_sync.py b/spyder/tests/test_dependencies_in_sync.py index bb8865d043a..54c51fd5709 100644 --- a/spyder/tests/test_dependencies_in_sync.py +++ b/spyder/tests/test_dependencies_in_sync.py @@ -9,6 +9,8 @@ import os.path as osp # Third party imports +from packaging.requirements import Requirement +from packaging.specifiers import SpecifierSet import pytest import yaml @@ -42,15 +44,11 @@ def parse_environment_yaml(fpath): elif dep == 'websockify': continue else: - parts = dep.split(' ') - if len(parts) > 1: - ver = parts[-1] - if ver[0] == '=': - ver = '=' + ver - - deps[parts[0]] = ver + req = Requirement(dep) + if req.specifier: + deps[req.name] = str(req.specifier) else: - deps[parts[0]] = None + deps[req.name] = None return deps @@ -66,10 +64,7 @@ def parse_spyder_dependencies(): ver = dep['required_version'] if ver: - if ';' in ver: - ver = ver.replace(';', ',') - elif ver[0] == '=': - ver = '=' + ver + ver = str(SpecifierSet(ver)) deps[dep['package_name'].lower()] = ver @@ -98,26 +93,16 @@ def parse_setup_install_requires(fpath): dep_list = literal_eval('[' + '\n'.join(lines[start:end + 1])) dep_list = [item for item in dep_list if item[0] != '#'] for dep in dep_list: - dep = dep.split(';')[0] - name, ver = None, None - - for sep in ['>=', '==', '<=', '<', '>']: - if sep in dep: - idx = dep.index(sep) - name = dep[:idx] - ver = dep[idx:] - break - - if name is not None: - name = name.split('[')[0] - else: - name = dep.split('[')[0] + req = Requirement(dep) # Transform pypi to conda name - if name == 'pyqt5': - name = 'pyqt' + if req.name == 'pyqt5': + req.name = 'pyqt' - deps[name] = ver + if req.specifier: + deps[req.name] = str(req.specifier) + else: + deps[req.name] = None return deps @@ -145,27 +130,22 @@ def parse_setup_extra_requires(fpath): dep_list = dep_dict.get('test') dep_list = [item for item in dep_list if item[0] != '#'] for dep in dep_list: - dep = dep.split(';')[0] - name, ver = None, None - - for sep in ['>=', '==', '<=', '<', '>']: - if sep in dep: - idx = dep.index(sep) - name = dep[:idx] - ver = dep[idx:] - break - - if name is not None: - name = name.split('[')[0] - else: - name = dep.split('[')[0] + req = Requirement(dep) # Transform pypi to conda name - if name == 'pyqt5': - name = 'pyqt' + if req.name == 'pyqt5': + req.name = 'pyqt' + + if req.marker and not req.marker.evaluate(): + # Skip dependencies which are not required for current environment + # (e.g. skip 'platform_system=="Windows"' on Linux) + continue + + if req.specifier: + deps[req.name] = str(req.specifier) + else: + deps[req.name] = None - deps[name] = ver - print(deps) return deps