Skip to content

Commit

Permalink
Fix bumping version (#20)
Browse files Browse the repository at this point in the history
* Fix bumping version

* Improve linter configuration

* Blacken

* Install build dep

* Fix bump version dep installation

* Strip output

* Correctly fix version
  • Loading branch information
fcollonval authored Feb 26, 2023
1 parent 89d0e43 commit 7b3146a
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 24 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dist
coverage
**/*.d.ts
tests
app/build

**/__tests__
ui-tests
3 changes: 2 additions & 1 deletion .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
**/lib
**/package.json
jupyterlab_rise
app/build
21 changes: 11 additions & 10 deletions examples/jupytext-python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}
Expand All @@ -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()
5 changes: 1 addition & 4 deletions jupyterlab_rise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
13 changes: 7 additions & 6 deletions jupyterlab_rise/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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(
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dynamic = ["version", "description", "authors", "urls", "keywords"]
[project.optional-dependencies]
test = [
"coverage",
"hatch",
"pytest",
"pytest-asyncio",
"pytest-cov",
Expand Down Expand Up @@ -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 = [
Expand Down
80 changes: 80 additions & 0 deletions scripts/bump_version.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__import__('setuptools').setup()
__import__("setuptools").setup()
2 changes: 1 addition & 1 deletion ui-tests/jupyter_server_test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7b3146a

Please sign in to comment.