Commit Graph

149 Commits

Author SHA1 Message Date
Miss Islington (bot) 233cf75d6d [3.15] gh-149819: fix .pth and .start file processing in subprocess when inheriting PYTHONPATH (GH-150177) (#150202)
gh-149819: fix .pth and .start file processing in subprocess when inheriting PYTHONPATH (GH-150177)

* gh-149819: Fix .pth files not loaded in Python subprocesses

After PR gh-149583 (Fix double evaluation of .pth and .site files in
venvs), .pth files are no longer loaded in subprocesses started with
subprocess.run([sys.executable, ...]).  The root cause: main() seeds
known_paths from removeduppaths() with all sys.path entries inherited
from the parent process.  addsitedir() then skips .pth processing for
every directory already in known_paths.

Fix:
- main(): call removeduppaths() for dedup but start known_paths as a
  fresh empty set, so that addsitedir() processes .pth files in every
  site-packages directory regardless of inherited sys.path.
- addsitedir(): move known_paths.add() before the sys.path.append and
  guard the append with 'sitedir not in sys.path' to avoid creating
  duplicate entries when called with a fresh known_paths.

This preserves the gh-75723 dedup guarantee while allowing subprocesses
to load .pth files.

* Fill out the tests for GH#149888

* Extend _make_start() and _make_pth() to take an optional `basedir` which is used instead of
 `site.tmpdir` if given.
* Add test_pth_processed_when_sitedir_already_on_path() to test the core GH#149819 bug: .pth files
  in subprocesses aren't handled if PYTHONPATH pointing to the .pth directory is inherited.
* Similarly add test_start_processed_when_sitedir_already_on_path() to verify that .start files in
  the same circumstances are also now processed.

* Update Lib/site.py



* Oops!  Remove redundant code

---------
(cherry picked from commit 3c298e2e38)

Co-authored-by: Barry Warsaw <barry@python.org>
Co-authored-by: BugBounty Mind <bugbounty-mind@deepseek.tui>
Co-authored-by: scoder <stefan_ml@behnel.de>
2026-05-21 15:31:41 -07:00
Barry Warsaw 45fc9acb8c [3.15] gh-149504: Fix re-entrancy bug when .pth/.start file invokes site.add sitedir() (#149659) (#149799)
* gh-149504: Fix re-entrancy bug when .pth/.start file invokes site.addsitedir() (#149659)

* Add re-entrant tests for gh-149504
* Add end-to-end integration test coverage

This ensures that future whitebox internal test changes do not regress the
public surface semantics.

* Implement a state class to process .pth and .start files

By using this state class and managing implicit and explicit batching, we make it structurally
impossible to get bitten by re-entrant site startup processing.

Fixes #149504

(cherry picked from commit b162307d7f)

* Add myself back to CODEOWNERS
2026-05-13 15:45:39 -07:00
Barry Warsaw 24c4aecc16 gh-148641: Implement PEP 829 - startup configuration files (#149109)
Implement PEP 829 - startup configuration files
Also add `pkgutil.resolve_name(..., strict=True)` 

Co-authored-by: Brett Cannon <brett@python.org>
2026-05-03 17:17:29 +00:00
Brett Cannon af185727b2 GH-65961: Stop setting __cached__ on modules (GH-142165) 2025-12-11 11:44:46 -08:00
Stan Ulbrych 7ac94fcb1d gh-140170: Fix test_site with -s flag (GH-140179)
Commit
2025-10-16 12:49:08 +03:00
Steve Dower 7d06a0af17 gh-120037: Disable user site packages when a ._pth file is used (GH-137428) 2025-08-19 21:28:28 +01:00
ggqlq 03f5519d77 gh-131178: Add tests for site command-line interface (GH-133582) 2025-08-15 14:00:43 -04:00
Serhiy Storchaka 2602d8ae98 gh-71339: Use new assertion methods in tests (GH-129046) 2025-05-22 13:17:22 +03:00
Jelle Zijlstra 58567cc18c gh-132952: Speed up startup by importing _io instead of io (#132957) 2025-04-28 08:38:56 -07:00
Bénédikt Tran 3185e3115c gh-131277: allow EnvironmentVarGuard to unset more than one environment variable at once (#131280)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-03-16 14:09:33 +01:00
Sam Gross e8c91d90ba gh-121103: Put free-threaded libraries in lib/python3.14t (#121293)
On POSIX systems, excluding macOS framework installs, the lib directory
for the free-threaded build now includes a "t" suffix to avoid conflicts
with a co-located default build installation.
2024-07-11 16:21:37 -04:00
Victor Stinner e9f4d80fa6 gh-120417: Add #noqa: F401 to tests (#120627)
Ignore linter "imported but unused" warnings in tests when the linter
doesn't understand how the import is used.
2024-06-18 15:51:47 +00:00
Serhiy Storchaka 74208ed0c4 gh-113659: Skip hidden .pth files (GH-113660)
Skip .pth files with names starting with a dot or hidden file attribute.
2024-01-16 20:23:05 +02:00
Zackery Spytz f19b93fce0 gh-73965: New environment variable PYTHON_HISTORY (#13208)
It can be used to set the location of a .python_history file

---------

Co-authored-by: Levi Sabah <0xl3vi@gmail.com>
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
2024-01-06 22:30:12 -08:00
Itamar Oren 5dc79e3d7f gh-113628: Fix test_site test with long stdlib paths (#113640) 2024-01-02 17:30:53 -07:00
Charles Machalow 738574fb21 gh-108747: Add unit tests for site.{usercustomize,sitecustomize} hooks (#109470) 2023-10-17 22:05:41 -07:00
Victor Stinner cbb3a6f8ad gh-109237: Fix test_site for non-ASCII working directory (#109238)
Fix test_site.test_underpth_basic() when the working directory
contains at least one non-ASCII character: encode the "._pth" file to
UTF-8 and enable the UTF-8 Mode to use UTF-8 for the child process
stdout.
2023-09-10 22:04:35 +00:00
Serhiy Storchaka 509bb61977 Reorder some test's decorators (GH-108804)
For example, do not demand the 'cpu' resource if the test cannot be run
due to non-working threads.
2023-09-03 15:21:43 +03:00
Steve Dower 51fd4de101 gh-94205: Ensures all required DLLs are copied on Windows for underpth tests (GH-94206) 2022-06-24 11:48:53 +01:00
Irit Katriel b1ae4af5e8 GH-77403: Fix tests which fail when PYTHONUSERBASE is not normalized (GH-93917) 2022-06-17 23:28:23 +01:00
Victor Stinner 3ceb4b8d3a gh-84623: Remove unused imports in tests (#93772) 2022-06-13 16:56:03 +02:00
Serhiy Storchaka 1be3260a90 bpo-47152: Convert the re module into a package (GH-32177)
The sre_* modules are now deprecated.
2022-04-02 11:35:13 +03:00
Victor Stinner 04dd60e50c bpo-46659: Update the test on the mbcs codec alias (GH-31168)
encodings registers the _alias_mbcs() codec search function before
the search_function() codec search function. Previously, the
_alias_mbcs() was never used.

Fix the test_codecs.test_mbcs_alias() test: use the current ANSI code
page, not a fake ANSI code page number.

Remove the test_site.test_aliasing_mbcs() test: the alias is now
implemented in the encodings module, no longer in the site module.
2022-02-06 21:50:09 +01:00
Christian Heimes 8464fbc42e bpo-40280: Skip subprocess-based tests on wasm32-emscripten (GH-30615) 2022-01-25 08:09:06 +01:00
Steve Dower bfc59ed0a0 bpo-46049: Fixes ._pth support on non-Windows (GH-30051) 2021-12-11 15:06:17 +00:00
Steve Dower 971ece8e17 bpo-46048: Fix parsing of single character lines in getpath readlines() (GH-30048) 2021-12-11 13:43:40 +00:00
Steve Dower 99fcf15052 bpo-45582: Port getpath[p].c to Python (GH-29041)
The getpath.py file is frozen at build time and executed as code over a namespace. It is never imported, nor is it meant to be importable or reusable. However, it should be easier to read, modify, and patch than the previous code.

This commit attempts to preserve every previously tested quirk, but these may be changed in the future to better align platforms.
2021-12-03 00:08:42 +00:00
Eric Snow 090591636c bpo-45020: Freeze os, site, and codecs. (gh-28398)
https://bugs.python.org/issue45020
2021-09-17 16:31:31 -06:00
native-api 1270ad6ec8 bpo-36160: Fix test_site so that it can run independently of other tests (GH-12131) 2021-05-20 11:25:37 +01:00
Steve Dower 04732ca993 bpo-43105: Importlib now resolves relative paths when creating module spec objects from file locations (GH-25121) 2021-04-07 01:02:07 +01:00
pxinwr ab74c014ae bpo-31904: Fix site and sysconfig modules for VxWorks RTOS (GH-21821) 2020-12-20 23:27:42 +01:00
Ned Deily 6a48518e8d bpo-41939: always enable test_site.test_license_exists_at_url (GH-22688) 2020-10-13 21:38:56 -04:00
Victor Stinner 1fce240d6c bpo-41939: Fix test_site.test_license_exists_at_url() (#22559)
Call urllib.request.urlcleanup() to reset the global
urllib.request._opener.
2020-10-05 18:24:00 +02:00
idomic 0c71a66b53 bpo-33689: Blank lines in .pth file cause a duplicate sys.path entry (GH-20679) 2020-09-19 22:13:29 +03:00
Hai Shi 79bb2c93f2 bpo-40275: Use new test.support helper submodules in tests (GH-21743) 2020-08-06 13:51:29 +02:00
Hai Shi c7decc27d5 bpo-40275: Use new test.support helper submodules in tests (GH-21727) 2020-08-04 17:53:12 +02:00
Steve Dower 936a660945 bpo-41304: Ensure python3x._pth is loaded on Windows (GH-21495) 2020-07-15 22:56:49 +01:00
Serhiy Storchaka 9355868458 bpo-41043: Escape literal part of the path for glob(). (GH-20994) 2020-06-20 11:10:31 +03:00
native-api 2145c8c972 bpo-33944: site: Add site-packages tracing in verbose mode (GH-12110) 2020-06-12 15:20:11 +09:00
Serhiy Storchaka bfb1cf4465 bpo-40275: Move transient_internet from test.support to socket_helper (GH-19711) 2020-04-29 10:36:20 +03:00
Victor Stinner d18de46117 bpo-27807: Skip test_site.test_startup_imports() if pth file (GH-19060)
test_site.test_startup_imports() is now skipped if a path of sys.path
contains a .pth file.

Sort test_site imports.
2020-03-18 18:27:32 +01:00
Victor Stinner 8510f43078 bpo-1294959: Add sys.platlibdir attribute (GH-18381)
Add --with-platlibdir option to the configure script: name of the
platform-specific library directory, stored in the new sys.platlitdir
attribute. It is used to build the path of platform-specific dynamic
libraries and the path of the standard library.

It is equal to "lib" on most platforms. On Fedora and SuSE, it is
equal to "lib64" on 64-bit systems.

Co-Authored-By: Jan Matějek <jmatejek@suse.com>
Co-Authored-By: Matěj Cepl <mcepl@cepl.eu>
Co-Authored-By: Charalampos Stratakis <cstratak@redhat.com>
2020-03-10 09:53:09 +01:00
Inada Naoki c4d92c8ada simplify StartupImportTests (GH-13096)
_osx_support and copyreg are not imported from site on macOS for now.
2019-05-05 18:06:30 +09:00
Serhiy Storchaka 5b10b98247 bpo-22831: Use "with" to avoid possible fd leaks in tests (part 2). (GH-10929) 2019-03-05 10:06:26 +02:00
native-api 45d8d2469a fixed duplicated method name of test_getuserbase() (GH-12140) 2019-03-04 01:05:19 +09:00
Serhiy Storchaka 94cf308ee2 bpo-33306: Improve SyntaxError messages for unbalanced parentheses. (GH-6516) 2018-12-17 17:34:14 +02:00
Victor Stinner f2f4555d82 bpo-10496: posixpath.expanduser() catchs pwd.getpwuid() error (GH-10919)
* posixpath.expanduser() now returns the input path unchanged if
  the HOME environment variable is not set and pwd.getpwuid() raises
  KeyError (the current user identifier doesn't exist in the password
  database).
* Add test_no_home_directory() to test_site.
2018-12-05 16:49:35 +01:00
INADA Naoki d4c76d960b bpo-30167: Add test for module.__cached__ is None (GH-7617) 2018-10-01 21:10:37 +09:00
Steve Dower f14c28f397 bpo-34011: Fixes missing venv files and other tests (GH-9458) 2018-09-20 13:38:34 -07:00
Serhiy Storchaka 0185f34ddc bpo-33721: Make some os.path functions and pathlib.Path methods be tolerant to invalid paths. (#7695)
Such functions as os.path.exists(), os.path.lexists(), os.path.isdir(),
os.path.isfile(), os.path.islink(), and os.path.ismount() now return False
instead of raising ValueError or its subclasses UnicodeEncodeError
and UnicodeDecodeError for paths that contain characters or bytes
unrepresentative at the OS level.
2018-09-18 11:28:51 +03:00