jupyterlab-v3-codio-ext 0.1.32__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. jupyterlab_v3_codio_ext-0.1.32/.gitignore +121 -0
  2. jupyterlab_v3_codio_ext-0.1.32/CHANGELOG.md +5 -0
  3. jupyterlab_v3_codio_ext-0.1.32/LICENSE +29 -0
  4. jupyterlab_v3_codio_ext-0.1.32/PKG-INFO +169 -0
  5. jupyterlab_v3_codio_ext-0.1.32/README.md +114 -0
  6. jupyterlab_v3_codio_ext-0.1.32/RELEASE.md +80 -0
  7. jupyterlab_v3_codio_ext-0.1.32/install.json +5 -0
  8. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/__init__.py +4 -0
  9. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/_version.py +4 -0
  10. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/cli.py +125 -0
  11. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/labextension/package.json +180 -0
  12. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/labextension/schemas/jupyterlab-v3-codio-ext/package.json.orig +175 -0
  13. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/labextension/schemas/jupyterlab-v3-codio-ext/plugin.json +14 -0
  14. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/labextension/static/728.58a4c87e58739bb4bc0b.js +1 -0
  15. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/labextension/static/776.45df2450a89bc297885f.js +1 -0
  16. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/labextension/static/remoteEntry.d9bde5d497570d915a7f.js +1 -0
  17. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/labextension/static/style.js +4 -0
  18. jupyterlab_v3_codio_ext-0.1.32/jupyterlab_v3_codio_ext/labextension/static/third-party-licenses.json +16 -0
  19. jupyterlab_v3_codio_ext-0.1.32/package.json +175 -0
  20. jupyterlab_v3_codio_ext-0.1.32/pyproject.toml +91 -0
  21. jupyterlab_v3_codio_ext-0.1.32/schema/plugin.json +14 -0
  22. jupyterlab_v3_codio_ext-0.1.32/setup.py +57 -0
  23. jupyterlab_v3_codio_ext-0.1.32/style/base.css +5 -0
  24. jupyterlab_v3_codio_ext-0.1.32/style/index.css +1 -0
  25. jupyterlab_v3_codio_ext-0.1.32/style/index.js +1 -0
  26. jupyterlab_v3_codio_ext-0.1.32/test data.txt +23 -0
  27. jupyterlab_v3_codio_ext-0.1.32/test_setup.py +56 -0
  28. jupyterlab_v3_codio_ext-0.1.32/test_setup_v2.py +45 -0
