quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Graham Dumpleton (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MODPYTHON-143) Implement and integrate a new module importer.
Date Sun, 13 Aug 2006 23:36:14 GMT
    [ http://issues.apache.org/jira/browse/MODPYTHON-143?page=comments#action_12427786 ] 
Graham Dumpleton commented on MODPYTHON-143:

The new module importer implements a feature whereby if using apache.import_module() or the
'import' statement, that it will first look in the same directory as the code file exists
for the target module. This brings it in line with how things normally work for Python modules
outside of mod_python and should eliminate the hacks people have had to do in the past involving
setting PythonPath directive to directories which are a part of the document tree exposed
by mod_python.

The only problem with making it look in the same directory first is that it changes the behaviour
for code published using mod_python.publisher (and other cases, but this is most visible),
where the published code was in some subdirectory of  the root directory for which the PythonHandler
directive was specified. Previously when the import was done, the expectation was (although
the randomness of sys.path meant it may not have been the case in practice) that the root
directory for where the handler directive was specified would be checked and then anywhere
else on sys.path. That is, it wouldn't look in the same directory first when it was in a subdirectory.

What this means is that if the subdirectory contained a sibling code file called 'random.py'
and the first code file tried to import 'random', the 'random.py' file in the same directory
would be ignored and instead it would go off any use the 'random' module distributed with
Python instead. With the new importer though it will look in the same directory first, resulting
in a greater risk that file local to the directory will hide and prevent the importing of
a standard Python module.

A mechanism is therefore need to resolve such clashes and state that any imports from a specific
file should ignore some or perhaps all modules in the same directory when performing an import.

The simplest way of doing this would be to allow a code file to specify a special global variable
listing any module or file names from the current directory which should be ignored. For example
something like:

  __mp_ignore_local_modules__ = ['random']

  import random

Might need to come up with a better name for the global variable though.

> Implement and integrate a new module importer.
> ----------------------------------------------
>                 Key: MODPYTHON-143
>                 URL: http://issues.apache.org/jira/browse/MODPYTHON-143
>             Project: mod_python
>          Issue Type: Task
>          Components: importer
>    Affects Versions: 3.2.8
>            Reporter: Graham Dumpleton
>         Assigned To: Graham Dumpleton
>             Fix For: 3.3
> This is an overall task to cover the issue of rectifying the various module importer
issues by replacing it with a new implementation. A description of the various problems can
be found in:
>   http://www.dscpl.com.au/articles/modpython-003.html
> Separate issues had already been created for some of the specific problems. These issues
will now be linked to this problem and thus marked as being dependent on this issue.
> In other words, replacing the module importer will solve a number of number issues. Rather
than try and keep up to date all the separate issues, all information about the replacement
will be put against this issue instead.
> Note that there are also some issues which are not directly related to the module importer
but which will be made dependent on this issue because it is easier to fix the issue as part
of the rewrite of the module importer and top level handler dispatch mechanism than it is
to address it as a distinct item.
> In respect of what impacts the new module importer implementation may have and how it
is used may change, this will be documented in the following document for the time being:
>   http://www.dscpl.com.au/articles/modpython-007.html
> Note that this document is a work in progress. It is dense reading and assumes you know
a bit about the current module importer and its problems. Any significant issues raised by
this document can be added here as a comment, or if a general dicussion of a topic is needed,
raise the issue on the mod_python developers mailing list.
> A possible new implementation for the module importer is basically ready for testing
and experimentation. The intent is to push it into the mod_python source tree, but for its
use to be optional. 
> If wanting to enable it for a specific Python interpreter, the PythonImport directive
would be used:
>   PythonImport mod_python.future.importer mytestinterpreter
> If wanting to enable it for all Python interpreters, a PythonOption directive would be
used at global scope within the Apache configuration. Ie., outside of all Location, Directory
or Files container directives. The exact option name to be used hasn't yet been decided.
> More details and announcements at the appropriate time.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message