From 05ccf752512c74d212f746017f240c692f848983 Mon Sep 17 00:00:00 2001 From: Alfred Wingate Date: Mon, 19 Jun 2023 07:30:22 +0300 Subject: [PATCH 1/2] remove use of distutils * Python 3.11 deprecated distutils and Python 3.12 completely removed it * Removed find_package_data entirely as there was not package data to install Signed-off-by: Alfred Wingate --- tests/testtemplate/setup.py | 103 ------------------------------------ virtualenvwrapper.sh | 2 +- 2 files changed, 1 insertion(+), 104 deletions(-) diff --git a/tests/testtemplate/setup.py b/tests/testtemplate/setup.py index f18835e..6c9b794 100644 --- a/tests/testtemplate/setup.py +++ b/tests/testtemplate/setup.py @@ -5,102 +5,6 @@ from setuptools import setup, find_packages -from distutils.util import convert_path -from fnmatch import fnmatchcase - -import os -import sys - -############################################################################## -# find_package_data is an Ian Bicking creation. - -# Provided as an attribute, so you can append to these instead -# of replicating them: -standard_exclude = ('*.py', '*.pyc', '*~', '.*', '*.bak', '*.swp*') -standard_exclude_directories = ('.*', 'CVS', '_darcs', './build', - './dist', 'EGG-INFO', '*.egg-info') - - -def find_package_data( - where='.', package='', - exclude=standard_exclude, - exclude_directories=standard_exclude_directories, - only_in_packages=True, - show_ignored=False): - """ - Return a dictionary suitable for use in ``package_data`` - in a distutils ``setup.py`` file. - - The dictionary looks like:: - - {'package': [files]} - - Where ``files`` is a list of all the files in that package that - don't match anything in ``exclude``. - - If ``only_in_packages`` is true, then top-level directories that - are not packages won't be included (but directories under packages - will). - - Directories matching any pattern in ``exclude_directories`` will - be ignored; by default directories with leading ``.``, ``CVS``, - and ``_darcs`` will be ignored. - - If ``show_ignored`` is true, then all the files that aren't - included in package data are shown on stderr (for debugging - purposes). - - Note patterns use wildcards, or can be exact paths (including - leading ``./``), and all searching is case-insensitive. - - This function is by Ian Bicking. - """ - - out = {} - stack = [(convert_path(where), '', package, only_in_packages)] - while stack: - where, prefix, package, only_in_packages = stack.pop(0) - for name in os.listdir(where): - fn = os.path.join(where, name) - if os.path.isdir(fn): - bad_name = False - for pattern in exclude_directories: - if (fnmatchcase(name, pattern) - or fn.lower() == pattern.lower()): - bad_name = True - if show_ignored: - print >> sys.stderr, ( - "Directory %s ignored by pattern %s" - % (fn, pattern)) - break - if bad_name: - continue - if os.path.isfile(os.path.join(fn, '__init__.py')): - if not package: - new_package = name - else: - new_package = package + '.' + name - stack.append((fn, '', new_package, False)) - else: - stack.append((fn, prefix + name + '/', package, only_in_packages)) - elif package or not only_in_packages: - # is a file - bad_name = False - for pattern in exclude: - if (fnmatchcase(name, pattern) - or fn.lower() == pattern.lower()): - bad_name = True - if show_ignored: - print >> sys.stderr, ( - "File %s ignored by pattern %s" - % (fn, pattern)) - break - if bad_name: - continue - out.setdefault(package, []).append(prefix+name) - return out -############################################################################## - setup( name=PROJECT, version=VERSION, @@ -130,13 +34,6 @@ def find_package_data( packages=find_packages(), include_package_data=True, - # Scan the input for package information - # to grab any data files (text, images, etc.) - # associated with sub-packages. - package_data=find_package_data('mytemplates', - package='mytemplates', - only_in_packages=False, - ), entry_points={ 'virtualenvwrapper.project.template': [ diff --git a/virtualenvwrapper.sh b/virtualenvwrapper.sh index edd9631..afa5395 100644 --- a/virtualenvwrapper.sh +++ b/virtualenvwrapper.sh @@ -820,7 +820,7 @@ function virtualenvwrapper_get_python_version { # Prints the path to the site-packages directory for the current environment. function virtualenvwrapper_get_site_packages_dir { - "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib())" + "$VIRTUAL_ENV/$VIRTUALENVWRAPPER_ENV_BIN_DIR/python" -c "import sysconfig; print(sysconfig.get_path('platlib'))" } # Path management for packages outside of the virtual env. From da927a0d64e039db1bab04f65563db94a7d07fb2 Mon Sep 17 00:00:00 2001 From: Alfred Wingate Date: Mon, 19 Jun 2023 07:34:57 +0300 Subject: [PATCH 2/2] install setuptools for test packages, use pip * setuptools isn't included in ensurepip in Python 3.12 * Use pip install instead of invoking setup.py directly, due to setuptools discouraging it and allowing updates for the tests packages to use PEP517 compliant build system to done seamlessly. Also don't need to invoke pip install -r requirements.txt. * editable_mode=compat is comparable to python setup.py develop. But setuptools doesn't guarantee the longevity of the feature. Removal of support for the legacy method would be a thing consider. Signed-off-by: Alfred Wingate --- tests/test_cp.sh | 2 +- tests/test_project_templates.sh | 2 +- tests/test_wipeenv.sh | 4 ++-- tests/testpackage/requirements.txt | 1 + tests/testtemplate/requirements.txt | 1 + 5 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 tests/testpackage/requirements.txt create mode 100644 tests/testtemplate/requirements.txt diff --git a/tests/test_cp.sh b/tests/test_cp.sh index b1b9b3d..cadd5ea 100755 --- a/tests/test_cp.sh +++ b/tests/test_cp.sh @@ -23,7 +23,7 @@ test_new_env_activated () { mkvirtualenv "source" >/dev/null 2>&1 RC=$? assertEquals "0" "$RC" - (cd tests/testpackage && python setup.py install) >/dev/null 2>&1 + (cd tests/testpackage && pip install .) >/dev/null 2>&1 cpvirtualenv "source" "destination" >/dev/null 2>&1 rmvirtualenv "source" >/dev/null 2>&1 testscript="$(which testscript.py)" diff --git a/tests/test_project_templates.sh b/tests/test_project_templates.sh index 5329cf6..32c7fcf 100755 --- a/tests/test_project_templates.sh +++ b/tests/test_project_templates.sh @@ -4,7 +4,7 @@ test_dir=$(dirname $0) source "$test_dir/setup.sh" oneTimeSetUp() { - (cd "$test_dir/testtemplate" && rm -rf build && "$VIRTUAL_ENV/bin/python" setup.py install) + (cd "$test_dir/testtemplate" && rm -rf build && "$VIRTUAL_ENV/bin/python" -m pip install .) rm -rf "$WORKON_HOME" mkdir -p "$WORKON_HOME" rm -rf "$PROJECT_HOME" diff --git a/tests/test_wipeenv.sh b/tests/test_wipeenv.sh index 3eb7b71..f731580 100755 --- a/tests/test_wipeenv.sh +++ b/tests/test_wipeenv.sh @@ -20,7 +20,7 @@ tearDown() { test_wipeenv () { mkvirtualenv "wipetest" >/dev/null 2>&1 - (cd tests/testpackage && python setup.py install) >/dev/null 2>&1 + (cd tests/testpackage && pip install .) >/dev/null 2>&1 before="$(pip freeze)" assertTrue "testpackage not installed" "pip freeze | grep testpackage" wipeenv >/dev/null 2>&1 @@ -52,7 +52,7 @@ test_wipeenv_pip_e () { test_wipeenv_develop () { mkvirtualenv "wipetest" >/dev/null 2>&1 - (cd tests/testpackage && python setup.py develop) >/dev/null 2>&1 + (cd tests/testpackage && pip install -e . --config-settings editable_mode=compat) >/dev/null 2>&1 before="$(pip freeze)" assertTrue "testpackage not installed" "pip freeze | grep testpackage" wipeenv >/dev/null 2>&1 diff --git a/tests/testpackage/requirements.txt b/tests/testpackage/requirements.txt new file mode 100644 index 0000000..49fe098 --- /dev/null +++ b/tests/testpackage/requirements.txt @@ -0,0 +1 @@ +setuptools diff --git a/tests/testtemplate/requirements.txt b/tests/testtemplate/requirements.txt new file mode 100644 index 0000000..49fe098 --- /dev/null +++ b/tests/testtemplate/requirements.txt @@ -0,0 +1 @@ +setuptools