"Loris Bennett" <loris.benn...@fu-berlin.de> writes:

> Hi,
>
> The following is a little bit involved, but I hope can make the problem clear.
>
> Using poetry I have written a dummy application which just uses to typer
> to illustrate a possible interface design.  The directory structure is a
> follows: 
>
>   $ tree -P *.py
>   .
>   |-- dist
>   |-- stoat
>   |   |-- hpc
>   |   |   |-- database.py
>   |   |   |-- group.py
>   |   |   |-- __init__.py
>   |   |   |-- main.py
>   |   |   |-- owner.py
>   |   |   `-- user.py
>   |   |-- __init__.py
>   |   |-- main.py
>   |   `-- storage
>   |       |-- database.py
>   |       |-- group.py
>   |       |-- __init__.py
>   |       |-- main.py
>   |       |-- owner.py
>   |       |-- share.py
>   |       `-- user.py
>   `-- tests
>       |-- __init__.py
>       `-- test_stoat.py
>
> With in the poetry shell I can run the application successfully:
>
>   $ python stoat/main.py hpc user --help                                      
>                                      
>   Usage: main.py hpc user [OPTIONS] COMMAND [ARGS]...
>
>     manage HPC users
>
>   Options:
>     --help  Show this message and exit.
>
>   Commands:
>     add     add a user
>     remove  remove a user
>
> I then install this in a non-standard path (because the OS Python3 is
> 3.6.8) and can run the installed version successfully:
>
>   $ PYTHONPATH=/trinity/shared/zedat/lib/python3.9/site-packages python 
> /trinity/shared/zedat/lib/python3.9/site-packages/stoat/main.py hpc user 
> --help
>   Usage: main.py hpc user [OPTIONS] COMMAND [ARGS]...
>
>     manage HPC users
>
>   Options:
>     --help  Show this message and exit.
>
>   Commands:
>     add     add a user
>     remove  remove a user
>
> However, poetry creates a script 'stoat' from the entry
>
>   [tool.poetry.scripts]
>   stoat = "stoat.main:main"
>
> in pyproject.toml, which looks like
>
>   
> #!/trinity/shared/easybuild/software/Python/3.9.6-GCCcore-11.2.0/bin/python3.9
>   # -*- coding: utf-8 -*-
>   import re
>   import sys
>   from stoat.main import main
>   if __name__ == '__main__':
>       sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
>       sys.exit(main())
>
> If I run that I get 
>
>   $ PYTHONPATH=/trinity/shared/zedat/lib/python3.9/site-packages stoat hpc 
> user --help
>   Traceback (most recent call last):
>     File "/trinity/shared/zedat/bin/stoat", line 5, in <module>
>       from stoat.main import main
>     File "/trinity/shared/zedat/lib/python3.9/site-packages/stoat/main.py", 
> line 3, in <module>
>       import hpc.main
>   ModuleNotFoundError: No module named 'hpc'
>
> Why is the module 'hpc' not found by the poetry script?

Never mind, I worked it out.  I had to replace 

  import hpc.main

with

  import stoat.hpc.main

However, this raises the question of why it worked in the first place
in the poetry shell. 

Cheers,

Loris

-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to