From 5b2175ebd9f4a669097e8309a53e3b843dcbb218 Mon Sep 17 00:00:00 2001 From: robnagler Date: Tue, 26 Feb 2019 17:10:49 +0000 Subject: uniquify paths in PYTHONPATH When running in a complex environment with lots of installed packages, PYTHONPATH gets way too long. Instead, just make sure that paths_on_pythonpath doesn't contain duplicates --- setuptools/command/test.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/setuptools/command/test.py b/setuptools/command/test.py index dde0118c..997fd8b0 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -186,11 +186,12 @@ class test(Command): orig_pythonpath = os.environ.get('PYTHONPATH', nothing) current_pythonpath = os.environ.get('PYTHONPATH', '') try: - prefix = os.pathsep.join(paths) - to_join = filter(None, [prefix, current_pythonpath]) - new_path = os.pathsep.join(to_join) - if new_path: - os.environ['PYTHONPATH'] = new_path + to_join = [] + for x in list(paths) + current_pythonpath.split(os.pathsep): + if x not in to_join: + to_join.append(x) + if to_join: + os.environ['PYTHONPATH'] = os.pathsep.join(to_join) yield finally: if orig_pythonpath is nothing: -- cgit v1.2.3 From 8db41e478db4ded53b9836f62211f8c9371ec7c9 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 5 Apr 2019 15:12:21 -0400 Subject: Rely on unique_everseen to avoid unnecessarily polluting the PYTHONPATH with duplicate entries. --- setuptools/command/test.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/setuptools/command/test.py b/setuptools/command/test.py index 997fd8b0..973e4eb2 100644 --- a/setuptools/command/test.py +++ b/setuptools/command/test.py @@ -15,6 +15,7 @@ from pkg_resources import (resource_listdir, resource_exists, normalize_path, working_set, _namespace_packages, evaluate_marker, add_activation_listener, require, EntryPoint) from setuptools import Command +from .build_py import _unique_everseen __metaclass__ = type @@ -186,12 +187,11 @@ class test(Command): orig_pythonpath = os.environ.get('PYTHONPATH', nothing) current_pythonpath = os.environ.get('PYTHONPATH', '') try: - to_join = [] - for x in list(paths) + current_pythonpath.split(os.pathsep): - if x not in to_join: - to_join.append(x) - if to_join: - os.environ['PYTHONPATH'] = os.pathsep.join(to_join) + prefix = os.pathsep.join(_unique_everseen(paths)) + to_join = filter(None, [prefix, current_pythonpath]) + new_path = os.pathsep.join(to_join) + if new_path: + os.environ['PYTHONPATH'] = new_path yield finally: if orig_pythonpath is nothing: -- cgit v1.2.3 From 1b4ef9635452958482a121f41e65d0b6cca1a9d6 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Fri, 5 Apr 2019 15:16:31 -0400 Subject: Add changelog entry. --- changelog.d/1709.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/1709.bugfix.rst diff --git a/changelog.d/1709.bugfix.rst b/changelog.d/1709.bugfix.rst new file mode 100644 index 00000000..c6670ae9 --- /dev/null +++ b/changelog.d/1709.bugfix.rst @@ -0,0 +1 @@ +In test.paths_on_python_path, avoid adding unnecessary duplicates to the PYTHONPATH. -- cgit v1.2.3