Skip to content

Commit a8e6761

Browse files
committed
Support fsspec specifiers for ScriptCreator NBs
Addresses #42
1 parent 464e81a commit a8e6761

5 files changed

Lines changed: 28 additions & 6 deletions

File tree

docs/xcetool.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ details on usage and available options.
1313

1414
Usage: `xcetool image build [OPTIONS] NOTEBOOK`
1515

16-
This is the main `xcetool` subcommand: it builds a container image from a supplied
17-
notebook and environment file. If given the `--eoap` argument, it also generates
18-
a CWL file defining a corresponding application package.
16+
This is the main `xcetool` subcommand: it builds a container image from a
17+
supplied notebook and environment file. If given the `--eoap` argument, it also
18+
generates a CWL file defining a corresponding application package. The
19+
NOTEBOOK argument can be a path to a local file, a URL, or any other string
20+
which can be parsed by the [fsspec](https://filesystem-spec.readthedocs.io/)
21+
library.
1922

2023
Options:
2124

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies:
1818
- cwltool
1919
- pytest
2020
- pytest-cov
21+
- pytest-httpserver
2122
- pytz
2223

2324
# Note: xcube is not required for the conversion itself, but is required

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ dev = [
5757
"cwltool",
5858
"pytest",
5959
"pytest-cov",
60+
"pytest-httpserver",
6061
"pytz"
6162
]
6263
doc = [

test/test_core.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,16 @@ def test_script_creator_notebook_config():
351351
assert config["container_image_tag"] == "my-tag"
352352

353353

354+
def test_script_creator_notebook_config_http(httpserver):
355+
http_path = "/mynotebook.ipynb"
356+
nb_path = pathlib.Path(__file__).parent / "data" / "paramtest.ipynb"
357+
httpserver.expect_request(http_path).respond_with_data(nb_path.read_bytes())
358+
script_creator = ScriptCreator(httpserver.url_for(http_path))
359+
config = script_creator.nb_params.config
360+
assert config["environment_file"] == "my-environment.yml"
361+
assert config["container_image_tag"] == "my-tag"
362+
363+
354364
def test_image_builder_notebook_config(tmp_path):
355365
nb_path = pathlib.Path(__file__).parent / "data" / "paramtest.ipynb"
356366
image_builder = ImageBuilder(nb_path, None, tmp_path, None)

xcengine/core.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from docker.errors import BuildError
2424
from docker.models.containers import Container
2525
from docker.models.images import Image
26+
import fsspec
2627
import nbconvert
2728
import nbformat
2829
import yaml
@@ -37,13 +38,19 @@
3738
class ScriptCreator:
3839
"""Turn a Jupyter notebook into a set of scripts"""
3940

40-
nb_path: pathlib.Path
41+
nb_path: pathlib.Path | str
4142
notebook: nbformat.NotebookNode
4243
nb_params: NotebookParameters = NotebookParameters({})
4344

44-
def __init__(self, nb_path: pathlib.Path):
45+
def __init__(self, nb_path: pathlib.Path | str):
46+
"""
47+
Instantiate a ScriptCreator for a specified notebook
48+
49+
:param nb_path: filesystem path or fsspec-parseable specifier
50+
(e.g. HTTP URL) to the input notebook
51+
"""
4552
self.nb_path = nb_path
46-
with open(nb_path) as fh:
53+
with fsspec.open(str(nb_path)) as fh:
4754
self.notebook = nbformat.read(fh, as_version=4)
4855
self.process_params_cell()
4956

0 commit comments

Comments
 (0)