Hi,
thinking about adding python import functionality to pyuno during the
last years, I have come to the proposal outlined in
http://www.openoffice.org/issues/show_bug.cgi?id=76281
.
The solution is very simple and solves imho 90% of what can be solved. I
have spent a lot of time thinking about how to solve the last 10%, but
all this ends doing in a lot of coding in the OOo unopkg tool, which I
wont be able to do in the next years ...
Let me know, what you think about it.
As another issue has to be fixed first (see below), I cannot say, when
this can be integrated into ooo codebase.
Bye,
Joerg
------------
Current situation:
A python uno component must be self contained in a single
python source file, meaning that it can only import
other python modules, that are in the office pythonpath.
In general, there are just the modules offered by the
python runtime (though you can extend the pythonpath
via the pythonloader.uno[.ini|rc] in the program directory).
A uno component itself is not added to sys.modules.
This is a strong limitation for the python component, because
- you can't split your component implementation into multiple source
files
when a certain complexity level is reached
- you can't use 3rd party python libraries
Suggested solution:
Whenever the pythonloader tries to load a new python unocomponent, it looks
beside the uno component for a file with the
name pythonpath.zip. If it exists, it puts it into sys.path (if it is not
already in there). Afterwards, it loads
the given component. You can put everything you want to have in
PYTHONPATH into
this zip-file. This is necessary,
as otherwise every file with a .py suffix would be interpreted as a python
component, packages would fail during the
registration process.
Positive effects:
* Uno components can be implemented with an arbirtrary number of
python source
files.
* The uno package mechanism allows them to be cleanly added/removed
* The implementation is short and simple (see below)
Negative effects:
* Storing these files in another zip-File is a hurdle for developers, but
can be overcome with simple packaging scripts.
Undesired Side effects:
* (cannot be changed, as python does not have a classloader
concept): Two
independend uno packages from different
developers may interfere each other, when they have name clashes in
their
code (e.g. same 3rd party product, but
different versions).
* If such a situation occurs, in general the last used component will
not work
properly
(which one is the last used component may also depend on the path
of user
interactions in the office process)
* The python component remains beside the .zip file.
* Code added through this mechanism can only be changed with a
restart of the
office process (as it got added
to sys.modules).
In order to give this proposal a try, you have to
1) apply the attached patch to the pythonloader.py file
2) Let the attached sample package run
Note: It only works, when you use office on windows or when you use an
office,
that uses the system python installation. With the default OOo build on
unix,
the solution currently fails due to issue
http://www.openoffice.org/issues/show_bug.cgi?id=27026 (no zip
support in OOo's python). This issue must be fixed, before this solution
can be
integrated.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]