FreeOrion

Forums for the FreeOrion project
It is currently Mon Dec 18, 2017 12:33 pm

All times are UTC




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Python __path__ help
PostPosted: Sat Jun 18, 2016 2:30 am 
Offline
Space Squid

Joined: Mon Aug 27, 2012 7:24 pm
Posts: 57
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']

_________________
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Sat Jun 18, 2016 3:52 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12045
Location: Munich
Code:
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
>>>


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Sat Jun 18, 2016 9:11 am 
Offline
Space Squid

Joined: Mon Aug 27, 2012 7:24 pm
Posts: 57
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:
import xml
print xml.__path__


That one should work even loading from a .zip file.

Mine gives
Code:
['/usr/lib/python2.7/xml']


Thanks.

_________________
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Sat Jun 18, 2016 9:29 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12045
Location: Munich
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:
>>> import xml
>>> print xml.__path__
['C:\\Users\\Geoff\\Desktop\\FreeOrion_VS2013_SDK\\FreeOrionTemp\\python27.zip\\xml']


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Sat Jun 18, 2016 2:23 pm 
Offline
Space Squid

Joined: Mon Aug 27, 2012 7:24 pm
Posts: 57
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:
>>> 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.

_________________
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Sun Jun 19, 2016 8:24 am 
Offline
Release Manager, Design
User avatar

Joined: Wed Nov 16, 2011 12:56 pm
Posts: 4309
Location: Sol III
Mac OSX:
Code:
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.


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Tue Jun 21, 2016 8:30 am 
Offline
Space Squid

Joined: Mon Aug 27, 2012 7:24 pm
Posts: 57
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.

_________________
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Tue Jun 21, 2016 7:38 pm 
Offline
Programmer

Joined: Mon Feb 29, 2016 8:37 pm
Posts: 205
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.


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Wed Jun 22, 2016 10:10 am 
Offline
Space Squid

Joined: Mon Aug 27, 2012 7:24 pm
Posts: 57
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.

_________________
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Sun Jun 26, 2016 1:06 pm 
Offline
AI Contributor
User avatar

Joined: Tue Jun 24, 2014 9:55 pm
Posts: 444
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

_________________
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0


Top
 Profile  
 
 Post subject: Re: Python __path__ help
PostPosted: Fri Jul 01, 2016 10:35 am 
Offline
Space Squid

Joined: Mon Aug 27, 2012 7:24 pm
Posts: 57
Quote:
print help in chat


Thank you.

_________________
All contributions are submitted under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidlines.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group