This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pythonXY._pth : unclear how .pth files are handled
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: barry, docs@python, steve.dower, takluyver
Priority: normal Keywords: patch

Created on 2018-01-28 18:51 by takluyver, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 5399 merged steve.dower, 2018-01-28 22:34
Messages (6)
msg310980 - (view) Author: Thomas Kluyver (takluyver) * Date: 2018-01-28 18:51
Nicholas Tollervey has been getting Pynsist to use the new pythonXY._pth file to assemble sys.path. However, I'm not clear on how this behaves with .pth files. The docs on this (https://docs.python.org/3/using/windows.html#finding-modules ) appear to contradict themselves:

> site is not imported unless one line in the file specifies import site
> ...
> Note that .pth files (without leading underscore) will be processed normally by the site module.

I can see two possibilities:

1. .pth files are processed normally if and only if the ._pth file specifies 'import site'. If it doesn't, they are ignored.
2. If a .pth file is encountered, site is imported to process it, but with sys.flags.nosite set, so that site doesn't do the normal stuff on import.

Some packages unfortunately seem to depend on .pth files getting processed, so if 1. is the case, Pynsist needs to ensure site is loaded.

Thanks :-)
msg311005 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-01-28 21:39
1 is correct. I don't see the contradiction - maybe you could purpose a rewording? (Perhaps it currently relies on the knowledge that the site module finds and processes .pth files? -S will also suppress it.)
msg311012 - (view) Author: Thomas Kluyver (takluyver) * Date: 2018-01-28 22:08
I'd reword the second sentence like this:

> Note that .pth files (without leading underscore) will be processed only if this file specifies ``import site``.

The current wording sounds (to me) like a guarantee that .pth files will still be handled, despite the other things that this mechanism switches off.
msg311032 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-01-28 23:34
New changeset 15ea3a6a320623328530e5d8da5b83c75766180b by Steve Dower in branch 'master':
bpo-32699: Improves doc for .pth files in presense of a ._pth file (#5399)
https://github.com/python/cpython/commit/15ea3a6a320623328530e5d8da5b83c75766180b
msg311043 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2018-01-29 03:22
Hopefully that's enough of a clarification.
msg311079 - (view) Author: Thomas Kluyver (takluyver) * Date: 2018-01-29 08:17
Thanks Steve, that looks good.
History
Date User Action Args
2022-04-11 14:58:57adminsetgithub: 76880
2018-01-29 08:17:38takluyversetmessages: + msg311079
2018-01-29 03:22:16steve.dowersetstatus: open -> closed

resolution: fixed

assignee: docs@python
stage: patch review -> resolved
versions: + Python 3.7, Python 3.8
nosy: + docs@python
messages: + msg311043
components: + Documentation
type: enhancement
2018-01-28 23:34:11steve.dowersetmessages: + msg311032
2018-01-28 22:34:36steve.dowersetkeywords: + patch
stage: patch review
pull_requests: + pull_request5233
2018-01-28 22:08:09takluyversetmessages: + msg311012
2018-01-28 21:42:01barrysetnosy: + barry
2018-01-28 21:39:31steve.dowersetmessages: + msg311005
2018-01-28 18:51:50takluyvercreate