klaundal / lompe

MIT License
12 stars 8 forks source link

Make into a package and add binder configuration #2

Closed smithara closed 1 year ago

smithara commented 1 year ago

I had a look at setting this up with mybinder.org

I'm not sure how the PYTHONPATH plays with conda so I added the configuration to make it into a package. That just needed the new pyproject.toml file but also the modules had to move into a lompe subdirectory. Doing this means that the lompe code can just be installed in-place from the cloned repository (pip install -e .). This might interfere with your current way of working(?)

The environment.yml and postBuild in the binder directory provide the configuration that enables the notebooks to run (more info here). The environment.yml also loosely fixes package versions so there is a reasonable level of reproducibility and that can also be used to create an environment locally.

These changes enable the examples to be run directly at https://mybinder.org/v2/gh/smithara/lompe/binderize (it's a bit flakey so might need a few retries) which can be helpful both as a demo for prospective users, and as a test against the "works on my machine" problem

klaundal commented 1 year ago

Hi Ashley,

This is great! I will merge the pull request, but I first tried to install your branch on my system to check that everything runs. I ran into a problem with importing the submodules after they had moved, and couldn't figure out if this should be possible, or if the init file(s) have to be changed. Are you able to import lompe with the new structure?

smithara commented 1 year ago

Hmm I'm pretty sure it's working. I'm able to import them and run the notebooks in code_paper_figures. I tested it again with:

git clone https://github.com/smithara/lompe.git
cd lompe
git checkout binderize
git submodule init
git submodule update
mamba env create --name lompe_test --file binder/environment.yml
mamba activate lompe_test
pip install -e .[extras]
python -c "import lompe; import lompe.dipole; import lompe.polplot; import lompe.secsy"

Do you mean importing dipole etc directly? rather than as submodules of lompe?

klaundal commented 1 year ago

Ah! I had missed a lot of that.

I will merge and put the install instructions in the readme. I also checked that it can be run without an install if the repository root directory is in PYTHONPATH.

Really nice! Thank you!