|
| 1 | +# jupyterlab-code-snippets |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | +Code Snippets Extension for JupyterLab. |
| 6 | + |
| 7 | +This extension is composed of a Python package named `jupyterlab-code-snippets` |
| 8 | +for the server extension and a NPM package named `jupyterlab-code-snippets` |
| 9 | +for the frontend extension. |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +- JupyterLab >= 2.0 |
| 14 | +- Node.js |
| 15 | + |
| 16 | +## Install |
| 17 | + |
| 18 | +```bash |
| 19 | +pip install jupyterlab-code-snippets |
| 20 | +jupyter lab build |
| 21 | +``` |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +In `jupyter_notebook_config.py`: |
| 26 | + |
| 27 | +```python |
| 28 | +c.JupyterLabCodeSnippets.snippet_dir = "/path/to/snippets" |
| 29 | +``` |
| 30 | + |
| 31 | +In JupyterLab, use the "Code Snippets" menu to select the snippet: |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +## Troubleshoot |
| 37 | + |
| 38 | +If you are seeing the frontend extension but it is not working, check |
| 39 | +that the server extension is enabled: |
| 40 | + |
| 41 | +```bash |
| 42 | +jupyter serverextension list |
| 43 | +``` |
| 44 | + |
| 45 | +If the server extension is installed and enabled but you are not seeing |
| 46 | +the frontend, check the frontend extension is installed and enabled: |
| 47 | + |
| 48 | +```bash |
| 49 | +jupyter labextension list |
| 50 | +``` |
| 51 | + |
| 52 | +If it is installed, try: |
| 53 | + |
| 54 | +```bash |
| 55 | +jupyter lab clean |
| 56 | +jupyter lab build |
| 57 | +``` |
| 58 | + |
| 59 | +## Contributing |
| 60 | + |
| 61 | +### Development Install |
| 62 | + |
| 63 | +The `jlpm` command is JupyterLab's pinned version of |
| 64 | +[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use |
| 65 | +`yarn` or `npm` in lieu of `jlpm` below. |
| 66 | + |
| 67 | +```bash |
| 68 | +# Clone the repo to your local environment |
| 69 | +# Move to jupyterlab-code-snippets directory |
| 70 | +# Install the server extension |
| 71 | +pip install -e . |
| 72 | + |
| 73 | +# Register the server extension |
| 74 | +jupyter serverextension enable --py jupyterlab-code-snippets |
| 75 | + |
| 76 | +# Install the dependencies |
| 77 | +jlpm |
| 78 | + |
| 79 | +# Build the TypeScript source |
| 80 | +jlpm build |
| 81 | + |
| 82 | +# Link your development version of the extension with JupyterLab |
| 83 | +jupyter labextension link . |
| 84 | + |
| 85 | +# Rebuild the TypeScript source after making changes |
| 86 | +jlpm build |
| 87 | + |
| 88 | +# Rebuild JupyterLab after making any changes |
| 89 | +jupyter lab build |
| 90 | +``` |
| 91 | + |
| 92 | +You can watch the source directory and run JupyterLab in watch mode to watch for changes in the extension's source and automatically rebuild the extension and application. |
| 93 | + |
| 94 | +```bash |
| 95 | +# Watch the source directory in another terminal tab |
| 96 | +jlpm watch |
| 97 | + |
| 98 | +# Run jupyterlab in watch mode in one terminal tab |
| 99 | +jupyter lab --watch |
| 100 | +``` |
| 101 | + |
| 102 | +### Uninstall |
| 103 | + |
| 104 | +```bash |
| 105 | +pip uninstall jupyterlab-code-snippets |
| 106 | +jupyter labextension uninstall jupyterlab-code-snippets |
| 107 | +``` |
0 commit comments