Creating a binder for a repository containing both setup.py and environment.yaml

Dear Binder aficionados,

I created a binder for my python package hosted on GitHub.

In a couple of days I am giving a tutorial and would like people to run the notebooks inside docs/tutorials in the repo.

The problem is the following: a couple of notebooks show how to wrap my package with an external package that is not part of the core dependencies (sherpa).
Being not among the core dependencies, and hence not in the setup.py's install_requires, the binder image (relying on the setup.py) was built without this additional package.

In order to solve this I created an environment.yaml (it’s in the repo) containing this additional external dependency. Still, when I re-launch binder, the setup.py and not the environment.yaml is used. Therefore I cannot execute in binder my example notebooks with the wrapper - the additional package is missing.

Any suggestion? Is there a way to specify to binder which build method has to be used?

I know you can add optional dependencies in setup.py, I am not sure though binder will run the appropriate extra command (e.g. python setup.py[with_sherpa]) when building.

Many thanks in advance,
Cosimo

The easiest would be to put the follwoing towards the top of your notebooks demonstrating wrapping:

%pip install sherpa

I assume it is Python package based on the description, but if it needs conda substitute conda in place of pip.

That way it runs before you need it and install it in the session environment at that time.


The other way would be to make a binder directory and put your environment.yml file there and specify installing your package there via addition of pip to environment.yml. Here’s an example of using pip in environment.yml that just happens to be one I have handy. Putting configuration files outside of root is covered in the documentation here.

1 Like

Thanks for your help @fomightez!
The environment.yaml was ignored because the extension accepted by Binder is .yml.
Renaming environment.yaml to environment.yml fixed it.
And actually the environment.yml takes precedence over the setup.py.

Thanks

I routinely use repos with an environment.yml specifying “.” as
pip dependency, which triggers the setup.py. See e.g.:

Would that work for you?

2 Likes

Yes, I was considering putting my concern of you talking about .yaml in my reply; however, when I looked I thought you had fixed it already, and so I thought the issue may have remained. Still, the issues your post raised are good concepts to discuss and have examples highlighted on this forum.