From f492d09e42bc26090a0086dbe2f7bab63eb427e9 Mon Sep 17 00:00:00 2001 From: Jeremy Tuloup Date: Wed, 2 Dec 2020 21:31:05 +0100 Subject: [PATCH] Rename to jupyter-resource-usage --- .github/workflows/tests.yml | 4 +-- .travis.yml | 2 +- CHANGELOG.md | 32 +++++++++---------- CONTRIBUTING.md | 18 +++++------ README.md | 26 +++++++-------- RELEASE.md | 10 +++--- binder/environment.yml | 4 +-- .../__init__.py | 17 +++++----- {nbresuse => jupyter_resource_usage}/api.py | 2 +- .../config.py | 4 +-- jupyter_resource_usage/etc/nbextension.json | 5 +++ .../etc/serverextension.json | 2 +- .../metrics.py | 2 +- .../prometheus.py | 3 +- .../static/main.js | 14 ++++---- .../tests/__init__.py | 0 .../tests/test_basic.py | 20 +++++++----- {nbresuse => jupyter_resource_usage}/utils.py | 0 nbresuse/etc/nbextension.json | 5 --- setup.cfg | 2 +- setup.py | 18 +++++++---- 21 files changed, 99 insertions(+), 91 deletions(-) rename {nbresuse => jupyter_resource_usage}/__init__.py (67%) rename {nbresuse => jupyter_resource_usage}/api.py (96%) rename {nbresuse => jupyter_resource_usage}/config.py (96%) create mode 100644 jupyter_resource_usage/etc/nbextension.json rename {nbresuse => jupyter_resource_usage}/etc/serverextension.json (62%) rename {nbresuse => jupyter_resource_usage}/metrics.py (97%) rename {nbresuse => jupyter_resource_usage}/prometheus.py (97%) rename {nbresuse => jupyter_resource_usage}/static/main.js (78%) rename {nbresuse => jupyter_resource_usage}/tests/__init__.py (100%) rename {nbresuse => jupyter_resource_usage}/tests/test_basic.py (72%) rename {nbresuse => jupyter_resource_usage}/utils.py (100%) delete mode 100644 nbresuse/etc/nbextension.json diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5eec54e..71be1ef 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -26,7 +26,7 @@ jobs: python -m pip install --upgrade pip python -m pip install -e ".[dev]" - name: Lint with flake8 - run: python -m flake8 nbresuse + run: python -m flake8 jupyter_resource_usage - name: Test with pytest run: | - python -m pytest -vvv nbresuse --cov=nbresuse --junitxml=python_junit.xml --cov-report=xml --cov-branch + python -m pytest -vvv jupyter_resource_usage --cov=jupyter_resource_usage --junitxml=python_junit.xml --cov-report=xml --cov-branch diff --git a/.travis.yml b/.travis.yml index 40d5f33..c831fe8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ install: - pip install --editable . script: -- python -m pytest -vvv nbresuse +- python -m pytest -vvv jupyter-resource-usage jobs: diff --git a/CHANGELOG.md b/CHANGELOG.md index 9665c7b..db97bf3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,8 @@ ## 0.4.0 -- Soft-deprecate `/metrics` endpoint: [#68](https://github.com/yuvipanda/jupyter-resource-usage/pull/68) -- `nbresuse` now exposes a new endpoint: `/api/metrics/v1`: [#68](https://github.com/yuvipanda/jupyter-resource-usage/pull/68) +- Soft-deprecate `/metrics` endpoint: [#68](https://github.com/jupyter-server/jupyter-resource-usage/pull/68) +- `nbresuse` now exposes a new endpoint: `/api/metrics/v1`: [#68](https://github.com/jupyter-server/jupyter-resource-usage/pull/68) ### Migrating to 0.4.0 @@ -30,43 +30,43 @@ jupyter lab --ResourceUseDisplay.disable_legacy_endpoint=False ## 0.3.6 -- Fix handling of cpu percent in the API endpoint [#56](https://github.com/yuvipanda/jupyter-resource-usage/pull/56) -- Added Binder [#53](https://github.com/yuvipanda/jupyter-resource-usage/pull/53) & RELEASE.md [#54](https://github.com/yuvipanda/jupyter-resource-usage/pull/54) +- Fix handling of cpu percent in the API endpoint [#56](https://github.com/jupyter-server/jupyter-resource-usage/pull/56) +- Added Binder [#53](https://github.com/jupyter-server/jupyter-resource-usage/pull/53) & RELEASE.md [#54](https://github.com/jupyter-server/jupyter-resource-usage/pull/54) ## 0.3.5 -- Adding support for jupyterlab statusbar-extension [#45](https://github.com/yuvipanda/jupyter-resource-usage/pull/45) [#36](https://github.com/yuvipanda/jupyter-resource-usage/issues/36) +- Adding support for jupyterlab statusbar-extension [#45](https://github.com/jupyter-server/jupyter-resource-usage/pull/45) [#36](https://github.com/jupyter-server/jupyter-resource-usage/issues/36) **Note**: this release restores the `/metrics` endpoint returning a JSON response, that was removed in `0.3.4`. ## 0.3.4 -- Autoformatting and documentation [#33](https://github.com/yuvipanda/jupyter-resource-usage/pull/33) -- Add section about CPU usage to the README [#30](https://github.com/yuvipanda/jupyter-resource-usage/pull/30) -- Make psutil optional dependency of NBResuse [#25](https://github.com/yuvipanda/jupyter-resource-usage/pull/25) -- Report the memory usage metrics as prometheus metrics [#22](https://github.com/yuvipanda/jupyter-resource-usage/pull/22) +- Autoformatting and documentation [#33](https://github.com/jupyter-server/jupyter-resource-usage/pull/33) +- Add section about CPU usage to the README [#30](https://github.com/jupyter-server/jupyter-resource-usage/pull/30) +- Make psutil optional dependency of NBResuse [#25](https://github.com/jupyter-server/jupyter-resource-usage/pull/25) +- Report the memory usage metrics as prometheus metrics [#22](https://github.com/jupyter-server/jupyter-resource-usage/pull/22) **Note**: this release removed the `/metrics` endpoint that was returning a JSON response. As a result, JupyterLab does not display the memory usage indicator in the status bar with `nbresuse==0.3.4`. ## 0.3.3 -- Made memory limit possibly dynamic via passing a callable in the config. [#23](https://github.com/yuvipanda/jupyter-resource-usage/pull/23) -- Track CPU usage [#21](https://github.com/yuvipanda/jupyter-resource-usage/pull/21) +- Made memory limit possibly dynamic via passing a callable in the config. [#23](https://github.com/jupyter-server/jupyter-resource-usage/pull/23) +- Track CPU usage [#21](https://github.com/jupyter-server/jupyter-resource-usage/pull/21) ## 0.3.2 -- Require authentication for /metrics API Handler [#18](https://github.com/yuvipanda/jupyter-resource-usage/pull/18) +- Require authentication for /metrics API Handler [#18](https://github.com/jupyter-server/jupyter-resource-usage/pull/18) ## 0.3.1 -- Don't poll in background, since user does not see it [#15](https://github.com/yuvipanda/jupyter-resource-usage/pull/15) -- Poll instantly once page is foregrounded [#15](https://github.com/yuvipanda/jupyter-resource-usage/pull/15) +- Don't poll in background, since user does not see it [#15](https://github.com/jupyter-server/jupyter-resource-usage/pull/15) +- Poll instantly once page is foregrounded [#15](https://github.com/jupyter-server/jupyter-resource-usage/pull/15) This should reduce the number of /metrics requests massively, with minimal interruption to user experience. ## 0.3.0 -- Automatically install & enable extensions [#9](https://github.com/yuvipanda/jupyter-resource-usage/pull/9) +- Automatically install & enable extensions [#9](https://github.com/jupyter-server/jupyter-resource-usage/pull/9) - Put nbextension / serverextension enables in different places - Put nbresuse js files in appropriate path @@ -74,7 +74,7 @@ This should reduce the number of /metrics requests massively, with minimal inter - Change 'Mem' prefix in display to less cryptic 'Memory' - Fix primary screenshot to show memory limit too -- Distribute static files via package_data [#1](https://github.com/yuvipanda/jupyter-resource-usage/pull/1) +- Distribute static files via package_data [#1](https://github.com/jupyter-server/jupyter-resource-usage/pull/1) - Add screenshot for memory usage warning - Configurable memory usage warnings - More configurability via traitlets diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ada4f16..6fc55bc 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing -Contributions to NBResuse are highly welcome! As a [Jupyter](https://jupyter.org) project, +Contributions to jupyter-resource-usage are highly welcome! As a [Jupyter](https://jupyter.org) project, you can follow the [Jupyter contributor guide](https://jupyter.readthedocs.io/en/latest/contributor/content-contributor.html). Make sure to also follow [Project Jupyter's Code of Conduct](https://github.com/jupyter/governance/blob/master/conduct/code_of_conduct.md) @@ -13,13 +13,13 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier 1. Clone the git repository: ```bash - git clone https://github.com/yuvipanda/nbresuse + git clone https://github.com/jupyter-server/jupyter-resource-usage ``` 2. Create an environment that will hold our dependencies. ```bash - cd nbresuse + cd jupyter-resource-usage pipenv --python 3.6 ``` @@ -29,7 +29,7 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier pipenv shell ``` -4. Do a dev install of nbresuse and its dependencies +4. Do a dev install of jupyter-resource-usage and its dependencies ```bash pip install --editable .[dev] @@ -38,9 +38,9 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier 5. Install and enable the nbextension for use with Jupyter Classic Notebook. ```bash - jupyter nbextension install --py nbresuse --symlink --sys-prefix - jupyter serverextension enable --py nbresuse --sys-prefix - jupyter nbextension enable --py nbresuse --sys-prefix + jupyter nbextension install --py jupyter-resource-usage --symlink --sys-prefix + jupyter serverextension enable --py jupyter-resource-usage --sys-prefix + jupyter nbextension enable --py jupyter-resource-usage --sys-prefix ``` 6. Start a Jupyter Notebook instance, open a new notebook and check out the memory usage @@ -57,7 +57,7 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier MEM_LIMIT=$(expr 128 \* 1024 \* 1024) jupyter notebook ``` -8. NBResuse has adopted automatic code formatting so you shouldn't +8. jupyter-resource-usage has adopted automatic code formatting so you shouldn't need to worry too much about your code style. As long as your code is valid, the pre-commit hook should take care of how it should look. Here is how to set up pre-commit hooks for automatic code formatting, etc. @@ -86,7 +86,7 @@ yourself after that. or that trigger any bugs that you have fixed to catch regressions. `pytest` is used to run the test suite. You can run the tests with: ```bash -python -m pytest -vvv nbresuse +python -m pytest -vvv jupyter-resource-usage ``` in the repo directory. diff --git a/README.md b/README.md index 3ba3bb4..a155e6b 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,17 @@ **[Resources Displayed](#resources-displayed)** | **[Contributing](#contributing)** -# NBResuse +# jupyter-resource-usage -![Github Actions Status](https://github.com/yuvipanda/nbresuse/workflows/Tests/badge.svg) -[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/yuvipanda/nbresuse/stable) -[![PyPI](https://img.shields.io/pypi/v/nbresuse)](https://pypi.python.org/pypi/nbresuse) -[![PyPI](https://img.shields.io/pypi/l/nbresuse)](https://pypi.python.org/pypi/nbresuse) -[![GitHub](https://img.shields.io/badge/issue_tracking-github-blue?logo=github)](https://github.com/yuvipanda/nbresuse/issues) +![Github Actions Status](https://github.com/jupyter-server/jupyter-resource-usage/workflows/Tests/badge.svg) +[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyter-server/jupyter-resource-usage/stable) +[![PyPI](https://img.shields.io/pypi/v/jupyter-resource-usage)](https://pypi.python.org/pypi/jupyter-resource-usage) +[![PyPI](https://img.shields.io/pypi/l/jupyter-resource-usage)](https://pypi.python.org/pypi/jupyter-resource-usage) +[![GitHub](https://img.shields.io/badge/issue_tracking-github-blue?logo=github)](https://github.com/jupyter-server/jupyter-resource-usage/issues) ![Screenshot with memory limit](screenshot.png) -NB Resource Usage (NBResuse) is a small extension for Jupyter Notebooks that +Jupyter Resource Usage is an extension for Jupyter Notebooks and JupyterLab that displays an indication of how much resources your current notebook server and its children (kernels, terminals, etc) are using. This is displayed in the main toolbar in the notebook itself, refreshing every 5s. @@ -23,22 +23,22 @@ main toolbar in the notebook itself, refreshing every 5s. You can currently install this package from PyPI. ```bash -pip install nbresuse +pip install jupyter-resource-usage ``` **If your notebook version is < 5.3**, you need to enable the extension manually. ``` -jupyter serverextension enable --py nbresuse --sys-prefix -jupyter nbextension install --py nbresuse --sys-prefix -jupyter nbextension enable --py nbresuse --sys-prefix +jupyter serverextension enable --py jupyter-resource-usage --sys-prefix +jupyter nbextension install --py jupyter-resource-usage --sys-prefix +jupyter nbextension enable --py jupyter-resource-usage --sys-prefix ``` ## Configuration ### Memory Limit -`nbresuse` can display a memory limit (but not enforce it). You can set this +`jupyter-resource-usage` can display a memory limit (but not enforce it). You can set this in several ways: 1. `MEM_LIMIT` environment variable. This is set by [JupyterHub](https://github.com/jupyterhub/jupyterhub/) @@ -61,7 +61,7 @@ can set the parameter `--ResourceUseDisplay.mem_warning_threshold=0.1`. ### CPU Usage -`nbresuse` can also track CPU usage and report a `cpu_percent` value as part of the `/metrics` response. +`jupyter-resource-usage` can also track CPU usage and report a `cpu_percent` value as part of the `/metrics` response. You can set the `cpu_limit` in several ways: diff --git a/RELEASE.md b/RELEASE.md index 236c13b..8af0f8b 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,12 +1,12 @@ -# Making a new release of nbresuse +# Making a new release of jupyter-resource-usage ## Getting a clean environment Creating a new environment can help avoid pushing local changes and any extra tag. ```bash -conda create -n nbresuse-release -c conda-forge twine keyring -conda activate nbresuse-release +conda create -n jupyter-resource-usage-release -c conda-forge twine keyring +conda activate jupyter-resource-usage-release ``` Alternatively, the local repository can be cleaned with: @@ -23,7 +23,7 @@ Make sure the `dist/` folder is empty. 2. `python setup.py sdist bdist_wheel` 3. Double check the size of the bundles in the `dist/` folder 4. Run the tests - - `pip install "dist/nbresuse-X.Y.Z-py3-none-any.whl[dev]"` + - `pip install "dist/jupyter-resource-usage-X.Y.Z-py3-none-any.whl[dev]"` - `python -m pytest` 5. `export TWINE_USERNAME=mypypi_username` 6. `twine upload dist/*` @@ -34,7 +34,7 @@ The easiest is to wait for the bot to open the PR automatically. To do the release manually: -1. Open a new PR on https://github.com/conda-forge/nbresuse-feedstock to update the `version` and the `sha256` hash +1. Open a new PR on https://github.com/conda-forge/jupyter-resource-usage-feedstock to update the `version` and the `sha256` hash 2. Wait for the tests 3. Merge the PR diff --git a/binder/environment.yml b/binder/environment.yml index 6345537..d438847 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -1,8 +1,8 @@ -name: nbresuse +name: jupyter-resource-usage channels: - conda-forge dependencies: - python=3 - jupyterlab=2 -- nbresuse=0.3.6 +- jupyter_resource_usage=0.3.6 - nodejs diff --git a/nbresuse/__init__.py b/jupyter_resource_usage/__init__.py similarity index 67% rename from nbresuse/__init__.py rename to jupyter_resource_usage/__init__.py index 64e6b70..d111d65 100644 --- a/nbresuse/__init__.py +++ b/jupyter_resource_usage/__init__.py @@ -1,17 +1,16 @@ +from jupyter_resource_usage.api import ApiHandler +from jupyter_resource_usage.config import ResourceUseDisplay +from jupyter_resource_usage.metrics import PSUtilMetricsLoader +from jupyter_resource_usage.prometheus import PrometheusHandler from notebook.utils import url_path_join from tornado import ioloop -from nbresuse.api import ApiHandler -from nbresuse.config import ResourceUseDisplay -from nbresuse.metrics import PSUtilMetricsLoader -from nbresuse.prometheus import PrometheusHandler - def _jupyter_server_extension_paths(): """ Set up the server extension for collecting metrics """ - return [{"module": "nbresuse"}] + return [{"module": "jupyter_resource_usage"}] def _jupyter_nbextension_paths(): @@ -21,9 +20,9 @@ def _jupyter_nbextension_paths(): return [ { "section": "notebook", - "dest": "nbresuse", + "dest": "jupyter_resource_usage", "src": "static", - "require": "nbresuse/main", + "require": "jupyter_resource_usage/main", } ] @@ -33,7 +32,7 @@ def load_jupyter_server_extension(nbapp): Called during notebook start """ resuseconfig = ResourceUseDisplay(parent=nbapp) - nbapp.web_app.settings["nbresuse_display_config"] = resuseconfig + nbapp.web_app.settings["jupyter_resource_usage_display_config"] = resuseconfig base_url = nbapp.web_app.settings["base_url"] if not resuseconfig.disable_legacy_endpoint: diff --git a/nbresuse/api.py b/jupyter_resource_usage/api.py similarity index 96% rename from nbresuse/api.py rename to jupyter_resource_usage/api.py index 8f2ba5f..5478305 100644 --- a/nbresuse/api.py +++ b/jupyter_resource_usage/api.py @@ -22,7 +22,7 @@ async def get(self): """ Calculate and return current resource usage metrics """ - config = self.settings["nbresuse_display_config"] + config = self.settings["jupyter_resource_usage_display_config"] cur_process = psutil.Process() all_processes = [cur_process] + cur_process.children(recursive=True) diff --git a/nbresuse/config.py b/jupyter_resource_usage/config.py similarity index 96% rename from nbresuse/config.py rename to jupyter_resource_usage/config.py index 295c296..847ad96 100644 --- a/nbresuse/config.py +++ b/jupyter_resource_usage/config.py @@ -34,7 +34,7 @@ def validate(self, obj, value): class ResourceUseDisplay(Configurable): """ - Holds server-side configuration for nbresuse + Holds server-side configuration for jupyter-resource-usage """ disable_legacy_endpoint = Bool( @@ -42,7 +42,7 @@ class ResourceUseDisplay(Configurable): help=""" Disable legacy /metrics endpoint - This prevents nbresuse from shadowing the prometheus /metrics endpoint. + This prevents jupyter-resource-usage from shadowing the prometheus /metrics endpoint. """, config=True, ) diff --git a/jupyter_resource_usage/etc/nbextension.json b/jupyter_resource_usage/etc/nbextension.json new file mode 100644 index 0000000..23d093c --- /dev/null +++ b/jupyter_resource_usage/etc/nbextension.json @@ -0,0 +1,5 @@ +{ + "load_extensions": { + "jupyter_resource_usage/main": true + } +} diff --git a/nbresuse/etc/serverextension.json b/jupyter_resource_usage/etc/serverextension.json similarity index 62% rename from nbresuse/etc/serverextension.json rename to jupyter_resource_usage/etc/serverextension.json index ae39ec9..935a9b2 100644 --- a/nbresuse/etc/serverextension.json +++ b/jupyter_resource_usage/etc/serverextension.json @@ -1,7 +1,7 @@ { "NotebookApp": { "nbserver_extensions": { - "nbresuse": true + "jupyter_resource_usage": true } } } diff --git a/nbresuse/metrics.py b/jupyter_resource_usage/metrics.py similarity index 97% rename from nbresuse/metrics.py rename to jupyter_resource_usage/metrics.py index 6352d76..7532b9c 100644 --- a/nbresuse/metrics.py +++ b/jupyter_resource_usage/metrics.py @@ -8,7 +8,7 @@ class PSUtilMetricsLoader: def __init__(self, nbapp: NotebookApp): - self.config = nbapp.web_app.settings["nbresuse_display_config"] + self.config = nbapp.web_app.settings["jupyter_resource_usage_display_config"] self.nbapp = nbapp def get_process_metric_value(self, process, name, kwargs, attribute=None): diff --git a/nbresuse/prometheus.py b/jupyter_resource_usage/prometheus.py similarity index 97% rename from nbresuse/prometheus.py rename to jupyter_resource_usage/prometheus.py index 15e7db1..76ad49a 100644 --- a/nbresuse/prometheus.py +++ b/jupyter_resource_usage/prometheus.py @@ -1,10 +1,9 @@ from typing import Optional +from jupyter_resource_usage.metrics import PSUtilMetricsLoader from notebook.notebookapp import NotebookApp from prometheus_client import Gauge -from nbresuse.metrics import PSUtilMetricsLoader - try: # Traitlets >= 4.3.3 from traitlets import Callable diff --git a/nbresuse/static/main.js b/jupyter_resource_usage/static/main.js similarity index 78% rename from nbresuse/static/main.js rename to jupyter_resource_usage/static/main.js index 8c0cfcb..00d2352 100644 --- a/nbresuse/static/main.js +++ b/jupyter_resource_usage/static/main.js @@ -4,22 +4,22 @@ define([ ], function ($, utils) { function setupDOM() { $('#maintoolbar-container').append( - $('
').attr('id', 'nbresuse-display') + $('
').attr('id', 'jupyter-resource-usage-display') .addClass('btn-group') .addClass('pull-right') .append( $('').text('Memory: ') ).append( - $('').attr('id', 'nbresuse-mem') + $('').attr('id', 'jupyter-resource-usage-mem') .attr('title', 'Actively used Memory (updates every 5s)') ) ); // FIXME: Do something cleaner to get styles in here? $('head').append( - $('