Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/ekalinin/nodeenv/issues/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
Expand Down
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,17 @@ 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

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
-----
Expand Down
67 changes: 14 additions & 53 deletions nodeenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,25 @@
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
import socket
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'

join = os.path.join
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'))

Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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('_')
)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

coverage
flake8
mock; python_version < '3.3'
pytest
setuptools
tox
Expand Down
15 changes: 5 additions & 10 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand All @@ -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}},
)
25 changes: 7 additions & 18 deletions tests/nodeenv_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions tests/test_activate_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions tests/test_install_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading