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

Make the repository compatible with Jupyter Releaser #162

Closed
jtpio opened this issue Jun 17, 2021 · 6 comments · Fixed by #163
Closed

Make the repository compatible with Jupyter Releaser #162

jtpio opened this issue Jun 17, 2021 · 6 comments · Fixed by #163

Comments

@jtpio
Copy link
Member

jtpio commented Jun 17, 2021

Problem

Extension authors creating a new extension from this cookiecutter will very likely want to release it at some point.

For now there is no real instructions for releasing the extension in the cookicutter itself, just a couple of notes in the extension tutorial: https://jupyterlab.readthedocs.io/en/stable/extension/extension_tutorial.html#publishing-your-extension

Ideally, the generated extension would automatically be compatible with the Jupyter Releaser so it can be published to both PyPI and npm: https://github.com/jupyter-server/jupyter_releaser

Proposed Solution

Additional context

This topic was also discussed in #101

@jtpio
Copy link
Member Author

jtpio commented Jun 18, 2021

Testing on a simple (soon to be archived) repo: https://github.com/jtpio/jupyterlab-python-file, logging here some findings.

It looks like the "Draft Release Action" current builds npm before Python:

https://github.com/jupyter-server/jupyter_releaser/blob/cba7bf7981c41415eda5ae4d2d3026908f003211/jupyter_releaser/actions/draft_release.py#L9-L13

And the cookiecutter assumes using jlpm which requires installing jupyterlab as a build dependency, which makes the workflow fail:

image

@jtpio
Copy link
Member Author

jtpio commented Jun 18, 2021

Adding the following hook to the package.json builds the package:

"jupyter-releaser": {
  "hooks": {
    "before-build-npm": [
      "python -m pip install jupyterlab~=3.0",
      "jlpm"
    ]
  }
},

image

But then stops a bit later when trying to extract the package:

image

Here: https://github.com/jupyter-server/jupyter_releaser/blob/cba7bf7981c41415eda5ae4d2d3026908f003211/jupyter_releaser/npm.py#L123

Probably because the result of npm pack contains more than just the path to the tarball.

@jtpio
Copy link
Member Author

jtpio commented Jun 21, 2021

Probably because the result of npm pack contains more than just the path to the tarball.

Checking the last line of the command output seems to do the trick for now:

diff --git a/jupyter_releaser/npm.py b/jupyter_releaser/npm.py
index d1c6aa6..731e087 100644
--- a/jupyter_releaser/npm.py
+++ b/jupyter_releaser/npm.py
@@ -24,7 +24,7 @@ def build_dist(package, dist_dir):

     if osp.isdir(package):
         basedir = package
-        tarball = osp.join(package, util.run("npm pack", cwd=package))
+        tarball = osp.join(package, util.run("npm pack", cwd=package).split('\n')[-1])
     else:
         basedir = osp.dirname(package)
         tarball = package

Next the releaser tries to import the package, but since that test extension is not importable it fails a little bit after:

image

Also the cookiecutter now defaults to underscores for the package name which it means it shouldn't be an issue with a fresh new extension.

@jtpio
Copy link
Member Author

jtpio commented Jun 21, 2021

Looks like everything went well after:

.github/actions/publish-release/action.yml | 2 ++
1 file changed, 2 insertions(+)

diff --git a/.github/actions/publish-release/action.yml b/.github/actions/publish-release/action.yml
index 15b4844..517db7e 100644
--- a/.github/actions/publish-release/action.yml
+++ b/.github/actions/publish-release/action.yml
@@ -31,6 +31,8 @@ runs:
        export RH_DRY_RUN=${{ inputs.dry_run }}
        export release_url=${{ inputs.release_url }}
        export RH_NPM_COMMAND="npm publish --access public"
+        
+        echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc

        # Install Jupyter Releaser from git
        pip install -q git+https://github.com/jupyter-server/jupyter_releaser.git@v1

image

@jtpio
Copy link
Member Author

jtpio commented Jun 21, 2021

explicitly creating .npmrc in the home directory with (probably something to fix in jupyter_releaser directly):

This could probably handled here: https://github.com/jupyter-server/jupyter_releaser/blob/cba7bf7981c41415eda5ae4d2d3026908f003211/jupyter_releaser/npm.py#L130-L141

@jtpio
Copy link
Member Author

jtpio commented Jun 23, 2021

Now looking good with this test repo, with the package correctly publishing to npm:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant