From 3de0c343c3cc19bd2ede0c64537b0cbe53df3d8d Mon Sep 17 00:00:00 2001 From: "RIO\\teodora.misan" Date: Wed, 25 Sep 2024 13:47:20 +0300 Subject: [PATCH] EBR-91: rename the python package to align with the default convention --- .github/workflows/build.yml | 8 +++----- .gitignore | 4 ++-- .prettierignore | 2 +- README.md | 8 ++++---- conftest.py | 2 +- jupyter-config/nb-config/tvbextunicore.json | 2 +- jupyter-config/server-config/tvbextunicore.json | 2 +- package.json | 4 ++-- pyproject.toml | 14 +++++++------- src/__tests__/constants.tests.tsx | 4 ++-- src/constants.ts | 4 ++-- src/handler.ts | 4 ++-- src/index.ts | 6 +++--- {tvbextunicore => tvb_ext_unicore}/__init__.py | 6 +++--- {tvbextunicore => tvb_ext_unicore}/exceptions.py | 0 {tvbextunicore => tvb_ext_unicore}/handlers.py | 16 ++++++++-------- .../logger/__init__.py | 0 .../logger/builder.py | 0 .../logger/logging.conf | 8 ++++---- .../tests/__init__.py | 0 .../tests/test_unicore_wrapper.py | 14 +++++++------- .../unicore_wrapper/__init__.py | 0 .../unicore_wrapper/job_dto.py | 0 .../unicore_wrapper/unicore_wrapper.py | 8 ++++---- {tvbextunicore => tvb_ext_unicore}/utils.py | 2 +- 25 files changed, 58 insertions(+), 60 deletions(-) rename {tvbextunicore => tvb_ext_unicore}/__init__.py (82%) rename {tvbextunicore => tvb_ext_unicore}/exceptions.py (100%) rename {tvbextunicore => tvb_ext_unicore}/handlers.py (88%) rename {tvbextunicore => tvb_ext_unicore}/logger/__init__.py (100%) rename {tvbextunicore => tvb_ext_unicore}/logger/builder.py (100%) rename {tvbextunicore => tvb_ext_unicore}/logger/logging.conf (89%) rename {tvbextunicore => tvb_ext_unicore}/tests/__init__.py (100%) rename {tvbextunicore => tvb_ext_unicore}/tests/test_unicore_wrapper.py (90%) rename {tvbextunicore => tvb_ext_unicore}/unicore_wrapper/__init__.py (100%) rename {tvbextunicore => tvb_ext_unicore}/unicore_wrapper/job_dto.py (100%) rename {tvbextunicore => tvb_ext_unicore}/unicore_wrapper/unicore_wrapper.py (95%) rename {tvbextunicore => tvb_ext_unicore}/utils.py (91%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 78256f7..ca04bd7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,13 +41,11 @@ jobs: CLB_AUTH: 'TEST_TOKEN' run: | set -eux - jlpm - jlpm run build python -m pip install .[test] jupyter server extension list - jupyter server extension list 2>&1 | grep -ie "tvbextunicore.*OK" + jupyter server extension list 2>&1 | grep -ie "tvb_ext_unicore.*OK" jupyter labextension list 2>&1 | grep -ie "tvb-ext-unicore.*OK" python -m jupyterlab.browser_check @@ -57,7 +55,7 @@ jobs: - name: Run Python & JS tests run: | set -eux - pytest tvbextunicore -r ap + pytest tvb_ext_unicore -r ap yarn test - name: Package the extension @@ -126,6 +124,6 @@ jobs: pip install "jupyterlab>=4.0.0,<5" tvb_ext_unicore*.whl - jupyter server extension list 2>&1 | grep -ie "tvbextunicore.*OK" + jupyter server extension list 2>&1 | grep -ie "tvb_ext_unicore.*OK" jupyter labextension list 2>&1 | grep -ie "tvb-ext-unicore.*OK" python -m jupyterlab.browser_check --no-browser-test diff --git a/.gitignore b/.gitignore index b688f0f..989d36e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,9 +7,9 @@ node_modules/ *.egg-info/ .ipynb_checkpoints *.tsbuildinfo -tvbextunicore/labextension +tvb_ext_unicore/labextension # Version file is handled by hatchling -tvbextunicore/_version.py +tvb_ext_unicore/_version.py # Created by https://www.gitignore.io/api/python # Edit at https://www.gitignore.io/?templates=python diff --git a/.prettierignore b/.prettierignore index fb0cf42..0e6b0bc 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,4 +3,4 @@ node_modules **/lib **/package.json !/package.json -tvbextunicore +tvb_ext_unicore diff --git a/README.md b/README.md index a5a2418..ff8de69 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This jupyter extension offers a UI component to monitor HPC jobs through Unicore to easily switch between computing sites, retrieve details about the jobs, and also cancel them. -The package is composed of a Python module named `tvbextunicore` +The package is composed of a Python module named `tvb_ext_unicore` for the server extension and a NPM package named `tvb-ext-unicore` for the frontend extension. @@ -85,7 +85,7 @@ pip install -e . # Link your development version of the extension with JupyterLab jupyter labextension develop . --overwrite # Server extension must be manually installed in develop mode -jupyter server extension enable tvbextunicore +jupyter server extension enable tvb_ext_unicore # Define CLB_AUTH environment variable holding your EBRAINS token export CLB_AUTH=${ebrains_token} @@ -115,7 +115,7 @@ jupyter lab build --minimize=False ```bash # Server extension must be manually disabled in develop mode -jupyter server extension disable tvbextunicore +jupyter server extension disable tvb_ext_unicore pip uninstall tvb-ext-unicore ``` @@ -141,7 +141,7 @@ jupyter labextension develop . --overwrite To execute them, run: ```sh -pytest -vv -r ap --cov tvbextunicore +pytest -vv -r ap --cov tvb_ext_unicore ``` #### Frontend tests diff --git a/conftest.py b/conftest.py index a05b535..178dde6 100644 --- a/conftest.py +++ b/conftest.py @@ -5,4 +5,4 @@ @pytest.fixture def jp_server_config(jp_server_config): - return {"ServerApp": {"jpserver_extensions": {"tvbextunicore": True}}} + return {"ServerApp": {"jpserver_extensions": {"tvb_ext_unicore": True}}} diff --git a/jupyter-config/nb-config/tvbextunicore.json b/jupyter-config/nb-config/tvbextunicore.json index bd7c2e9..d500b5c 100644 --- a/jupyter-config/nb-config/tvbextunicore.json +++ b/jupyter-config/nb-config/tvbextunicore.json @@ -1,7 +1,7 @@ { "NotebookApp": { "nbserver_extensions": { - "tvbextunicore": true + "tvb_ext_unicore": true } } } diff --git a/jupyter-config/server-config/tvbextunicore.json b/jupyter-config/server-config/tvbextunicore.json index 7728778..dcd67e6 100644 --- a/jupyter-config/server-config/tvbextunicore.json +++ b/jupyter-config/server-config/tvbextunicore.json @@ -1,7 +1,7 @@ { "ServerApp": { "jpserver_extensions": { - "tvbextunicore": true + "tvb_ext_unicore": true } } } diff --git a/package.json b/package.json index a1ee143..62e7edb 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "build:prod": "jlpm clean && jlpm build:lib:prod && jlpm build:labextension", "clean": "jlpm clean:lib", "clean:all": "jlpm clean:lib && jlpm clean:labextension && jlpm clean:lintcache", - "clean:labextension": "rimraf tvbextunicore/labextension tvbextunicore/_version.py", + "clean:labextension": "rimraf tvb_ext_unicore/labextension tvb_ext_unicore/_version.py", "clean:lib": "rimraf lib tsconfig.tsbuildinfo", "clean:lintcache": "rimraf .eslintcache .stylelintcache", "eslint": "jlpm eslint:check --fix", @@ -122,7 +122,7 @@ } }, "extension": true, - "outputDir": "tvbextunicore/labextension" + "outputDir": "tvb_ext_unicore/labextension" }, "jupyter-releaser": { "hooks": { diff --git a/pyproject.toml b/pyproject.toml index 2af15d3..bf23395 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -44,25 +44,25 @@ source = "nodejs" fields = ["description", "authors", "urls", "keywords"] [tool.hatch.build.targets.sdist] -artifacts = ["tvbextunicore/labextension"] +artifacts = ["tvb_ext_unicore/labextension"] exclude = [".github", "binder"] [tool.hatch.build.targets.wheel.shared-data] -"tvbextunicore/labextension" = "share/jupyter/labextensions/tvb-ext-unicore" +"tvb_ext_unicore/labextension" = "share/jupyter/labextensions/tvb-ext-unicore" "install.json" = "share/jupyter/labextensions/tvb-ext-unicore/install.json" "jupyter-config/server-config" = "etc/jupyter/jupyter_server_config.d" [tool.hatch.build.hooks.version] -path = "tvbextunicore/_version.py" +path = "tvb_ext_unicore/_version.py" [tool.hatch.build.hooks.jupyter-builder] dependencies = ["hatch-jupyter-builder>=0.5"] build-function = "hatch_jupyter_builder.npm_builder" ensured-targets = [ - "tvbextunicore/labextension/static/style.js", - "tvbextunicore/labextension/package.json", + "tvb_ext_unicore/labextension/static/style.js", + "tvb_ext_unicore/labextension/package.json", ] -skip-if-exists = ["tvbextunicore/labextension/static/style.js"] +skip-if-exists = ["tvb_ext_unicore/labextension/static/style.js"] [tool.hatch.build.hooks.jupyter-builder.build-kwargs] build_cmd = "build:prod" @@ -72,7 +72,7 @@ npm = ["jlpm"] build_cmd = "install:extension" npm = ["jlpm"] source_dir = "src" -build_dir = "tvbextunicore/labextension" +build_dir = "tvb_ext_unicore/labextension" [tool.jupyter-releaser.options] version_cmd = "hatch version" diff --git a/src/__tests__/constants.tests.tsx b/src/__tests__/constants.tests.tsx index 8c3f2fe..f743ea2 100644 --- a/src/__tests__/constants.tests.tsx +++ b/src/__tests__/constants.tests.tsx @@ -2,7 +2,7 @@ import { getJobCode, getDownloadFileCode } from '../constants'; describe('test getJobCode, getDownloadFileCode', () => { it('generates code to get a job', () => { - const expected = `from tvbextunicore.unicore_wrapper import unicore_wrapper + const expected = `from tvb_ext_unicore.unicore_wrapper import unicore_wrapper unicore = unicore_wrapper.UnicoreWrapper() job = unicore.get_job('url') job`; @@ -10,7 +10,7 @@ job`; }); it('generates code to download a file', () => { - const expected = `from tvbextunicore.unicore_wrapper import unicore_wrapper + const expected = `from tvb_ext_unicore.unicore_wrapper import unicore_wrapper unicore = unicore_wrapper.UnicoreWrapper() download_result = unicore.download_file('test_url', 'test_file') download_result`; diff --git a/src/constants.ts b/src/constants.ts index c3dca9e..6589dbb 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -30,7 +30,7 @@ export const RELOAD_CHECK_RATE_MS = 10000; //should check every 10sec * @param file */ export function getDownloadFileCode(job_url: string, file: string): string { - return `from tvbextunicore.unicore_wrapper import unicore_wrapper + return `from tvb_ext_unicore.unicore_wrapper import unicore_wrapper unicore = unicore_wrapper.UnicoreWrapper() download_result = unicore.download_file('${job_url}', '${file}') download_result`; @@ -41,7 +41,7 @@ download_result`; * @param job_url */ export function getJobCode(job_url: string): string { - return `from tvbextunicore.unicore_wrapper import unicore_wrapper + return `from tvb_ext_unicore.unicore_wrapper import unicore_wrapper unicore = unicore_wrapper.UnicoreWrapper() job = unicore.get_job('${job_url}') job`; diff --git a/src/handler.ts b/src/handler.ts index 0c24f06..edf2627 100644 --- a/src/handler.ts +++ b/src/handler.ts @@ -17,7 +17,7 @@ export async function requestAPI( const settings = ServerConnection.makeSettings(); const requestUrl = URLExt.join( settings.baseUrl, - 'tvbextunicore', // API Namespace + 'tvb_ext_unicore', // API Namespace endPoint ); let response: Response; @@ -60,7 +60,7 @@ export async function requestStream( const settings = ServerConnection.makeSettings(); const requestUrl = URLExt.join( settings.baseUrl, - 'tvbextunicore', // API Namespace + 'tvb_ext_unicore', // API Namespace endPoint ); let response: Response; diff --git a/src/index.ts b/src/index.ts index d8fd118..a87c8d1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -51,7 +51,7 @@ export type NullableIKernelConnection = * Initialization data for the tvb-ext-unicore extension. */ const plugin: JupyterFrontEndPlugin = { - id: 'tvbextunicore:plugin', + id: 'tvb_ext_unicore:plugin', autoStart: true, requires: [ ICommandPalette, @@ -73,7 +73,7 @@ const plugin: JupyterFrontEndPlugin = { console.log('JupyterLab extension tvb-ext-unicore is activated!'); let widget: MainAreaWidget; const columns = ['id', 'name', 'owner', 'site', 'status', 'start_time']; - const command = 'tvbextunicore:open'; + const command = 'tvb_ext_unicore:open'; app.commands.addCommand(command, { label: 'PyUnicore Task Stream', execute: async (args = { defaultSite: NO_SITE }): Promise => { @@ -125,7 +125,7 @@ const plugin: JupyterFrontEndPlugin = { }); widget = new MainAreaWidget({ content }); - widget.id = 'tvbextunicore'; + widget.id = 'tvb_ext_unicore'; widget.title.label = 'PyUnicore Task Stream'; widget.title.closable = true; } diff --git a/tvbextunicore/__init__.py b/tvb_ext_unicore/__init__.py similarity index 82% rename from tvbextunicore/__init__.py rename to tvb_ext_unicore/__init__.py index f73e8c3..859a5b9 100644 --- a/tvbextunicore/__init__.py +++ b/tvb_ext_unicore/__init__.py @@ -6,14 +6,14 @@ def _jupyter_labextension_paths(): return [{ "src": "labextension", - "dest": "tvbextunicore" + "dest": "tvb_ext_unicore" }] def _jupyter_server_extension_points(): return [{ - "module": "tvbextunicore" + "module": "tvb_ext_unicore" }] @@ -26,7 +26,7 @@ def _load_jupyter_server_extension(server_app): JupyterLab application instance """ setup_handlers(server_app.web_app) - server_app.log.info("Registered tvbextunicore server extension") + server_app.log.info("Registered tvb_ext_unicore server extension") # For backward compatibility with notebook server - useful for Binder/JupyterHub diff --git a/tvbextunicore/exceptions.py b/tvb_ext_unicore/exceptions.py similarity index 100% rename from tvbextunicore/exceptions.py rename to tvb_ext_unicore/exceptions.py diff --git a/tvbextunicore/handlers.py b/tvb_ext_unicore/handlers.py similarity index 88% rename from tvbextunicore/handlers.py rename to tvb_ext_unicore/handlers.py index 0c78e00..be353e0 100644 --- a/tvbextunicore/handlers.py +++ b/tvb_ext_unicore/handlers.py @@ -13,10 +13,10 @@ import tornado from tornado.web import MissingArgumentError -from tvbextunicore.exceptions import SitesDownException, FileNotExistsException, JobRunningException -from tvbextunicore.unicore_wrapper.unicore_wrapper import UnicoreWrapper -from tvbextunicore.logger.builder import get_logger -from tvbextunicore.utils import build_response, DownloadStatus +from tvb_ext_unicore.exceptions import SitesDownException, FileNotExistsException, JobRunningException +from tvb_ext_unicore.unicore_wrapper.unicore_wrapper import UnicoreWrapper +from tvb_ext_unicore.logger.builder import get_logger +from tvb_ext_unicore.utils import build_response, DownloadStatus LOGGER = get_logger(__name__) @@ -135,10 +135,10 @@ def setup_handlers(web_app): host_pattern = ".*$" base_url = web_app.settings["base_url"] - sites_pattern = url_path_join(base_url, "tvbextunicore", "sites") - jobs_pattern = url_path_join(base_url, "tvbextunicore", "jobs") - output_pattern = url_path_join(base_url, "tvbextunicore", "job_output") - drive_pattern = url_path_join(base_url, "tvbextunicore", r"drive/([^/]+)?/([^/]+)?") + sites_pattern = url_path_join(base_url, "tvb_ext_unicore", "sites") + jobs_pattern = url_path_join(base_url, "tvb_ext_unicore", "jobs") + output_pattern = url_path_join(base_url, "tvb_ext_unicore", "job_output") + drive_pattern = url_path_join(base_url, "tvb_ext_unicore", r"drive/([^/]+)?/([^/]+)?") handlers = [ (jobs_pattern, JobsHandler), (sites_pattern, SitesHandler), diff --git a/tvbextunicore/logger/__init__.py b/tvb_ext_unicore/logger/__init__.py similarity index 100% rename from tvbextunicore/logger/__init__.py rename to tvb_ext_unicore/logger/__init__.py diff --git a/tvbextunicore/logger/builder.py b/tvb_ext_unicore/logger/builder.py similarity index 100% rename from tvbextunicore/logger/builder.py rename to tvb_ext_unicore/logger/builder.py diff --git a/tvbextunicore/logger/logging.conf b/tvb_ext_unicore/logger/logging.conf similarity index 89% rename from tvbextunicore/logger/logging.conf rename to tvb_ext_unicore/logger/logging.conf index 995d6c9..416ee81 100644 --- a/tvbextunicore/logger/logging.conf +++ b/tvb_ext_unicore/logger/logging.conf @@ -2,7 +2,7 @@ ## TVB-EXT-UNICORE - logging configuration. ## ############################################ [loggers] -keys=root, tvbextunicore +keys=root, tvb_ext_unicore [handlers] keys=consoleHandler, fileHandler @@ -16,12 +16,12 @@ handlers=consoleHandler, fileHandler propagate=0 ############################################ -## tvbextunicore specific logging ## +## tvb_ext_unicore specific logging ## ############################################ -[logger_tvbextunicore] +[logger_tvb_ext_unicore] level=INFO handlers=consoleHandler, fileHandler -qualname=tvbextunicore +qualname=tvb_ext_unicore propagate=0 ############################################ diff --git a/tvbextunicore/tests/__init__.py b/tvb_ext_unicore/tests/__init__.py similarity index 100% rename from tvbextunicore/tests/__init__.py rename to tvb_ext_unicore/tests/__init__.py diff --git a/tvbextunicore/tests/test_unicore_wrapper.py b/tvb_ext_unicore/tests/test_unicore_wrapper.py similarity index 90% rename from tvbextunicore/tests/test_unicore_wrapper.py rename to tvb_ext_unicore/tests/test_unicore_wrapper.py index efaab54..0b7d4e4 100644 --- a/tvbextunicore/tests/test_unicore_wrapper.py +++ b/tvb_ext_unicore/tests/test_unicore_wrapper.py @@ -10,15 +10,15 @@ import pytest from datetime import datetime -from tvbextunicore.exceptions import TVBExtUnicoreException, SitesDownException, \ +from tvb_ext_unicore.exceptions import TVBExtUnicoreException, SitesDownException, \ FileNotExistsException, JobRunningException -from tvbextunicore.unicore_wrapper.unicore_wrapper import UnicoreWrapper, DOWNLOAD_MESSAGE -from tvbextunicore.unicore_wrapper.job_dto import JobDTO, NAME, OWNER, SITE_NAME, STATUS, SUBMISSION_TIME, \ +from tvb_ext_unicore.unicore_wrapper.unicore_wrapper import UnicoreWrapper, DOWNLOAD_MESSAGE +from tvb_ext_unicore.unicore_wrapper.job_dto import JobDTO, NAME, OWNER, SITE_NAME, STATUS, SUBMISSION_TIME, \ TERMINATION_TIME, \ MOUNT_POINT -from tvbextunicore.utils import build_response, DownloadStatus +from tvb_ext_unicore.utils import build_response, DownloadStatus -GET_JOB = 'tvbextunicore.unicore_wrapper.unicore_wrapper.UnicoreWrapper.get_job' +GET_JOB = 'tvb_ext_unicore.unicore_wrapper.unicore_wrapper.UnicoreWrapper.get_job' SHUTIL_MOVE = 'shutil.move' @@ -135,7 +135,7 @@ def test_get_jobs(mocker): def mockk(self, site=''): return MockPyUnicoreClient() - mocker.patch('tvbextunicore.unicore_wrapper.unicore_wrapper.UnicoreWrapper._UnicoreWrapper__build_client', mockk) + mocker.patch('tvb_ext_unicore.unicore_wrapper.unicore_wrapper.UnicoreWrapper._UnicoreWrapper__build_client', mockk) unicore_wrapper = UnicoreWrapper() jobs, msg = unicore_wrapper.get_jobs('TEST_SITE') @@ -153,7 +153,7 @@ def test_get_jobs_exception_at_sites(mocker): def mockk(self, site=''): raise SitesDownException(exception_msg) - mocker.patch('tvbextunicore.unicore_wrapper.unicore_wrapper.UnicoreWrapper._UnicoreWrapper__build_client', mockk) + mocker.patch('tvb_ext_unicore.unicore_wrapper.unicore_wrapper.UnicoreWrapper._UnicoreWrapper__build_client', mockk) unicore_wrapper = UnicoreWrapper() jobs, msg = unicore_wrapper.get_jobs('TEST_SITE') diff --git a/tvbextunicore/unicore_wrapper/__init__.py b/tvb_ext_unicore/unicore_wrapper/__init__.py similarity index 100% rename from tvbextunicore/unicore_wrapper/__init__.py rename to tvb_ext_unicore/unicore_wrapper/__init__.py diff --git a/tvbextunicore/unicore_wrapper/job_dto.py b/tvb_ext_unicore/unicore_wrapper/job_dto.py similarity index 100% rename from tvbextunicore/unicore_wrapper/job_dto.py rename to tvb_ext_unicore/unicore_wrapper/job_dto.py diff --git a/tvbextunicore/unicore_wrapper/unicore_wrapper.py b/tvb_ext_unicore/unicore_wrapper/unicore_wrapper.py similarity index 95% rename from tvbextunicore/unicore_wrapper/unicore_wrapper.py rename to tvb_ext_unicore/unicore_wrapper/unicore_wrapper.py index 6ca17e3..de8d30e 100644 --- a/tvbextunicore/unicore_wrapper/unicore_wrapper.py +++ b/tvb_ext_unicore/unicore_wrapper/unicore_wrapper.py @@ -10,10 +10,10 @@ import pyunicore.client as unicore_client from pyunicore.credentials import OIDCToken from requests.exceptions import ConnectionError -from tvbextunicore.exceptions import TVBExtUnicoreException, ClientAuthException, SitesDownException -from tvbextunicore.exceptions import FileNotExistsException, JobRunningException -from tvbextunicore.logger.builder import get_logger -from tvbextunicore.unicore_wrapper.job_dto import JobDTO +from tvb_ext_unicore.exceptions import TVBExtUnicoreException, ClientAuthException, SitesDownException +from tvb_ext_unicore.exceptions import FileNotExistsException, JobRunningException +from tvb_ext_unicore.logger.builder import get_logger +from tvb_ext_unicore.unicore_wrapper.job_dto import JobDTO LOGGER = get_logger(__name__) DOWNLOAD_MESSAGE = 'Downloaded successfully!' diff --git a/tvbextunicore/utils.py b/tvb_ext_unicore/utils.py similarity index 91% rename from tvbextunicore/utils.py rename to tvb_ext_unicore/utils.py index 814fcc6..f53abcb 100644 --- a/tvbextunicore/utils.py +++ b/tvb_ext_unicore/utils.py @@ -7,7 +7,7 @@ import json import enum -from tvbextunicore.logger.builder import get_logger +from tvb_ext_unicore.logger.builder import get_logger LOGGER = get_logger(__name__)