Skip to content

Commit 8bc8d37

Browse files
authored
Merge pull request #26 from repo2wasm/24-notebook-link
Implement support to Notebook.link
2 parents a10ad3c + 1177684 commit 8bc8d37

File tree

9 files changed

+409
-306
lines changed

9 files changed

+409
-306
lines changed

.github/workflows/pypi-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v6
1313
- uses: prefix-dev/setup-pixi@v0.9.3
1414
with:
15-
pixi-version: v0.56.0
15+
pixi-version: v0.62.2
1616
cache: true
1717
- name: Publish to PyPI
1818
env:

.github/workflows/test-examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- uses: actions/checkout@v6
2727
- uses: prefix-dev/setup-pixi@v0.9.3
2828
with:
29-
pixi-version: v0.56.0
29+
pixi-version: v0.62.2
3030
cache: true
3131
- name: Test example
3232
run: pixi run repo2wasm ${{ matrix.example_path }} --no-run

.github/workflows/unittest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- uses: actions/checkout@v6
1818
- uses: prefix-dev/setup-pixi@v0.9.3
1919
with:
20-
pixi-version: v0.56.0
20+
pixi-version: v0.62.2
2121
cache: true
2222
- name: Test example
2323
run: pixi run test

docs/source/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## 0.7.0
44

5+
### Enhancements made
6+
7+
- Support configuration files in `.nblink`
8+
59
## 0.6.0
610

711
### Enhancements made

