alan-turing-institute / CROP

CROP is a Research Observation Platform
MIT License
25 stars 5 forks source link

Make CROP core pip-installable. #410

Closed nbarlowATI closed 1 year ago

nbarlowATI commented 1 year ago

The core directory contains useful database schema and queries, and is used by both the webapp and the ingress functions. It could potentially also be used by the model functions. In order to do that, while avoiding the need to hack the PYTHONPATH or sys.path, we could make the core directory pip-installable. This way we can always import core modules from anywhere else in the directory structure. Perhaps we would want the actual python "package" to be called cropcore, both to avoid potential conflicts with other packages and with the local filesystem version - I think this can be done in setup.py.

@mhauru @dsj976 , any objections to this, or other things we should think about?

dsj976 commented 1 year ago

I think this is a good idea Nick. I can't think of any negative side effects and would definitely solve a few problems.

mhauru commented 1 year ago

The only request I have is that it would remain the case that within the same local copy of the package all imports are relative, to avoid the confusion where I edit some file A.py but forget that the neighbouring file B.py, which has an import A in it, doesn't import that A.py, but rather its now-out-of-date installed version. Maybe the cropcore thing would solve that, although I'm a bit confused (I always find imports and module discovery confusing)?

nbarlowATI commented 1 year ago

Well...... this is an interesting question... We can definitely keep it so that all the imports in modules in core are relative (e.g. in db.py it has from .structure import BASE rather than from cropcore.structure import BASE). BUT, I think for the code in webapp/ and models/ we would be importing from cropcore, i.e. any time you changed something in a core module, you would need to redo pip install .. EXCEPT if you do pip install -e . the first time - this would install "cropcore" in developer mode, make a symbolic link to your local installation in site-packages rather than copying files there. EXCEPT that Stack Overflow seems to suggest that having the package name and directory name different may not work with developer mode..... to be tested! :)