SCM-NV / pyZacros

Python Library for Automating Zacros Simulations
Other
7 stars 2 forks source link

Why is __init__ in package root? #65

Closed stefsmeets closed 2 years ago

stefsmeets commented 2 years ago

I updated to the latest version and I noticed all my scripts are now broken. This seems to be a result of #64, which moves the entire package structure up one level. Now __init__.py and all modules are in the package root. Before they were in the pyzacros subdirectory.

This breaks all my code depending on pyzacros. Every statement such as:

from pyzacros.core.Species import Species

Now becomes:

from core.Species import Species

To me this is really odd in a python package. As a user, if I install pyZacros I'd expect to be able to import it as pyzacros.

But, I can also do:

import tests
import setup
import examples
import doc
import __version__

from anywhere on my system. This can cause some really nasty issues with name collisions with other packages.

For now I will revert to the latest working version, but I hope this change can be reversed in a future update.

bas-rustenburg commented 2 years ago

Hi Stef,

I think you should be able to import it as pyzacros. How are you installing/importing it?

What works for me is

  1. I clone the github repo, and cd into the folder.
  2. I use pip install -e . on that folder
  3. python -c "import pyzacros; print(pyzacros.__version__)" should print out the version string

Alternatively pip install -e git+https://github.com/SCM-NV/pyZacros.git#egg=pyzacros To install without checking out manually, seems to work for me.

I think python setup.py install should also work.

stefsmeets commented 2 years ago

I installed it using pip install -e ..

bas-rustenburg commented 2 years ago

Did a little testing. Something in the python environment that we use within SCM software is making it work. However, using another environment I see the same issue as you are having. The issue seems to go away if I don't use the -e flag. Can you try that instead?

stefsmeets commented 2 years ago

Yeah, that does seem to work. I prefer to have it in editable mode (easier to update/debug that way). I think the offending line is this one: https://github.com/SCM-NV/pyZacros/blob/5856a07ac17dafca739eac556dc31b70bbbbb44e/setup.py#L8 Which does something funny during setup.

bas-rustenburg commented 2 years ago

That particular line is working as intended. It seems that the package_dir option is not really well supported in develop mode, from what I can gather by googling.

However, I found a way to get around it. I found that the following helped:

git clone git@github.com:SCM-NV/pyZacros.git pyzacros
pip install -e ./pyzacros

Note the lowercase name, like the package. Now, importing pyzacros works for me.