docs/source/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
`repo2wasm` is a clone of [`jupyter-repo2docker`] targeting [WebAssembly](https://en.wikipedia.org/wiki/WebAssembly) (Wasm) environment. If [`jupyter-repo2docker`] is a wrapper around [Docker Engine](https://docs.docker.com/engine/), `repo2wasm` is a wrapper around [JupyterLite].
44

5-
```{important}
5+
```{hint}
66
Only programming languages already compiled to Wasm are supported, more details in the section "[](#supported-programming-languages)".
77
```
88

docs/source/user-guide/supported-configuration-files.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,46 @@
22

33
# Supported configuration files
44

5-
## Users
5+
## Configuration file location
6+
7+
The supported configuration files are searched in the following directories:
8+
9+
- `.binder`
10+
- `binder`
11+
- `.` (root of the project)
12+
- `.nblink`
13+
14+
### Root of project
15+
16+
![status: implemented](https://img.shields.io/badge/status-implemented-green)
17+
![version: 0.3.0](https://img.shields.io/badge/version-0.3.0-blue)
18+
19+
### `binder` folder
20+
21+
![status: implemented](https://img.shields.io/badge/status-implemented-green)
22+
![version: 0.3.0](https://img.shields.io/badge/version-0.3.0-blue)
23+
24+
The `binder` folder **must** be at the root of your project.
25+
26+
### `.binder` folder
27+
28+
![status: implemented](https://img.shields.io/badge/status-implemented-green)
29+
![version: 0.3.0](https://img.shields.io/badge/version-0.3.0-blue)
30+
31+
The `.binder` folder **must** be at the root of your project.
32+
33+
### `.nblink` folder
34+
35+
![status: implemented](https://img.shields.io/badge/status-implemented-green)
36+
![version: 0.7.0](https://img.shields.io/badge/version-0.7.0-blue)
37+
38+
The `.nblink` folder **must** be at the root of your project.
39+
40+
```{error}
41+
The `.nblink` folder is not searched by `jupyter-repo2docker` used by [mybinder.org](https://mybinder.org).
42+
```
43+
44+
## Configuration file for users
645

746
### `environment.yml`
847

@@ -43,7 +82,7 @@ More details in [repo2docker > User guide > install.R - Install R packages](http
4382

4483
More details in [repo2docker > User guide > Project.toml - Install a Julia environment](https://repo2docker.readthedocs.io/en/latest/configuration/research/#project-toml-install-a-julia-environment).
4584

46-
## Package Developers
85+
## Configuration file for package developers
4786

4887
### `Pipfile` and/or `Pipfile.lock`
4988

@@ -63,7 +102,7 @@ More details in [repo2docker > User guide > setup.py - Install Python packages](
63102

64103
More details in [repo2docker > User guide > DESCRIPTION - Install as an R package](https://repo2docker.readthedocs.io/en/latest/configuration/research/#description-install-as-an-r-package).
65104

66-
## System-wide configuration
105+
## Configuration file for system-wide configuration
67106

68107
### `apt.txt`
69108

@@ -89,7 +128,7 @@ More details in [repo2docker > User guide > default.nix - the nix package manage
89128

90129
More details in [repo2docker > User guide > Dockerfile - Advanced environments](https://repo2docker.readthedocs.io/en/latest/configuration/system/#dockerfile-advanced-environments).
91130

92-
## Post-build actions
131+
## Configuration file for post-build actions
93132

94133
### `postBuild`
95134

pixi.lock

Lines changed: 313 additions & 275 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ description = "Build source into Python package"
6060
cmd = "rm -rf dist; python -m build"
6161

6262
[tool.pixi.feature.release.tasks.upload]
63-
description = "Upload package to PyPI"
63+
description = "Upload package to PyPI"
6464
cmd = "python3 -m twine upload --repository pypi dist/*"
6565
depends-on = ["build"]
6666

src/repo2wasm/binder.py

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,61 @@
77

88
logger = logging.getLogger(__name__)
99

10-
ALLOWED_BINDER_DIR = [".binder", "binder", "."]
10+
# As documented in https://repo2docker.readthedocs.io/en/latest/specification/
11+
ALLOWED_REPO2DOCKER_DIR = [".binder", "binder", "."]
1112

12-
ALLOWED_BINDER_CONFIGURATION_MAPPING = {
13+
ALLOWED_REPO2DOCKER_CONFIGURATION_MAPPING = {
1314
"environment.yml": CondaBuildPack,
1415
"requirements.txt": RequirementsBuildPack,
1516
"install.R": InstallBuildPack,
1617
}
1718

19+
# As documented in https://notebook.link/docs/user-guide/enable-your-github-repository#define-the-environment
20+
ALLOWED_NOTEBOOK_LINK_DIR = [".nblink", "."]
1821

19-
def find_configuration_file(path_to_repository):
20-
for configuration_file in ALLOWED_BINDER_CONFIGURATION_MAPPING:
21-
for binder_dir in ALLOWED_BINDER_DIR:
22-
file_path = os.path.join(path_to_repository, binder_dir, configuration_file)
23-
logger.debug("Searching for %s ...", file_path)
24-
if os.path.isfile(file_path):
25-
logger.debug("Found %s", file_path)
26-
return file_path
22+
ALLOWED_NOTEBOOK_LINK_CONFIGURATION_MAPPING = {
23+
"environment.yml": CondaBuildPack,
24+
}
2725

28-
raise RuntimeError("Configuration file not found.")
26+
CONFIGURATION_PROVIDERS = {
27+
"repo2docker": (ALLOWED_REPO2DOCKER_CONFIGURATION_MAPPING, ALLOWED_REPO2DOCKER_DIR),
28+
"notebook.link": (
29+
ALLOWED_NOTEBOOK_LINK_CONFIGURATION_MAPPING,
30+
ALLOWED_NOTEBOOK_LINK_DIR,
31+
),
32+
}
2933

3034

3135
def get_buildpack(path_to_repository, ide, output_dir, forgiving=False):
32-
configuration_file_path = find_configuration_file(path_to_repository)
36+
configuration_file_path = None
37+
BuildPack = None
38+
39+
for provider, (
40+
configuration_mapping,
41+
allowed_dir,
42+
) in CONFIGURATION_PROVIDERS.items():
43+
logger.debug("Testing for %s as provider ...", provider)
44+
for configuration_file in configuration_mapping:
45+
for binder_dir in allowed_dir:
46+
file_path = os.path.join(
47+
path_to_repository, binder_dir, configuration_file
48+
)
49+
logger.debug("Searching for %s ...", file_path)
50+
if os.path.isfile(file_path):
51+
logger.debug("Found %s", file_path)
52+
configuration_file_path = file_path
53+
BuildPack = configuration_mapping[configuration_file]
54+
break
55+
56+
if configuration_file_path is not None:
57+
break
3358

34-
configuration_file = os.path.basename(configuration_file_path)
59+
if configuration_file_path is not None:
60+
break
3561

36-
for (
37-
buildpack_configuration_file,
38-
BuildPack,
39-
) in ALLOWED_BINDER_CONFIGURATION_MAPPING.items():
40-
if configuration_file == buildpack_configuration_file:
41-
return BuildPack(
42-
path_to_repository, configuration_file_path, ide, output_dir, forgiving
43-
)
62+
if configuration_file_path is None:
63+
raise RuntimeError("Configuration file not found.")
4464

45-
raise RuntimeError("Build pack not found.")
65+
return BuildPack(
66+
path_to_repository, configuration_file_path, ide, output_dir, forgiving
67+
)

0 commit comments

Comments
 (0)