[Pythonmac-SIG] Using slash-seperated paths for creating FSSpecs (was: Mach-O MacPython IDE!!!)

Donovan Preston dp@ulaluma.com
Fri, 21 Dec 2001 17:56:45 -0800


On Friday, December 21, 2001, at 01:44 PM, Jack Jansen wrote:
>
> Recently, Donovan Preston <dp@ulaluma.com> said:
>> Hmm. Well, I suppose the only way to get around this is to explicitly
>> state which type of path is being used as Jack suggested, or to always
>> assume slash-delimited paths on X and colon-delimited paths on 9.
>
> I assume you mean "MacPython" where you say 9 and "MachoPython" where
> you say X, right? Pathname interpretation is more a function of the
> runtime library than of the OS, in the case of Python.

Yes, correct, sorry. So I should have said "Always assume 
slash-delimited paths on Mach-O Python and colon-delimited paths on CFM 
MacPython."

>> Since os.path.join creates slash-delimited strings on X, all of the
>> places in the IDE where there is code that looks like
>> os.path.join(rootdir, 'my:subdir:etc') are going to have to be replaced
>> anyway. I suggest replacing them with os.path.join(*[rootdir, 'my',
>> 'subdir', 'etc']) which works no matter what OS you are running under.
>
> Or, alternatively, use macpath. Os.path is great to get rid of
> platform dependencies, but only if you add single components. If
> you're using my:subdir:etc you have a Mac dependency anyway, so
> there's little to be gained from using os.path.

Ah. I wasn't aware there was a macpath module which would do 
colon-delimiting even on X. Hmm. At first glance I thought that might 
work, but upon further inspection I recall why sticking to 
colon-delimited paths won't work on Mach-O MacPython:

There are constructions throughout the IDE that look like this:

	widgetresfile = os.path.join(sys.exec_prefix, 
":Mac:Tools:IDE:Widgets.rsrc")

Since sys.exec_prefix is specified as a slash-delimited string, even 
macpath won't help here. And I am strongly opposed to making 
sys.exec_prefix return a colon-delimited string :-) And rather than 
convert any slash-delimited string such as sys.exec_prefix to a 
colon-delimited string prior to using macpath.join, I still contest that 
it's better to use os.path.join and construct your path segments in a 
platform agnostic way. Maybe this syntax will be a little more to your 
(non-obfuscated) liking ;-)

pathsegments = [sys.exec_prefix, 'Mac', 'Tools', 'IDE']
path = os.path.join(*pathsegments)

Then, the resulting path can be passed to the new FSSpec_New, after it's 
been updated to conform to your pseudocode, no matter what runtime you 
are running under and it will work.

Donovan