@@ -0,0 +1,121 @@
1
+ *.bundle.*
2
+ lib/
3
+ node_modules/
4
+ *.log
5
+ .eslintcache
6
+ .stylelintcache
7
+ *.egg-info/
8
+ .ipynb_checkpoints
9
+ *.tsbuildinfo
10
+ jupyterlab_v3_codio_ext/labextension
11
+ # Version file is handled by hatchling
12
+ jupyterlab_v3_codio_ext/_version.py
13
+
14
+ # Created by https://www.gitignore.io/api/python
15
+ # Edit at https://www.gitignore.io/?templates=python
16
+
17
+ ### Python ###
18
+ # Byte-compiled / optimized / DLL files
19
+ __pycache__/
20
+ *.py[cod]
21
+ *$py.class
22
+
23
+ # C extensions
24
+ *.so
25
+
26
+ # Distribution / packaging
27
+ .Python
28
+ build/
29
+ develop-eggs/
30
+ dist/
31
+ downloads/
32
+ eggs/
33
+ .eggs/
34
+ lib/
35
+ lib64/
36
+ parts/
37
+ sdist/
38
+ var/
39
+ wheels/
40
+ pip-wheel-metadata/
41
+ share/python-wheels/
42
+ .installed.cfg
43
+ *.egg
44
+ MANIFEST
45
+
46
+ # PyInstaller
47
+ # Usually these files are written by a python script from a template
48
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
49
+ *.manifest
50
+ *.spec
51
+
52
+ # Installer logs
53
+ pip-log.txt
54
+ pip-delete-this-directory.txt
55
+
56
+ # Unit test / coverage reports
57
+ htmlcov/
58
+ .tox/
59
+ .nox/
60
+ .coverage
61
+ .coverage.*
62
+ .cache
63
+ nosetests.xml
64
+ coverage/
65
+ coverage.xml
66
+ *.cover
67
+ .hypothesis/
68
+ .pytest_cache/
69
+
70
+ # Translations
71
+ *.mo
72
+ *.pot
73
+
74
+ # Scrapy stuff:
75
+ .scrapy
76
+
77
+ # Sphinx documentation
78
+ docs/_build/
79
+
80
+ # PyBuilder
81
+ target/
82
+
83
+ # pyenv
84
+ .python-version
85
+
86
+ # celery beat schedule file
87
+ celerybeat-schedule
88
+
89
+ # SageMath parsed files
90
+ *.sage.py
91
+
92
+ # Spyder project settings
93
+ .spyderproject
94
+ .spyproject
95
+
96
+ # Rope project settings
97
+ .ropeproject
98
+
99
+ # Mr Developer
100
+ .mr.developer.cfg
101
+ .project
102
+ .pydevproject
103
+
104
+ # mkdocs documentation
105
+ /site
106
+
107
+ # mypy
108
+ .mypy_cache/
109
+ .dmypy.json
110
+ dmypy.json
111
+
112
+ # Pyre type checker
113
+ .pyre/
114
+
115
+ # End of https://www.gitignore.io/api/python
116
+
117
+ # OSX files
118
+ .DS_Store
119
+
120
+ # Yarn cache
121
+ .yarn/
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ <!-- <START NEW CHANGELOG ENTRY> -->
4
+
5
+ <!-- <END NEW CHANGELOG ENTRY> -->
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, codio
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.5
2
+ Name: jupyterlab_v3_codio_ext
3
+ Version: 0.1.32
4
+ Dynamic: Keywords
5
+ Summary: A JupyterLab v3 extension to interact with codio.
6
+ Project-URL: Homepage, https://github.com/codio/jupyterlab3-codio-ext
7
+ Project-URL: Bug Tracker, https://github.com/codio/jupyterlab3-codio-ext/issues
8
+ Project-URL: Repository, https://github.com/codio/jupyterlab3-codio-ext.git
9
+ Author-email: codio <support@codio.com>
10
+ License: BSD 3-Clause License
11
+
12
+ Copyright (c) 2024, codio
13
+ All rights reserved.
14
+
15
+ Redistribution and use in source and binary forms, with or without
16
+ modification, are permitted provided that the following conditions are met:
17
+
18
+ 1. Redistributions of source code must retain the above copyright notice, this
19
+ list of conditions and the following disclaimer.
20
+
21
+ 2. Redistributions in binary form must reproduce the above copyright notice,
22
+ this list of conditions and the following disclaimer in the documentation
23
+ and/or other materials provided with the distribution.
24
+
25
+ 3. Neither the name of the copyright holder nor the names of its
26
+ contributors may be used to endorse or promote products derived from
27
+ this software without specific prior written permission.
28
+
29
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
33
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
+ License-File: LICENSE
40
+ Classifier: Framework :: Jupyter
41
+ Classifier: Framework :: Jupyter :: JupyterLab
42
+ Classifier: Framework :: Jupyter :: JupyterLab :: 3
43
+ Classifier: Framework :: Jupyter :: JupyterLab :: Extensions
44
+ Classifier: Framework :: Jupyter :: JupyterLab :: Extensions :: Prebuilt
45
+ Classifier: License :: OSI Approved :: BSD License
46
+ Classifier: Programming Language :: Python
47
+ Classifier: Programming Language :: Python :: 3
48
+ Classifier: Programming Language :: Python :: 3.7
49
+ Classifier: Programming Language :: Python :: 3.8
50
+ Classifier: Programming Language :: Python :: 3.9
51
+ Classifier: Programming Language :: Python :: 3.10
52
+ Classifier: Programming Language :: Python :: 3.11
53
+ Requires-Python: >=3.7
54
+ Description-Content-Type: text/markdown
55
+
56
+ # jupyterlab_v3_codio_ext
57
+
58
+ [![Github Actions Status](https://github.com/codio/jupyterlab3-codio-ext/workflows/Build/badge.svg)](https://github.com/codio/jupyterlab3-codio-ext/actions/workflows/build.yml)
59
+ A JupyterLab extension to interact with codio.
60
+
61
+ ## Requirements
62
+
63
+ - JupyterLab >= 3.0
64
+
65
+ ## Install
66
+
67
+ To install the extension, execute:
68
+
69
+ ```bash
70
+ pip install jupyterlab-v3-codio-ext
71
+ ```
72
+
73
+ ## Uninstall
74
+
75
+ To remove the extension, execute:
76
+
77
+ ```bash
78
+ pip uninstall jupyterlab-v3-codio-ext
79
+ ```
80
+
81
+ ## Contributing
82
+
83
+ ### Development install
84
+
85
+ Note: You will need NodeJS to build the extension package.
86
+
87
+ The `jlpm` command is JupyterLab's pinned version of
88
+ [yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
89
+ `yarn` or `npm` in lieu of `jlpm` below.
90
+
91
+ ```bash
92
+ # Clone the repo to your local environment
93
+ # Change directory to the jupyterlab_v3_codio_ext directory
94
+ # Install package in development mode
95
+ pip install -e "."
96
+ # Link your development version of the extension with JupyterLab
97
+ jupyter labextension develop . --overwrite
98
+ # Rebuild extension Typescript source after making changes
99
+ jlpm build
100
+ ```
101
+
102
+ You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.
103
+
104
+ ```bash
105
+ # Watch the source directory in one terminal, automatically rebuilding when needed
106
+ jlpm watch
107
+ # Run JupyterLab in another terminal
108
+ jupyter lab
109
+ ```
110
+
111
+ With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).
112
+
113
+ By default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:
114
+
115
+ ```bash
116
+ jupyter lab build --minimize=False
117
+ ```
118
+
119
+ ### Development uninstall
120
+
121
+ ```bash
122
+ pip uninstall jupyterlab_v3_codio_ext
123
+ ```
124
+
125
+ In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
126
+ command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
127
+ folder is located. Then you can remove the symlink named `jupyterlab3-codio-ext` within that folder.
128
+
129
+ ### Packaging the extension
130
+
131
+ See [RELEASE](RELEASE.md)
132
+
133
+ ### Development
134
+
135
+ https://jupyterlab.readthedocs.io/en/3.6.x/extension/extension_tutorial.html
136
+
137
+ ```
138
+ pip install -ve .
139
+ ```
140
+
141
+ in codio to install labextension mount folder.
142
+ then in folder `~/.pyenv/versions/3.11.2/share/jupyter/labextensions`
143
+ ```
144
+ sudo ln -s /usr/share/codio-tools/jupyterlab-v3-codio-ext/jupyterlab_v3_codio_ext/labextension/ jupyterlab-v3-codio-ext
145
+ ```
146
+
147
+
148
+ ### Build
149
+
150
+ ```
151
+ python -m build
152
+ ```
153
+
154
+ ### Upload
155
+
156
+ ```
157
+ twine upload dist/* --verbose
158
+ ```
159
+
160
+ or
161
+ ```
162
+ twine upload --repository testpypi dist/* --verbose
163
+ ```
164
+
165
+ ### Update config
166
+
167
+ ```
168
+ jupyterlab-v3-codio-ext-cli --env "https://codio.com"
169
+ ```
@@ -0,0 +1,114 @@
1
+ # jupyterlab_v3_codio_ext
2
+
3
+ [![Github Actions Status](https://github.com/codio/jupyterlab3-codio-ext/workflows/Build/badge.svg)](https://github.com/codio/jupyterlab3-codio-ext/actions/workflows/build.yml)
4
+ A JupyterLab extension to interact with codio.
5
+
6
+ ## Requirements
7
+
8
+ - JupyterLab >= 3.0
9
+
10
+ ## Install
11
+
12
+ To install the extension, execute:
13
+
14
+ ```bash
15
+ pip install jupyterlab-v3-codio-ext
16
+ ```
17
+
18
+ ## Uninstall
19
+
20
+ To remove the extension, execute:
21
+
22
+ ```bash
23
+ pip uninstall jupyterlab-v3-codio-ext
24
+ ```
25
+
26
+ ## Contributing
27
+
28
+ ### Development install
29
+
30
+ Note: You will need NodeJS to build the extension package.
31
+
32
+ The `jlpm` command is JupyterLab's pinned version of
33
+ [yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use
34
+ `yarn` or `npm` in lieu of `jlpm` below.
35
+
36
+ ```bash
37
+ # Clone the repo to your local environment
38
+ # Change directory to the jupyterlab_v3_codio_ext directory
39
+ # Install package in development mode
40
+ pip install -e "."
41
+ # Link your development version of the extension with JupyterLab
42
+ jupyter labextension develop . --overwrite
43
+ # Rebuild extension Typescript source after making changes
44
+ jlpm build
45
+ ```
46
+
47
+ You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension.
48
+
49
+ ```bash
50
+ # Watch the source directory in one terminal, automatically rebuilding when needed
51
+ jlpm watch
52
+ # Run JupyterLab in another terminal
53
+ jupyter lab
54
+ ```
55
+
56
+ With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).
57
+
58
+ By default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:
59
+
60
+ ```bash
61
+ jupyter lab build --minimize=False
62
+ ```
63
+
64
+ ### Development uninstall
65
+
66
+ ```bash
67
+ pip uninstall jupyterlab_v3_codio_ext
68
+ ```
69
+
70
+ In development mode, you will also need to remove the symlink created by `jupyter labextension develop`
71
+ command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions`
72
+ folder is located. Then you can remove the symlink named `jupyterlab3-codio-ext` within that folder.
73
+
74
+ ### Packaging the extension
75
+
76
+ See [RELEASE](RELEASE.md)
77
+
78
+ ### Development
79
+
80
+ https://jupyterlab.readthedocs.io/en/3.6.x/extension/extension_tutorial.html
81
+
82
+ ```
83
+ pip install -ve .
84
+ ```
85
+
86
+ in codio to install labextension mount folder.
87
+ then in folder `~/.pyenv/versions/3.11.2/share/jupyter/labextensions`
88
+ ```
89
+ sudo ln -s /usr/share/codio-tools/jupyterlab-v3-codio-ext/jupyterlab_v3_codio_ext/labextension/ jupyterlab-v3-codio-ext
90
+ ```
91
+
92
+
93
+ ### Build
94
+
95
+ ```
96
+ python -m build
97
+ ```
98
+
99
+ ### Upload
100
+
101
+ ```
102
+ twine upload dist/* --verbose
103
+ ```
104
+
105
+ or
106
+ ```
107
+ twine upload --repository testpypi dist/* --verbose
108
+ ```
109
+
110
+ ### Update config
111
+
112
+ ```
113
+ jupyterlab-v3-codio-ext-cli --env "https://codio.com"
114
+ ```
@@ -0,0 +1,80 @@
1
+ # Making a new release of jupyterlab_v3_codio_ext
2
+
3
+ The extension can be published to `PyPI` and `npm` manually or using the [Jupyter Releaser](https://github.com/jupyter-server/jupyter_releaser).
4
+
5
+ ## Manual release
6
+
7
+ ### Python package
8
+
9
+ This extension can be distributed as Python
10
+ packages. All of the Python
11
+ packaging instructions in the `pyproject.toml` file to wrap your extension in a
12
+ Python package. Before generating a package, we first need to install `build`.
13
+
14
+ ```bash
15
+ pip install build twine hatch
16
+ ```
17
+
18
+ Bump the version using `hatch`. By default this will create a tag.
19
+ See the docs on [hatch-nodejs-version](https://github.com/agoose77/hatch-nodejs-version#semver) for details.
20
+
21
+ ```bash
22
+ hatch version <new-version>
23
+ ```
24
+
25
+ Make sure to clean up all the development files before building the package:
26
+
27
+ ```bash
28
+ jlpm clean:all
29
+ ```
30
+
31
+ You could also clean up the local git repository:
32
+
33
+ ```bash
34
+ git clean -dfX
35
+ ```
36
+
37
+ To create a Python source package (`.tar.gz`) and the binary package (`.whl`) in the `dist/` directory, do:
38
+
39
+ ```bash
40
+ python -m build
41
+ ```
42
+
43
+ > `python setup.py sdist bdist_wheel` is deprecated and will not work for this package.
44
+
45
+ Then to upload the package to PyPI, do:
46
+
47
+ ```bash
48
+ twine upload dist/*
49
+ ```
50
+
51
+ ### NPM package
52
+
53
+ To publish the frontend part of the extension as a NPM package, do:
54
+
55
+ ```bash
56
+ npm login
57
+ npm publish --access public
58
+ ```
59
+
60
+ ## Automated releases with the Jupyter Releaser
61
+
62
+ The extension repository should already be compatible with the Jupyter Releaser.
63
+
64
+ Check out the [workflow documentation](https://github.com/jupyter-server/jupyter_releaser#typical-workflow) for more information.
65
+
66
+ Here is a summary of the steps to cut a new release:
67
+
68
+ - Fork the [`jupyter-releaser` repo](https://github.com/jupyter-server/jupyter_releaser)
69
+ - Add `ADMIN_GITHUB_TOKEN`, `PYPI_TOKEN` and `NPM_TOKEN` to the Github Secrets in the fork
70
+ - Go to the Actions panel
71
+ - Run the "Draft Changelog" workflow
72
+ - Merge the Changelog PR
73
+ - Run the "Draft Release" workflow
74
+ - Run the "Publish Release" workflow
75
+
76
+ ## Publishing to `conda-forge`
77
+
78
+ If the package is not on conda forge yet, check the documentation to learn how to add it: https://conda-forge.org/docs/maintainer/adding_pkgs.html
79
+
80
+ Otherwise a bot should pick up the new version publish to PyPI, and open a new PR on the feedstock repository automatically.
@@ -0,0 +1,5 @@
1
+ {
2
+ "packageManager": "python",
3
+ "packageName": "jupyterlab_v3_codio_ext",
4
+ "uninstallInstructions": "Use your Python package manager (pip, conda, etc.) to uninstall the package jupyterlab_v3_codio_ext"
5
+ }
@@ -0,0 +1,4 @@
1
+ from ._version import __version__ # noqa
2
+
3
+ def _jupyter_labextension_paths():
4
+ return [{"src": "labextension", "dest": "jupyterlab-v3-codio-ext"}]
@@ -0,0 +1,4 @@
1
+ # This file is auto-generated by Hatchling. As such, do not:
2
+ # - modify
3
+ # - track in version control e.g. be sure to add to .gitignore
4
+ __version__ = VERSION = '0.1.32'
@@ -0,0 +1,125 @@
1
+ import argparse
2
+ import json
3
+ import os
4
+ import subprocess
5
+ import sys
6
+
7
+
8
+ extension_name = __package__.replace("_", "-")
9
+ user_settings_dir = "lab/user-settings"
10
+
11
+ DEFAULT_ENV = os.getenv("CODIO_ENV", "https://codio.com")
12
+ CODIO_CLIENT_PATH = "/ext/iframe/base/static/codio-client.js"
13
+ DEFAULT_CODIO_CLIENT_URL = DEFAULT_ENV + CODIO_CLIENT_PATH
14
+
15
+ DEFAULT_JUPYTER_CONFIG_PATH = os.path.join(os.path.expanduser("~"), ".jupyter")
16
+
17
+
18
+ def get_jupyter_lab_version(version_output):
19
+ for line in version_output.splitlines():
20
+ if line.startswith("jupyterlab"):
21
+ return line.split(":")[1].strip()
22
+ return None
23
+
24
+ def get_user_settings_dir(config_dir, version):
25
+ settings_dir = None
26
+ major_version = int(version.split(".")[0]) if version else 0
27
+ if major_version >= 4:
28
+ settings_dir = os.environ.get("JUPYTERLAB_SETTINGS_DIR")
29
+ if not settings_dir:
30
+ settings_dir = os.path.join(config_dir, user_settings_dir)
31
+ return os.path.abspath(settings_dir)
32
+
33
+ def get_config_dir_from_json(json_data):
34
+ config = json_data.get("config", [])
35
+ for path in config:
36
+ ext_schemas_dir = os.path.join(path, "lab")
37
+ if os.path.exists(ext_schemas_dir):
38
+ return path
39
+ return DEFAULT_JUPYTER_CONFIG_PATH
40
+
41
+
42
+ def copy_config_value(client_url, dst_dir):
43
+ config = {"codioClientUrl": client_url}
44
+
45
+ plugin_settings_file = os.path.join(dst_dir, "plugin.jupyterlab-settings")
46
+ try:
47
+ os.makedirs(dst_dir, exist_ok=True)
48
+ with open(plugin_settings_file, "w") as dst:
49
+ dst.write(json.dumps(config))
50
+ print(f"Copy config \nto {plugin_settings_file}")
51
+ return 0
52
+ except Exception as error:
53
+ print(f"Error copying config: {error}")
54
+ return 1
55
+
56
+
57
+ def main():
58
+ parser = argparse.ArgumentParser(description="Configure my JupyterLab extension")
59
+
60
+ subparsers = parser.add_subparsers(
61
+ dest="command",
62
+ help="Command to execute"
63
+ )
64
+ env_parser = subparsers.add_parser(
65
+ "env",
66
+ help="Set the CODIO environment URL \"https://codio.com\""
67
+ )
68
+ env_parser.add_argument(
69
+ "env",
70
+ nargs="?",
71
+ help="Environment URL default is \"https://codio.com\"",
72
+ default=DEFAULT_ENV,
73
+ )
74
+
75
+ args = parser.parse_args()
76
+
77
+ if args.command != "env":
78
+ parser.print_help()
79
+ return 1
80
+
81
+ if args.command == "env":
82
+ if not args.env:
83
+ print("Usage: test.py env <env>")
84
+ print("default <env> if '{}'".format(DEFAULT_ENV))
85
+ env = DEFAULT_ENV
86
+ else:
87
+ print(f"Using CODIO environment: {args.env}")
88
+ print(f"Using CODIO client URL: {args.env}{CODIO_CLIENT_PATH}")
89
+ env = args.env
90
+
91
+ client_url = f"{args.env}{CODIO_CLIENT_PATH}" if args.env else DEFAULT_CODIO_CLIENT_URL
92
+
93
+ try:
94
+ result = subprocess.run(["jupyter", "--version"], check=True, stdout=subprocess.PIPE)
95
+ version_output = result.stdout.decode("utf-8").strip()
96
+ except subprocess.CalledProcessError:
97
+ print("Jupyter is not installed")
98
+ return 1
99
+
100
+ result = subprocess.run(["jupyter", "--json", "--paths"], stdout=subprocess.PIPE)
101
+ decoded = result.stdout.decode("utf-8")
102
+ try:
103
+ paths = json.loads(decoded)
104
+ except json.JSONDecodeError as error:
105
+ print(f"Error decoding Jupyter paths: {error}")
106
+ return 1
107
+
108
+ config_dir = get_config_dir_from_json(paths)
109
+ if config_dir:
110
+ print(f"Found config directory: {config_dir}")
111
+ version = get_jupyter_lab_version(version_output)
112
+ if not version:
113
+ print("Jupyter Lab is not installed")
114
+ return 1
115
+ user_settings_dir = get_user_settings_dir(config_dir, version)
116
+ dst_dir = os.path.join(user_settings_dir, extension_name)
117
+ print(f"Destination directory: {dst_dir}")
118
+ return copy_config_value(client_url, dst_dir)
119
+ else:
120
+ print("No config directory found")
121
+ return 1
122
+
123
+
124
+ if __name__ == "__main__":
125
+ raise sys.exit(main())