Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .binder directory #653

Merged
merged 8 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The philosophy for the repo2docker buildpacks includes:
- using common configuration files for familiar installation and packaging tools
- allowing configuration files to be combined to compose more complex setups
- specifying default locations for configuration files
(the repository's root directory or .binder directory)
(in the repository's root, `binder` or `.binder` directory)


When designing `repo2docker` and adding to it in the future, the
Expand Down
7 changes: 4 additions & 3 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ specify the ``branch-name`` or ``commit-hash``. For example::
Where to put configuration files
================================

``repo2docker`` will look for configuration files in either:
``repo2docker`` will look for configuration files in:

* A folder named ``binder/`` in the root of the repository.
* A folder named ``.binder/`` in the root of the repository.
* The root directory of the repository.

If the folder ``binder/`` is located at the top level of the repository,
only configuration files in the ``binder/`` folder will be considered.
`repo2docker` searches for these folders in order (``binder/``, ``.binder/``,
root). Only configuration files in the first identified folder are considered.

Check the complete list of :ref:`configuration files <config-files>` supported
by ``repo2docker`` to see how to configure the build process.
Expand Down
15 changes: 11 additions & 4 deletions repo2docker/buildpacks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def __init__(self):
self.log = logging.getLogger('repo2docker')
self.appendix = ''
self.labels = {}
self._binder_dir = None
if sys.platform.startswith('win'):
self.log.warning("Windows environment detected. Note that Windows "
"support is experimental in repo2docker.")
Expand Down Expand Up @@ -414,12 +415,18 @@ def get_start_script(self):
"""
return None

@property
def binder_dir(self):
if self._binder_dir is None:
for dirname in ['binder', '.binder']:
if os.path.exists(dirname):
jhamman marked this conversation as resolved.
Show resolved Hide resolved
self._binder_dir = dirname
betatim marked this conversation as resolved.
Show resolved Hide resolved
self._binder_dir = ''
jhamman marked this conversation as resolved.
Show resolved Hide resolved
return self._binder_dir

def binder_path(self, path):
"""Locate a file"""
if os.path.exists('binder'):
return os.path.join('binder', path)
else:
return path
return os.path.join(self.binder_dir, path)

def detect(self):
return True
Expand Down
17 changes: 12 additions & 5 deletions repo2docker/buildpacks/nix/nix-shell-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@ _term() {

trap _term SIGTERM

# find binder sub-directory (if present)
for dir in "./binder" "./.binder"; do
if [ -e $dir ]; then
binder_dir = $dir
fi
done

# if there is a binder/ sub-directory it takes precedence
# files outside it are ignored
if [ -e ./binder ]; then
nixpath="./binder/default.nix";
if [ -f ./binder/start ]; then
chmod u+x ./binder/start
if [ -z $binder_dir ]; then
nixpath="$binder_dir/default.nix";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the failing nix tests it looks like it ends up setting nixpath to /default.nix and then erroring out. Not quite sure why it happens though :-/

if [ -f $binder_dir/start ]; then
chmod u+x $binder_dir/start
# Using `$@`` here which is what the internet recommends leads to
# errors when the command is something like `jupyter --ip=0.0.0.0 ...`
# as nix-shell picks that up as an argument to it instead of the command.
# There are several issues on the nix repos discussing this and adding support
# for -- to indicate "all arguments after this are for the command, not nix-shell"
# but it seems they have stalled/not yet produced an implementation.
# So let's use `$*` for now.
nix-shell $nixpath --command "./binder/start $*" &
nix-shell $nixpath --command "$binder_dir/start $*" &
else
nix-shell $nixpath --command "$*" &
fi
Expand Down
4 changes: 2 additions & 2 deletions repo2docker/buildpacks/python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_assemble_scripts(self):
))

# setup.py exists *and* binder dir is not used
if not os.path.exists('binder') and os.path.exists(setup_py):
if not self.binder_dir and os.path.exists(setup_py):
assemble_scripts.append((
'${NB_USER}',
'{} install --no-cache-dir .'.format(pip)
Expand All @@ -88,6 +88,6 @@ def detect(self):
return True
else:
return False
if not os.path.exists('binder') and os.path.exists(setup_py):
if not self.binder_dir and os.path.exists(setup_py):
return True
return os.path.exists(requirements_txt)
4 changes: 2 additions & 2 deletions repo2docker/buildpacks/r.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def detect(self):
return True

description_R = 'DESCRIPTION'
if ((not os.path.exists('binder') and os.path.exists(description_R))
if ((not self.binder_dir and os.path.exists(description_R))
or 'r' in self.stencila_contexts):
if not self.checkpoint_date:
# no R snapshot date set through runtime.txt
Expand Down Expand Up @@ -300,7 +300,7 @@ def get_assemble_scripts(self):
]

description_R = 'DESCRIPTION'
if not os.path.exists('binder') and os.path.exists(description_R):
if not self.binder_dir and os.path.exists(description_R):
assemble_scripts += [
(
"${NB_USER}",
Expand Down