Mailing List Archive

Improvements to the sys.path initialization documentation
Hi All,

Steve Dower, Eryk Sun and I have been working on improving the
documentation around how sys.path is initialised and therefore how Python
modules are found.

We're moving the details from
https://docs.python.org/3.11/using/windows.html#finding-modules
to a platform-agnostic new section in
https://docs.python.org/3.11/using/cmdline.html

We're aiming to have one place in the documentation where all the ways to
customize sys.path (PYTHONPATH, ._pth, site, etc) are at least mentioned.

We'd appreciate further community feedback on the changes before they are
merged.
https://bugs.python.org/issue31582
https://github.com/python/cpython/pull/31082

Thank you,
Russel
Re: Improvements to the sys.path initialization documentation [ In reply to ]
Hi,

I tried to document inputs and outputs of Modules/getpath.py in the C
API Initialization API:
https://docs.python.org/dev/c-api/init_config.html#python-path-configuration

I don't know if it would be possible to merge most of these
information at a single place to avoid oudated documentation.

Victor

On Wed, Mar 2, 2022 at 5:40 PM Russel Webber <russel.webber@gmail.com> wrote:
>
> Hi All,
>
> Steve Dower, Eryk Sun and I have been working on improving the documentation around how sys.path is initialised and therefore how Python modules are found.
>
> We're moving the details from https://docs.python.org/3.11/using/windows.html#finding-modules
> to a platform-agnostic new section in https://docs.python.org/3.11/using/cmdline.html
>
> We're aiming to have one place in the documentation where all the ways to customize sys.path (PYTHONPATH, ._pth, site, etc) are at least mentioned.
>
> We'd appreciate further community feedback on the changes before they are merged.
> https://bugs.python.org/issue31582
> https://github.com/python/cpython/pull/31082
>
> Thank you,
> Russel
>
> _______________________________________________
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-leave@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/5AZQZH45EUCYN26SVD5DO6O7XTPSTIB5/
> Code of Conduct: http://python.org/psf/codeofconduct/



--
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/Q5VGOJPJE67JKCMZO2CZBH6UFM7EMXDY/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: Improvements to the sys.path initialization documentation [ In reply to ]
Hi,
I will add a link to
https://docs.python.org/dev/c-api/init_config.html#python-path-configuration
as we're trying to at least mention every way sys.path can be initialised.
I think the audience for the C API docs are likely to be more knowledgeable
than those reading the Setup and Usage section, so I don't believe it will
be possible to merge the information.
Thanks,
Russel

On Thu, 3 Mar 2022 at 12:27, Victor Stinner <vstinner@python.org> wrote:

> Hi,
>
> I tried to document inputs and outputs of Modules/getpath.py in the C
> API Initialization API:
>
> https://docs.python.org/dev/c-api/init_config.html#python-path-configuration
>
> I don't know if it would be possible to merge most of these
> information at a single place to avoid oudated documentation.
>
> Victor
>
> On Wed, Mar 2, 2022 at 5:40 PM Russel Webber <russel.webber@gmail.com>
> wrote:
> >
> > Hi All,
> >
> > Steve Dower, Eryk Sun and I have been working on improving the
> documentation around how sys.path is initialised and therefore how Python
> modules are found.
> >
> > We're moving the details from
> https://docs.python.org/3.11/using/windows.html#finding-modules
> > to a platform-agnostic new section in
> https://docs.python.org/3.11/using/cmdline.html
> >
> > We're aiming to have one place in the documentation where all the ways
> to customize sys.path (PYTHONPATH, ._pth, site, etc) are at least mentioned.
> >
> > We'd appreciate further community feedback on the changes before they
> are merged.
> > https://bugs.python.org/issue31582
> > https://github.com/python/cpython/pull/31082
> >
> > Thank you,
> > Russel
> >
> > _______________________________________________
> > Python-Dev mailing list -- python-dev@python.org
> > To unsubscribe send an email to python-dev-leave@python.org
> > https://mail.python.org/mailman3/lists/python-dev.python.org/
> > Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/5AZQZH45EUCYN26SVD5DO6O7XTPSTIB5/
> > Code of Conduct: http://python.org/psf/codeofconduct/
>
>
>
> --
> Night gathers, and now my watch begins. It shall not end until my death.
>
Re: Improvements to the sys.path initialization documentation [ In reply to ]
Unrelated to the doc, now that getpath has been rewritten in pure
Python, thanks to Steve Dower!, it would be nice to move the last bits
of the sys.path initialization from the site module to the getpath
module. It's unpleasant to have a different sys.path depending if the
site module is loaded or not.

site handles venv, computes absolute paths and adds the user directory.

Loading customization modules (sitecustomize and usercustomize) should
stay in the site module.

Victor
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/4GZZ5PRP5YLZUVE34NYQQNUF4KBNMNNV/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: Improvements to the sys.path initialization documentation [ In reply to ]
On 3/4/22, Victor Stinner <vstinner@python.org> wrote:
> it would be nice to move the last bits of the sys.path initialization
> from the site module to the getpath module. It's unpleasant to
> have a different sys.path depending if the site module is loaded
> or not.

I don't understand. The site packages directories, including virtual
environments, are a site extension.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/5ZO73YHNL3BHXY4MHRITOGOECL2SZKPO/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: Improvements to the sys.path initialization documentation [ In reply to ]
On Fri, Mar 4, 2022 at 1:37 PM Eryk Sun <eryksun@gmail.com> wrote:
> I don't understand. The site packages directories, including virtual
> environments, are a site extension.

I propose to change that. Move all code related to sys.path from the
site module to the Modules/getpath.py module.

Victor
--
Night gathers, and now my watch begins. It shall not end until my death.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/HXD2JIDHBX7BFIU3FA7R3LWRFEXQMVYW/
Code of Conduct: http://python.org/psf/codeofconduct/
Re: Improvements to the sys.path initialization documentation [ In reply to ]
On Mon, 7 Mar 2022, 7:42 pm Victor Stinner, <vstinner@python.org> wrote:

> On Fri, Mar 4, 2022 at 1:37 PM Eryk Sun <eryksun@gmail.com> wrote:
> > I don't understand. The site packages directories, including virtual
> > environments, are a site extension.
>
> I propose to change that. Move all code related to sys.path from the
> site module to the Modules/getpath.py module.
>

Certain entries not being on sys.path when the site module isn't loaded is
a feature (the "-S" CLI option), not a bug to be fixed.

Those site entries haven't historically been the really confusing part of
path inititialisation - it's been finding out where all the *other* default
entries are coming from, so you can get a clearer picture of what's always
there vs what's being added by the site module.

Cheers,
Nick.



> Victor
> --
> Night gathers, and now my watch begins. It shall not end until my death.
> _______________________________________________
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-leave@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-dev@python.org/message/HXD2JIDHBX7BFIU3FA7R3LWRFEXQMVYW/
> Code of Conduct: http://python.org/psf/codeofconduct/
>