Page 1 of 1

Python __path__ help

Posted: Sat Jun 18, 2016 2:30 am
by spikethehobbit
Some proposed changes to the python interface use the `__path__` variable, but I am unsure how this variable works on different platforms. It would be helpful if a Windows and a Mac user could each post the output of this script:

import ctypes
print ctypes.__path__

On Linux, it produces
['/usr/lib/python2.7/ctypes']

Re: Python __path__ help

Posted: Sat Jun 18, 2016 3:52 am
by Geoff the Medio

Code: Select all

C:\Users\Geoff\Desktop\FreeOrion_VS2013_SDK\FreeOrionTemp>python
Python 2.7.9 (default, Apr 18 2015, 13:30:31) [MSC v.1800 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Geoff\Desktop\FreeOrion_VS2013_SDK\FreeOrionTemp\python27.zip\ctypes\__init__.py",
line 10, in <module>
ImportError: No module named _ctypes
>>> print ctypes.__path__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'ctypes' is not defined
>>>

Re: Python __path__ help

Posted: Sat Jun 18, 2016 9:11 am
by spikethehobbit
Ouch. That looks like a broken python install. Ah, it is in a .zip file, so it can't load the .dll. If it isn't too much trouble, could you try:

Code: Select all

import xml
print xml.__path__
That one should work even loading from a .zip file.

Mine gives

Code: Select all

['/usr/lib/python2.7/xml']
Thanks.

Re: Python __path__ help

Posted: Sat Jun 18, 2016 9:29 am
by Geoff the Medio
spikethehobbit wrote:Ouch. That looks like a broken python install.
It's not an install... it's the python.exe in the FreeOrion SDK.

Code: Select all

>>> import xml
>>> print xml.__path__
['C:\\Users\\Geoff\\Desktop\\FreeOrion_VS2013_SDK\\FreeOrionTemp\\python27.zip\\xml']

Re: Python __path__ help

Posted: Sat Jun 18, 2016 2:23 pm
by spikethehobbit
Geoff the Medio wrote:
spikethehobbit wrote:Ouch. That looks like a broken python install.
It's not an install... it's the python.exe in the FreeOrion SDK.

Code: Select all

>>> import xml
>>> print xml.__path__
['C:\\Users\\Geoff\\Desktop\\FreeOrion_VS2013_SDK\\FreeOrionTemp\\python27.zip\\xml']
I've never tried the windows version, so there is much I haven't seen before.
That path is both what I expected, and was afraid of. I can work with this.

Thank you.

Re: Python __path__ help

Posted: Sun Jun 19, 2016 8:24 am
by Vezzra
Mac OSX:

Code: Select all

Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> print ctypes.__path__
['/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes']
>>> 
However, this is what you get when launching the system installed Python. On Mac (as on Windows) FO ships with its own Python runtime environment, so the paths you'll get when FO runs its Python scripts are of course different.

Re: Python __path__ help

Posted: Tue Jun 21, 2016 8:30 am
by spikethehobbit
My main concern was the formatting. Mac and Linux use Unix format paths, while Windows uses it's own. That has implications for my planned python modularization scheme, since the proper path to the 'default/python' folder needs to be passed in through `freeorion.__path__`. Windows will need special handling (as expected) but Mac looks like it won't.

The other sticky issue is the current `--ai-path` option. I can jury-rig it into the new framework, or change it to a '--script-path' option for the whole python tree, but I'm not sure which the ai-devs would prefer, and I'm not sure where to ask.

Re: Python __path__ help

Posted: Tue Jun 21, 2016 7:38 pm
by LGM-Doyle
spikethehobbit have you looked in freeorion/utils/Directories.cpp?

It uses boost/filesystem which handles all of the differing OS path formatting issues internally.

Make keeping up with the vagaries of OS's filesystems someone else's maintenance problem.

Re: Python __path__ help

Posted: Wed Jun 22, 2016 10:10 am
by spikethehobbit
That is what I will wind up using, but I needed to be sure that native paths were actually being used. Thanks for the link to the proper file, though. I was just looking for it when I saw your post.

Re: Python __path__ help

Posted: Sun Jun 26, 2016 1:06 pm
by Cjkjvfnby
spikethehobbit wrote:Some proposed changes to the python interface use the `__path__` variable, but I am unsure how this variable works on different platforms. It would be helpful if a Windows and a Mac user could each post the output of this script:

import ctypes
print ctypes.__path__

On Linux, it produces
['/usr/lib/python2.7/ctypes']
FYI freeorion have interactive python console for AI code:
  • start game
  • print help in chat

Re: Python __path__ help

Posted: Fri Jul 01, 2016 10:35 am
by spikethehobbit
print help in chat
Thank you.