You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ponymail.apache.org by GitBox <gi...@apache.org> on 2021/05/09 08:55:36 UTC

[GitHub] [incubator-ponymail-foal] sbp opened a new pull request #23: Fix imports in the scripts in tools

sbp opened a new pull request #23:
URL: https://github.com/apache/incubator-ponymail-foal/pull/23


   The Python files in the `tools` directory are written to be run as scripts from that directory. This means that the `archiver.py` file doesn't work when installed as a package, which its own documentation advises, because it cannot find the `plugins` directory when imported as a package rather than run as a script.
   
   The obvious solution to this is to change the `plugins` imports in `archiver.py` to be relative dotted imports, but this then causes `archiver.py` to fail when it is imported from the `import-mbox.py` script.
   
   The problem is that Python [really doesn't like](https://stackoverflow.com/questions/16981921/relative-imports-in-python-3) files being used as both scripts and package modules. There have been many suggested workarounds for this over the years, with varying levels of complexity. This PR takes the [simple approach](https://stackoverflow.com/a/49480246) of using relative dotted imports only if `__package__` is set.
   
   A more advanced solution would be to treat `tools` as a package which can be installed using pip. This would require much more effort, but would probably be easier for end users. In lieu of that, this PR also adds a simple `__init__.py` file which imports from `archiver.py`, so that installing `tools` as a package now only requires copying the whole directory instead of also copying `archiver.py` to `__init__.py`.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-ponymail-foal] Humbedooh merged pull request #23: Fix imports in the scripts in tools

Posted by GitBox <gi...@apache.org>.
Humbedooh merged pull request #23:
URL: https://github.com/apache/incubator-ponymail-foal/pull/23


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org