PYTHONSITEDIR environment variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ago

    PYTHONSITEDIR environment variable

    Dear all,

    These days I often find myself using working-env.py, virtual-python.py
    & co. The main reason in most cases is to insulate my working
    environment so that I can use custom site-package libs together with
    the default stdlib. PYTHONHOME and/or PYTHONPATH (particularly with
    python -S) get close, but not quite there, and the above scripts seem
    a bit over the top.

    Wouldn't it be possible to support a PYTHONSITEDIR environment
    variable in site.py for this purpose? I have attached a possible
    patch. In what follows, if PYTHONSITEDIR is defined, that dir is used
    as the only source of site-packages, extra paths can easily be added
    by creating a .pth file in there. A different variable could be used
    to prepend a sitedir to the list of default sitedirs (similar code
    without "return None").


    --- /usr/lib/python2.5/site.py 2008-05-29 22:03:04.000000 000 +0100
    +++ /tmp/site.py 2008-09-09 18:06:42.000000 000 +0100
    @@ -167,6 +167,10 @@

    def addsitepackages (known_paths):
    """Add site-packages (and possibly site-python) to sys.path"""
    + sitedir = os.environ.get( 'PYTHONSITEDIR' )
    + if sitedir and os.path.isdir(s itedir):
    + addsitedir(site dir, known_paths)
    + return None
    prefixes = [sys.prefix]
    if sys.exec_prefix != sys.prefix:
    prefixes.append (sys.exec_prefi x)
  • Christian Heimes

    #2
    Re: PYTHONSITEDIR environment variable

    ago wrote:
    Wouldn't it be possible to support a PYTHONSITEDIR environment
    variable in site.py for this purpose? I have attached a possible
    patch. In what follows, if PYTHONSITEDIR is defined, that dir is used
    as the only source of site-packages, extra paths can easily be added
    by creating a .pth file in there. A different variable could be used
    to prepend a sitedir to the list of default sitedirs (similar code
    without "return None").
    I had a similar idea, wrote a PEP and implemented it for 2.6 and 3.0:

    This PEP proposes a new a per user site-packages directory to allow users the local installation of Python packages in their home directory.


    Christian


    Comment

    • ago

      #3
      Re: PYTHONSITEDIR environment variable

      On Sep 9, 6:56 pm, Christian Heimes <li...@cheimes. dewrote:
      I had a similar idea, wrote a PEP and implemented it for 2.6 and 3.0:
      >
      This PEP proposes a new a per user site-packages directory to allow users the local installation of Python packages in their home directory.

      >
      Christian
      Christian,

      I like your pep :),

      The only thing I would add is that in my experience I often use
      different working-envs for different projects, so I'd prefer to have a
      more generic solution as opposed to a single working-env per user. The
      latter could still be achieved by setting the appropriate environment
      variable in the user profile. Do you think it would be possible to
      accommodate for the above in your PEP?

      Comment

      • Christian Heimes

        #4
        Re: PYTHONSITEDIR environment variable

        ago wrote:
        The only thing I would add is that in my experience I often use
        different working-envs for different projects, so I'd prefer to have a
        more generic solution as opposed to a single working-env per user. The
        latter could still be achieved by setting the appropriate environment
        variable in the user profile. Do you think it would be possible to
        accommodate for the above in your PEP?
        Isn't PYTHONUSERBASE sufficient for your needs? The env var alters the
        base directory.

        I can neither change the PEP nor the implementation at this stage of the
        development cycle. Python 2.6 and 3.0 are in beta and the API is set in
        stone.

        Christian

        Comment

        • ago

          #5
          Re: PYTHONSITEDIR environment variable

          Small variation on the above patch, using 2 environment variables:
          PYTHONSITEDIR allows for local site-packages (that override system
          site packages), and PYTHONNOSYSSITE S skips system site-packages for
          "clean-room" operation (similar to virtual-python.py --no-site-
          packages).


          --- /usr/lib/python2.5/site.py 2008-05-29 22:03:04.000000 000 +0100
          +++ /tmp/site.py 2008-09-09 19:56:44.000000 000 +0100
          @@ -167,6 +167,11 @@

          def addsitepackages (known_paths):
          """Add site-packages (and possibly site-python) to sys.path"""
          + sitedir = os.environ.get( 'PYTHONSITEDIR' )
          + if sitedir and os.path.isdir(s itedir):
          + addsitedir(site dir, known_paths)
          + if os.environ.get( 'PYTHONNOSYSSIT ES'):
          + return None
          prefixes = [sys.prefix]
          if sys.exec_prefix != sys.prefix:
          prefixes.append (sys.exec_prefi x)


          Comment

          • ago

            #6
            Re: PYTHONSITEDIR environment variable

            On Sep 9, 7:45 pm, Christian Heimes <li...@cheimes. dewrote:
            ago wrote:
            The only thing I would add is that in my experience I often use
            different working-envs for different projects, so I'd prefer to have a
            more generic solution as opposed to a single working-env per user. The
            latter could still be achieved by setting the appropriate environment
            variable in the user profile. Do you think it would be possible to
            accommodate for the above in your PEP?
            >
            Isn't PYTHONUSERBASE sufficient for your needs? The env var alters the
            base directory.
            >
            I can neither change the PEP nor the implementation at this stage of the
            development cycle. Python 2.6 and 3.0 are in beta and the API is set in
            stone.
            >
            Christian

            I had missed that, yes I think that PYTHONUSERBASE will do fine!
            It might be useful though to be able to skip other system site dirs
            altogether so that only local site packages are used, as in the second
            patch I sent (see PYTHONNOSYSSITE S).

            Thanks a lot,

            Ago

            Comment

            Working...