Pythonic Idiom For Searching An Include Path
Tim Daneliuk
tundra at tundraware.com
Fri Jun 25 08:52:28 EDT 2010
On 6/25/2010 7:25 AM, Jorgen Grahn wrote:
> On Thu, 2010-06-24, Nobody wrote:
>> On Wed, 23 Jun 2010 17:27:16 -0500, Tim Daneliuk wrote:
>>
>>> Given a program 'foo' that takes a command line argument '-I
>>> includefile', I want to be able to look for 'includefile' in a path
>>> specified in an environment variable, 'FOOPATH'.
>>>
>>> I'd like a semantic that says:
>>>
>>> "If 'includefile' contains one or more path separator characters,
>>> ignore 'FOOPATH'. If it contains no path separators, look for it in
>>> the paths specified by 'FOOPATH', beginning with the leftmost path
>>> first."
>>>
>>> Is there a standard Pythonic idiom for doing this or do I need to cook
>>> up my own.
>>
>> There isn't an idiom.
>>
>> There are a surprising number of choices for such a simple task, e.g.
>> whether the search path is used for relative paths containing a separator,
>> whether you stop at the first file which exists or the first file which
>> meets other criteria (e.g. suitable permissions), whether default
>> locations come first or last, what happens if a default location is
>> included in the search path, etc.
>
> Another favorite is whether relative paths are relative to your
> current directory, or to the location of whatever file this is to be
> included /into/.
>
> For an example where it mattered (to C compilers), google for the
> paper "recursive make considered harmful". It took compiler writers
> decades to realize what the best choice was there.
>
> (By the way, -I commonly means "search this directory for include
> files" rather than "include this file". You may want to avoid
> confusing people by choosing another letter, like -i.)
>
> /Jorgen
>
I just went ahead and implemented my own. It will eventually find it's way
to:
http://www.tundraware.com/Software/tsearchpath/
I'll post on c.l.p.a when the thing is released into the wild.
Thanks to all that took the time to respond...
--
----------------------------------------------------------------------------
Tim Daneliuk tundra at tundraware.com
PGP Key: http://www.tundraware.com/PGP/
More information about the Python-list
mailing list