[Python-Dev] PEP 370 and IronPython (original) (raw)
Christian Heimes lists at cheimes.de
Thu Oct 8 13:17:46 CEST 2009
- Previous message: [Python-Dev] eggs now mandatory for pypi?
- Next message: [Python-Dev] PEP 370 and IronPython
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Dear Pythonistas!
Michael Foord has written a blog posting [1] regarding IronPython, site packages and my PEP 370. I'm referring to the section that talks about an issue with PEP 370.
If you install CPython 2.6 on Windows it creates a folder in the location: %APPDATA%\Python\Python26\site-packages. On my machine the full path is: C:\Users\michael\AppData\Roaming\Python\Python26\site-packages.
This is put on the path by site.py when you run Python and as it is a user directory it doesn't require elevation to install there. You install into the user directory rather than the 'usual' location with:
python setup.py --user install
Herein lies another problem though. IronPython uses the standard Python site.py, meaning that currently it shares the user site-packages folder with CPython. This is not ideal as typically you will want separate libraries install for IronPython. When Jython ports to Python 2.6 it will have the same issue.
I didn't think about IronPython during the design phase of the PEP. I didn't come into my mind that another implementation may require a different site packages directory. After spinning my head around the issue a simple solution came to me.
The solution requires a new attribute in the sys module that contains the name of the implementation. As an alternative we could use the first field of sys.subversion but I prefer an explicit attribute. I'm proposing "sys.name" with a value of "CPython", "IronPython", "Jython" or "PyPy". The site module uses the information of the attribute to modify the path to the user site directory.
The altered user site directories are:
CPython: ~/.local/lib/python2.6/site-packages %APPDATA%/Python/Python26
IronPython: ~/.local/lib/ironpython2.6/site-packages %APPDATA%/Python/IronPython26
Jython: ~/.local/lib/jython2.6/site-packages %APPDATA%/Python/Jython26
Proposed patch:
Index: Lib/site.py
--- Lib/site.py (revision 75282) +++ Lib/site.py (working copy) @@ -74,7 +74,12 @@ USER_SITE = None USER_BASE = None
+interpreter_name = getattr(sys, "name", "CPython") +if interpreter_name == "CPython":
b/w compatible name
interpreter_name = "python"
def makepath(*paths): dir = os.path.abspath(os.path.join(*paths)) return dir, os.path.normcase(dir)
@@ -253,10 +258,12 @@ return USER_SITE
if os.name == "nt":
USER_SITE = os.path.join(user_base, "Python" + sys.version[0] +
sys.version[2], "site-packages")
USER_SITE = os.path.join(user_base, interpreter_name.capitalize() +
sys.version[0] + sys.version[2],
else:"site-packages")
USER_SITE = os.path.join(user_base, "lib", "python" +
sys.version[:3],
USER_SITE = os.path.join(user_base, "lib",
interpreter_name.lower() +
sys.version[:3], "site-packages")
return USER_SITE
The patch doesn't modify the search path for global directories. These can be changed by altering sys.prefix and sys.exec_prefix.
Christian
[1] http://ironpython-urls.blogspot.com/2009/10/distributing-ironpython-packages.html
- Previous message: [Python-Dev] eggs now mandatory for pypi?
- Next message: [Python-Dev] PEP 370 and IronPython
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]