diff --git a/.eslintignore b/.eslintignore index fffa32f..fcde5f2 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,6 +3,7 @@ dist coverage **/*.d.ts tests +app/build **/__tests__ ui-tests diff --git a/.github/workflows/check-release.yml b/.github/workflows/check-release.yml index a398101..716cc77 100644 --- a/.github/workflows/check-release.yml +++ b/.github/workflows/check-release.yml @@ -15,7 +15,8 @@ jobs: uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - name: Install Dependencies run: | - pip install -e . + # Install dependencies for bump_version script + python -m pip install hatch "jupyterlab~=3.1" - name: Check Release uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v2 with: diff --git a/.prettierignore b/.prettierignore index f6c8db3..5924918 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,3 +3,4 @@ node_modules **/lib **/package.json jupyterlab_rise +app/build diff --git a/examples/jupytext-python.py b/examples/jupytext-python.py index a3cc8d3..889ed29 100644 --- a/examples/jupytext-python.py +++ b/examples/jupytext-python.py @@ -22,7 +22,7 @@ # # using jupytext # %% [markdown] -# if you have jupytext enabled, you can use RISE in a usual manner +# if you have jupytext enabled, you can use RISE in a usual manner # on notebooks that are stored as `.py` or `.md` (or other extensions, for that matter). # %% [markdown] {"slideshow": {"slide_type": "slide"}} @@ -35,35 +35,36 @@ # the only notable difference is for locating the notebook-specific CSS file # %% [markdown] -# of course, and as you might expect, if your notebook -# is called either `mynotebook.py` or `mynotebook.md`, -# or, here again, any other extension -# then it is `mynotebook.css` that is used, +# of course, and as you might expect, if your notebook +# is called either `mynotebook.py` or `mynotebook.md`, +# or, here again, any other extension +# then it is `mynotebook.css` that is used, # if it exists, to load a notebook-specific CSS # %% [markdown] {"slideshow": {"slide_type": "slide"}} # ## pros and cons # %% [markdown] -# jupytext is supercool if you use git a lot, and you don't carre about saving cell outputs +# jupytext is supercool if you use git a lot, and you don't carre about saving cell outputs # no need anymore to run `nbstripout` all the f... time + # %% {"cell_style": "split"} # you can still embed code of course def syracuse(n): - while n != 1: + while n != 1: if n % 2 == 0: n //= 2 yield n else: - n = 3*n + 1 + n = 3 * n + 1 yield n # %% {"cell_style": "split"} # but the output is no longer stored for n in (4, 8, 27): - print(f'n=${n} :', end=' ') + print(f"n=${n} :", end=" ") for i in syracuse(n): - print(i, end=' ') + print(i, end=" ") print() diff --git a/jupyterlab_rise/__init__.py b/jupyterlab_rise/__init__.py index 1f59686..5ce26e4 100644 --- a/jupyterlab_rise/__init__.py +++ b/jupyterlab_rise/__init__.py @@ -4,10 +4,7 @@ def _jupyter_labextension_paths(): - return [{ - "src": "labextension", - "dest": "jupyterlab-rise" - }] + return [{"src": "labextension", "dest": "jupyterlab-rise"}] def _jupyter_server_extension_points(): diff --git a/jupyterlab_rise/app.py b/jupyterlab_rise/app.py index 386dec4..0d7b438 100644 --- a/jupyterlab_rise/app.py +++ b/jupyterlab_rise/app.py @@ -24,9 +24,7 @@ version = __version__ -class RiseHandler( - ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler -): +class RiseHandler(ExtensionHandlerJinjaMixin, ExtensionHandlerMixin, JupyterHandler): def get_page_config(self, notebook_path: Optional[str] = None): config = LabConfig() app = self.extensionapp @@ -39,7 +37,7 @@ def get_page_config(self, notebook_path: Optional[str] = None): "token": self.settings["token"], "fullStaticUrl": ujoin(self.base_url, "static", self.name), "frontendUrl": ujoin(self.base_url, "rise/"), - 'notebookPath': notebook_path, + "notebookPath": notebook_path, } mathjax_config = self.settings.get("mathjax_config", "TeX-AMS_HTML-full,Safe") @@ -79,7 +77,9 @@ def get_page_config(self, notebook_path: Optional[str] = None): @web.authenticated def get(self, path: str = None): nb_path = Path(path) - if nb_path.is_dir(): # TODO is it enough to support Jupytext? or should we filter the `suffix` + if ( + nb_path.is_dir() + ): # TODO is it enough to support Jupytext? or should we filter the `suffix` raise web.HTTPError(404, f"Only files can be opened with RISE; got {path}") return self.write( @@ -88,10 +88,11 @@ def get(self, path: str = None): static=self.static_url, base_url=self.base_url, token=self.settings["token"], - page_config=self.get_page_config(path) + page_config=self.get_page_config(path), ) ) + class RiseApp(LabServerApp): name = "rise" app_name = "Rise" diff --git a/pyproject.toml b/pyproject.toml index 50c7682..9fce1a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ dynamic = ["version", "description", "authors", "urls", "keywords"] [project.optional-dependencies] test = [ "coverage", + "hatch", "pytest", "pytest-asyncio", "pytest-cov", @@ -77,7 +78,7 @@ source_dir = "src" build_dir = "jupyterlab_rise/labextension" [tool.jupyter-releaser.options] -version_cmd = "hatch version" +version-cmd = "python scripts/bump_version.py --force" [tool.jupyter-releaser.hooks] before-build-npm = [ diff --git a/scripts/bump_version.py b/scripts/bump_version.py new file mode 100644 index 0000000..e533aa0 --- /dev/null +++ b/scripts/bump_version.py @@ -0,0 +1,80 @@ +# Copyright (c) Jupyter Development Team. +# Distributed under the terms of the Modified BSD License. + +import argparse +import json +import shlex +import sys +from pathlib import Path +from subprocess import check_output, run + +from packaging.version import parse + +LERNA_CMD = "jlpm run lerna version --no-push --force-publish --no-git-tag-version" + + +def bump(force: bool, spec: str) -> None: + HERE = Path(__file__).parent.parent.resolve() + output = check_output( + shlex.split("git status --porcelain"), cwd=HERE, encoding="utf-8" + ) + if len(output) > 0: + raise Exception("Must be in a clean git state with no untracked files") + + curr = parse( + # Output maybe multi-lines if build dependencies needs to be installed. + check_output( + [sys.executable, "-m", "hatch", "version"], cwd=HERE, encoding="utf-8" + ).strip("\n").split("\n")[-1] + ) + if spec == "next": + spec = f"{curr.major}.{curr.minor}." + if curr.pre: + p, x = curr.pre + spec += f"{curr.micro}{p}{x + 1}" + else: + spec += f"{curr.micro + 1}" + + elif spec == "patch": + spec = f"{curr.major}.{curr.minor}." + if curr.pre: + spec += f"{curr.micro}" + else: + spec += f"{curr.micro + 1}" + + version = parse(spec) + + # convert the Python version + js_version = f"{version.major}.{version.minor}.{version.micro}" + if version.pre is not None: + p, x = version.pre + p = p.replace("a", "alpha").replace("b", "beta") + js_version += f"-{p}.{x}" + + # bump the JS packages + lerna_cmd = f"{LERNA_CMD} {js_version}" + if force: + lerna_cmd += " --yes" + run(shlex.split(lerna_cmd), cwd=HERE) + + path = HERE.joinpath("package.json") + if path.exists(): + with path.open(mode="r") as f: + data = json.load(f) + + data["version"] = js_version + + with path.open(mode="w") as f: + json.dump(data, f, indent=2) + + else: + raise FileNotFoundError(f"Could not find package.json under dir {path!s}") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser("bump_version", "Bump package version") + parser.add_argument("--force", action="store_true") + parser.add_argument("spec") + + args = parser.parse_args() + bump(args.force, args.spec) diff --git a/setup.py b/setup.py index bea2337..aefdf20 100644 --- a/setup.py +++ b/setup.py @@ -1 +1 @@ -__import__('setuptools').setup() +__import__("setuptools").setup() diff --git a/ui-tests/jupyter_server_test_config.py b/ui-tests/jupyter_server_test_config.py index 5ba7a91..23d06f6 100644 --- a/ui-tests/jupyter_server_test_config.py +++ b/ui-tests/jupyter_server_test_config.py @@ -10,7 +10,7 @@ c.ServerApp.port_retries = 0 c.ServerApp.open_browser = False -c.ServerApp.root_dir = mkdtemp(prefix='galata-test-') +c.ServerApp.root_dir = mkdtemp(prefix="galata-test-") c.ServerApp.token = "" c.ServerApp.password = "" c.ServerApp.disable_check_xsrf = True