diff --git a/CHANGES b/CHANGES index 59b4974..56e84d4 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,11 @@ Nodeenv changelog Version [unreleased] -------------------- +- Require Python 3.10 or later, matching the minimum version tested in CI. + Update package classifiers and wheel tags, and remove the unused Python 2 + compatibility paths. Old Node.js source builds still require Python 2.7 + as their build interpreter + `#436 `_ - `--source` builds of node.js 13 and later no longer need a `python2` command; 8.8 to 12.x still need one but point `python` at it on their own, so the `python` to python2 link in `PATH` is only set up for older diff --git a/README.rst b/README.rst index fb5d483..21761eb 100644 --- a/README.rst +++ b/README.rst @@ -107,7 +107,7 @@ Dependency For nodeenv ^^^^^^^^^^^ -* Python 3 (CI tests CPython 3.10 through 3.14) +* Python 3.10 or later (CI tests CPython 3.10 through 3.14) * make * tail @@ -115,6 +115,9 @@ For node.js ^^^^^^^^^^^ * libssl-dev +* Python 2.7 as a ``python2`` command when building Node.js versions older + than 13 from source; this is separate from the Python 3.10+ interpreter + that runs nodeenv. Usage ----- diff --git a/nodeenv.py b/nodeenv.py index b33829a..7177ae1 100644 --- a/nodeenv.py +++ b/nodeenv.py @@ -25,10 +25,7 @@ import subprocess import tarfile import time -if sys.version_info < (3, 3): - from pipes import quote as _quote -else: - from shlex import quote as _quote +from shlex import quote as _quote import platform import zipfile import shutil @@ -36,23 +33,10 @@ import sysconfig import glob -try: # pragma: no cover (py2 only) - from ConfigParser import SafeConfigParser as ConfigParser # pyright: ignore[reportMissingImports] # noqa: E501 - # noinspection PyCompatibility - import urllib2 # pyright: ignore[reportMissingImports] - from urlparse import urlsplit, urlunsplit # pyright: ignore[reportMissingImports] # noqa: E501 - from urllib import unquote # pyright: ignore[reportAttributeAccessIssue] - iteritems = operator.methodcaller('iteritems') - import httplib # pyright: ignore[reportMissingImports] - IncompleteRead = httplib.IncompleteRead -except ImportError: # pragma: no cover (py3 only) - from configparser import ConfigParser - # noinspection PyUnresolvedReferences - import urllib.request as urllib2 - from urllib.parse import unquote, urlsplit, urlunsplit - iteritems = operator.methodcaller('items') - import http - IncompleteRead = http.client.IncompleteRead +from configparser import ConfigParser +from http.client import IncompleteRead +import urllib.request as urllib2 +from urllib.parse import unquote, urlsplit, urlunsplit nodeenv_version = '1.11.0' @@ -60,7 +44,6 @@ abspath = os.path.abspath src_base_url = None -is_PY3 = sys.version_info[0] >= 3 is_WIN = platform.system() == 'Windows' is_CYGWIN = platform.system().startswith(('CYGWIN', 'MSYS')) @@ -79,27 +62,6 @@ # Utils -# https://github.com/jhermann/waif/blob/master/python/to_uft8.py -def to_utf8(text): - """Convert given text to UTF-8 encoding (as far as possible).""" - if not text or is_PY3: - return text - - try: # unicode or pure ascii - return text.encode("utf8") - except UnicodeDecodeError: - try: # successful UTF-8 decode means it's pretty sure UTF-8 - text.decode("utf8") - return text - except UnicodeDecodeError: - try: # get desperate; and yes, this has a western hemisphere bias - return text.decode("cp1252").encode("utf8") - except UnicodeDecodeError: - pass - - return text # return unchanged, hope for the best - - class Config(object): """ Configuration namespace. @@ -140,7 +102,7 @@ def _load(cls, configfiles, verbose=False): if not ini_file.has_section(section): continue - for attr, val in iteritems(vars(cls)): + for attr, val in vars(cls).items(): if attr.startswith('_') or not \ ini_file.has_option(section, attr): continue @@ -169,12 +131,12 @@ def _dump(cls): """ print(" [nodeenv]") print(" " + "\n ".join( - "%s = %s" % (k, v) for k, v in sorted(iteritems(vars(cls))) + "%s = %s" % (k, v) for k, v in sorted(vars(cls).items()) if not k.startswith('_'))) Config._default = dict( - (attr, val) for attr, val in iteritems(vars(Config)) + (attr, val) for attr, val in vars(Config).items() if not attr.startswith('_') ) @@ -428,7 +390,7 @@ def create_logger(): def emit(self, record): msg = self.format(record) fs = "%s" if getattr(record, "continued", False) else "%s\n" - self.stream.write(fs % to_utf8(msg)) + self.stream.write(fs % msg) self.flush() logging.StreamHandler.emit = emit @@ -690,8 +652,7 @@ def writefile(dest, content, overwrite=True, append=False): """ Create file and write content in it """ - content = to_utf8(content) - if is_PY3 and not isinstance(content, bytes): + if not isinstance(content, bytes): content = bytes(content, 'utf-8') if not os.path.exists(dest): logger.debug(' * Writing %s ... ', dest, extra=dict(continued=True)) @@ -1052,7 +1013,7 @@ def copy_node_from_prebuilt(env_dir, src_dir, node_version): else: dest = env_dir - src_folder_tpl = src_dir + to_utf8('/node-v%s*' % node_version) + src_folder_tpl = src_dir + '/node-v%s*' % node_version src_folder, = glob.glob(src_folder_tpl) copytree(src_folder, dest, True) @@ -1164,7 +1125,7 @@ def report_node_download_error(errors, args): def install_node_wrapped(env_dir, src_dir, args): env_dir = abspath(env_dir) - node_src_dir = join(src_dir, to_utf8('node-v%s' % args.node)) + node_src_dir = join(src_dir, 'node-v%s' % args.node) src_type = "prebuilt" if args.prebuilt else "source" logger.info(' * Install %s node (%s) ' % (src_type, args.node), @@ -1454,7 +1415,7 @@ def create_environment(env_dir, args): logger.info(' * Environment already exists: %s', env_dir) if not args.force: sys.exit(2) - src_dir = to_utf8(abspath(join(env_dir, 'src'))) + src_dir = abspath(join(env_dir, 'src')) mkdir(src_dir) if args.node == "system": @@ -1602,7 +1563,7 @@ def get_env_dir(args): sys.exit(2) else: res = args.env_dir - return to_utf8(res) + return res # noinspection PyProtectedMember diff --git a/requirements-dev.txt b/requirements-dev.txt index aa38656..ac4466c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -2,7 +2,6 @@ coverage flake8 -mock; python_version < '3.3' pytest setuptools tox diff --git a/setup.py b/setup.py index 0ad5e07..8b5cc0f 100644 --- a/setup.py +++ b/setup.py @@ -38,9 +38,7 @@ def read_file(file_name): author_email='e.v.kalinin@gmail.com', install_requires=[], extras_require={'certifi': ['certifi']}, - python_requires=( - ">=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*" - ), + python_requires='>=3.10', description="Node.js virtual environment builder", long_description=ldesc, py_modules=['nodeenv'], @@ -54,16 +52,13 @@ def read_file(file_name): 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', + 'Programming Language :: Python :: 3.14', 'Programming Language :: Python :: Implementation :: CPython', - 'Programming Language :: Python :: Implementation :: PyPy', 'Topic :: Software Development :: Libraries :: Python Modules' ], - options={'bdist_wheel': {'universal': True}}, ) diff --git a/tests/nodeenv_test.py b/tests/nodeenv_test.py index b47dbbe..5ee988b 100644 --- a/tests/nodeenv_test.py +++ b/tests/nodeenv_test.py @@ -1,11 +1,4 @@ -from __future__ import absolute_import -from __future__ import unicode_literals - -import sys -if sys.version_info < (3, 3): - from pipes import quote as _quote -else: - from shlex import quote as _quote +from shlex import quote as _quote import contextlib import http.server import io @@ -22,10 +15,7 @@ import threading import zipfile -try: - from unittest import mock -except ImportError: - import mock +from unittest import mock import pytest import nodeenv @@ -2579,16 +2569,15 @@ def test_without_python_virtualenv(self): result = nodeenv.get_env_dir(args) assert result == '/path/to/node/env' - def test_returns_utf8_encoded_string(self): - """Test that get_env_dir returns UTF-8 encoded string""" + def test_preserves_unicode_path(self): + """Environment paths remain text, including non-ASCII characters.""" args = mock.Mock() args.python_virtualenv = False - args.env_dir = '/path/to/env' + args.env_dir = '/path/to/öäü 环境' result = nodeenv.get_env_dir(args) - # The to_utf8 function is applied, - # but in Python 3 it returns the same string - assert result == '/path/to/env' + assert result == args.env_dir + assert isinstance(result, str) class TestInstallNpm: diff --git a/tests/test_activate_shells.py b/tests/test_activate_shells.py index 9e83447..b6a60ef 100644 --- a/tests/test_activate_shells.py +++ b/tests/test_activate_shells.py @@ -10,10 +10,7 @@ import subprocess import sys -try: - from unittest import mock -except ImportError: - import mock # pyright: ignore[reportMissingModuleSource] +from unittest import mock import pytest import nodeenv diff --git a/tests/test_install_activate.py b/tests/test_install_activate.py index 8595941..e83aae5 100644 --- a/tests/test_install_activate.py +++ b/tests/test_install_activate.py @@ -2,10 +2,7 @@ import os import subprocess -try: - from unittest import mock -except ImportError: - import mock # pyright: ignore[reportMissingModuleSource] +from unittest import mock import pytest import nodeenv