From 73e39ba3c2a335015449c413e5fd7822bc466483 Mon Sep 17 00:00:00 2001 From: mahendrapaipuri Date: Thu, 12 Oct 2023 11:13:18 +0200 Subject: [PATCH 1/3] refactor: :wrench: Move lint config to package.json --- .eslintignore | 7 ----- .eslintrc.js | 40 ---------------------------- .prettierrc | 3 --- .stylelintrc | 14 ---------- package.json | 73 +++++++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 71 insertions(+), 66 deletions(-) delete mode 100644 .eslintignore delete mode 100644 .eslintrc.js delete mode 100644 .prettierrc delete mode 100644 .stylelintrc diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index b908c37..0000000 --- a/.eslintignore +++ /dev/null @@ -1,7 +0,0 @@ -node_modules -dist -coverage -**/*.d.ts -tests -venv -.venv diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5b59bb8..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,40 +0,0 @@ -module.exports = { - extends: [ - 'eslint:recommended', - 'plugin:@typescript-eslint/eslint-recommended', - 'plugin:@typescript-eslint/recommended', - 'plugin:prettier/recommended', - ], - parser: '@typescript-eslint/parser', - parserOptions: { - project: 'tsconfig.json', - sourceType: 'module', - tsconfigRootDir: __dirname, - }, - plugins: ['@typescript-eslint'], - rules: { - '@typescript-eslint/naming-convention': [ - 'error', - { - selector: 'interface', - format: ['PascalCase'], - custom: { - regex: '^I[A-Z]', - match: true, - }, - }, - ], - '@typescript-eslint/no-unused-vars': ['warn', { args: 'none' }], - '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-namespace': 'off', - '@typescript-eslint/no-use-before-define': 'off', - '@typescript-eslint/quotes': [ - 'error', - 'single', - { avoidEscape: true, allowTemplateLiterals: false }, - ], - curly: ['error', 'all'], - eqeqeq: 'error', - 'prefer-arrow-callback': 'error', - }, -}; diff --git a/.prettierrc b/.prettierrc deleted file mode 100644 index 544138b..0000000 --- a/.prettierrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "singleQuote": true -} diff --git a/.stylelintrc b/.stylelintrc deleted file mode 100644 index e78bce6..0000000 --- a/.stylelintrc +++ /dev/null @@ -1,14 +0,0 @@ -{ - "extends": [ - "stylelint-config-recommended", - "stylelint-config-standard", - "stylelint-prettier/recommended" - ], - "rules": { - "no-empty-source": null, - "selector-class-pattern": null, - "property-no-vendor-prefix": null, - "selector-no-vendor-prefix": null, - "value-no-vendor-prefix": null - } -} diff --git a/package.json b/package.json index 7eafef3..ab1e6c2 100644 --- a/package.json +++ b/package.json @@ -39,10 +39,13 @@ "clean:lib": "rimraf lib tsconfig.tsbuildinfo", "eslint": "eslint . --ext .ts,.tsx --fix", "eslint:check": "eslint . --ext .ts,.tsx", - "lint": "jlpm run eslint && jlpm run prettier", - "lint:check": "jlpm run eslint:check && jlpm run prettier:check", + "lint": "jlpm run eslint && jlpm run prettier && jlpm stylelint", + "lint:check": "jlpm run eslint:check && jlpm run prettier:check && jlpm stylelint:check", "prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"", "prettier:check": "prettier --list-different \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"", + "stylelint": "jlpm stylelint:check --fix", + "stylelint:check": "stylelint --cache \"style/**/*.css\"", + "stylelint:files": "stylelint --fix", "install:extension": "jupyter labextension develop --overwrite .", "watch": "run-p watch:src watch:labextension", "watch:labextension": "jupyter labextension watch .", @@ -89,6 +92,72 @@ "outputDir": "jupyter_power_usage/labextension" }, "styleModule": "style/index.js", + "eslintIgnore": [ + "**/*.d.ts", + "dist", + "*node_modules*", + "coverage", + "tests", + "venv", + ".venv" + ], + "prettier": { + "singleQuote": true + }, + "eslintConfig": { + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:prettier/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "tsconfig.json", + "sourceType": "module", + "tsconfigRootDir": "." + }, + "plugins": ["@typescript-eslint"], + "rules": { + "@typescript-eslint/naming-convention": [ + "error", + { + "selector": "interface", + "format": ["PascalCase"], + "custom": { + "regex": "^I[A-Z]", + "match": true + } + } + ], + "@typescript-eslint/no-unused-vars": ["warn", { "args": "none" }], + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-namespace": "off", + "@typescript-eslint/no-use-before-define": "off", + "@typescript-eslint/quotes": [ + "error", + "single", + { "avoidEscape": true, "allowTemplateLiterals": false } + ], + "curly": ["error", "all"], + "eqeqeq": "error", + "prefer-arrow-callback": "error" + } + }, + "stylelint": { + "extends": [ + "stylelint-config-recommended", + "stylelint-config-standard", + "stylelint-prettier/recommended" + ], + "rules": { + "no-empty-source": null, + "selector-class-pattern": null, + "property-no-vendor-prefix": null, + "selector-no-vendor-prefix": null, + "value-no-vendor-prefix": null + } + }, "//": [ "These are comments that will survive: https://groups.google.com/g/nodejs/c/NmL7jdeuw0M/m/yTqI05DRQrIJ?pli=1", "Nested deps in resolutions: https://github.com/yarnpkg/rfcs/blob/master/implemented/0000-selective-versions-resolutions.md#package-designation", From 5492d90641bf6d3b7b7c3ec826fd84c475876626 Mon Sep 17 00:00:00 2001 From: mahendrapaipuri Date: Thu, 12 Oct 2023 11:13:44 +0200 Subject: [PATCH 2/3] docs: :memo: Update img URLs and add refs --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f231b64..d9a1437 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ [![PyPI](https://img.shields.io/pypi/l/jupyter-power-usage)](https://pypi.python.org/pypi/jupyter-power-usage) [![GitHub](https://img.shields.io/badge/issue_tracking-github-blue?logo=github)](https://github.com/jupyter-server/jupyter-resource-usage/issues) -![Screencast for power usage](./doc/power-usage.gif) +![Screencast for power usage](https://raw.githubusercontent.com/mahendrapaipuri/jupyter-power-usage/main/doc/power-usage.gif) The objective of this extension is to display power usage of the CPU and/or GPU on which jupyter server is running. Power usage is estimated using [Running Average Power Limit (RAPL)](https://web.eece.maine.edu/~vweaver/projects/rapl/) metrics that are available on Intel processors manufactured after 2012 (since broadwell). It is available on latest AMD processors as well. For the case of GPUs, currently only nVIDIA GPUs are supported and power usage is gathered from `nvidia-smi` tool. -Additionally, the extension is capable of estimating equivalent CO2 emissions. Emissions are estimated based on the current power usage and a emission factor that gives equivalent grams of CO2 power consumed. Currently, a [real time emission factor](https://www.rte-france.com/en/eco2mix/co2-emissions) is implemented for France and for the rest a constant configurable factor of 475 gCO2.eq/kWh is used. +Additionally, the extension is capable of estimating equivalent CO2 emissions. Emissions are estimated based on the current power usage and a emission factor that gives equivalent grams of CO2 power consumed. Currently, a [real time emission factor](https://www.rte-france.com/en/eco2mix/co2-emissions) is implemented for France and for the rest a constant configurable [factor](https://arxiv.org/pdf/2306.08323.pdf) of 475 gCO2.eq/kWh is used. The metrics are displayed in the top bar of JupyterLab and are updated at a configurable interval. The default interval is 5 seconds. RAPL can enforce power limit so as nVIDIA GPUs. If those power limits are enabled and available, they will be displayed in the indicators. @@ -64,7 +64,7 @@ By default `process` scope is used. The user can change it by CLI flag `--PowerU ### Frontend extension config -![Frontend extension settings](./doc/frontend-settings.png) +![Frontend extension settings](https://raw.githubusercontent.com/mahendrapaipuri/jupyter-power-usage/main/doc/frontend-settings.png) The frontend extension settings can be accessed by `Settings -> Advanced Settings -> Power Usage Monitor` in JupyterLab. Important settings are: @@ -92,3 +92,11 @@ pip uninstall jupyter_power_usage ``` This will uninstall python package and all the frontend related assets. + +## Troubleshooting + +- If power indicators do not show up in the JupyterLab, try reload the browser tab. + Sometimes network latencies prevent extension to load in time. + +- If there are any issues with the server side extension, they will be logged to the + same log that JupyterLab uses. From d87116a40eda3381f10f712c3a9118867012285d Mon Sep 17 00:00:00 2001 From: mahendrapaipuri Date: Thu, 12 Oct 2023 11:35:12 +0200 Subject: [PATCH 3/3] style: :art: Linted yml files Added eslint and prettier config to pre-commit config --- .github/workflows/build.yml | 38 ++++++++-------- .github/workflows/check-release.yml | 2 +- .github/workflows/lint.yml | 4 +- .github/workflows/prep-release.yml | 16 +++---- .github/workflows/publish-release.yml | 12 ++--- .github/workflows/tests.yml | 32 ++++++------- .pre-commit-config.yaml | 65 +++++++++++++++++---------- binder/environment.yml | 8 ++-- 8 files changed, 98 insertions(+), 79 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cabd8b4..4b3f982 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: Build on: push: - branches: [ main ] + branches: [main] pull_request: branches: '*' @@ -10,26 +10,26 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 - - name: Checkout - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 - - name: Base Setup - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + - name: Base Setup + uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - - name: Install dependencies - run: python -m pip install 'jupyterlab>=3.0.0,<4' + - name: Install dependencies + run: python -m pip install 'jupyterlab>=3.0.0,<4' - - name: Install the extension - run: | - python -m pip install . - jupyter server extension enable --py jupyter_power_usage --sys-prefix + - name: Install the extension + run: | + python -m pip install . + jupyter server extension enable --py jupyter_power_usage --sys-prefix - - name: Check the server and lab extensions are installed - run: | - jupyter server extension list 2>&1 | grep -ie "jupyter_power_usage.*enabled" - jupyter labextension list - jupyter labextension list 2>&1 | grep -ie "@mahendrapaipuri/jupyter-power-usage.*OK" - python -m jupyterlab.browser_check + - name: Check the server and lab extensions are installed + run: | + jupyter server extension list 2>&1 | grep -ie "jupyter_power_usage.*enabled" + jupyter labextension list + jupyter labextension list 2>&1 | grep -ie "@mahendrapaipuri/jupyter-power-usage.*OK" + python -m jupyterlab.browser_check diff --git a/.github/workflows/check-release.yml b/.github/workflows/check-release.yml index c058477..c3f1b05 100644 --- a/.github/workflows/check-release.yml +++ b/.github/workflows/check-release.yml @@ -1,7 +1,7 @@ name: Check Release on: push: - branches: [ master, main ] + branches: [master, main] pull_request: branches: - '*' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index caeaec6..3eda943 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,9 +2,9 @@ name: Lint on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: lint: diff --git a/.github/workflows/prep-release.yml b/.github/workflows/prep-release.yml index 7a2a18d..2ab4276 100644 --- a/.github/workflows/prep-release.yml +++ b/.github/workflows/prep-release.yml @@ -1,22 +1,22 @@ -name: "Step 1: Prep Release" +name: 'Step 1: Prep Release' on: workflow_dispatch: inputs: version_spec: - description: "New Version Specifier" - default: "next" + description: 'New Version Specifier' + default: 'next' required: false branch: - description: "The branch to target" + description: 'The branch to target' required: false post_version_spec: - description: "Post Version Specifier" + description: 'Post Version Specifier' required: false since: - description: "Use PRs with activity since this date or git reference" + description: 'Use PRs with activity since this date or git reference' required: false since_last_stable: - description: "Use PRs with activity since the last stable git tag" + description: 'Use PRs with activity since the last stable git tag' required: false type: boolean jobs: @@ -37,6 +37,6 @@ jobs: since: ${{ github.event.inputs.since }} since_last_stable: ${{ github.event.inputs.since_last_stable }} - - name: "** Next Step **" + - name: '** Next Step **' run: | echo "Optional): Review Draft Release: ${{ steps.prep-release.outputs.release_url }}" diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index da0dc3c..faa9088 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,15 +1,15 @@ -name: "Step 2: Publish Release" +name: 'Step 2: Publish Release' on: workflow_dispatch: inputs: branch: - description: "The target branch" + description: 'The target branch' required: false release_url: - description: "The URL of the draft GitHub release" + description: 'The URL of the draft GitHub release' required: false steps_to_skip: - description: "Comma separated list of steps to skip" + description: 'Comma separated list of steps to skip' required: false jobs: @@ -46,13 +46,13 @@ jobs: target: ${{ github.event.inputs.target }} release_url: ${{ steps.populate-release.outputs.release_url }} - - name: "** Next Step **" + - name: '** Next Step **' if: ${{ success() }} run: | echo "Verify the final release" echo ${{ steps.finalize-release.outputs.release_url }} - - name: "** Failure Message **" + - name: '** Failure Message **' if: ${{ failure() }} run: | echo "Failed to Publish the Draft Release Url:" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0b97e8c..fd85805 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,9 +2,9 @@ name: Tests on: push: - branches: [ main ] + branches: [main] pull_request: - branches: [ main ] + branches: [main] jobs: build: @@ -13,26 +13,26 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - python-version: ["3.8", "3.11"] + python-version: ['3.8', '3.11'] steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 - - name: Base Setup - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + - name: Base Setup + uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - - name: Install dependencies - run: | - python -m pip install -e ".[dev]" + - name: Install dependencies + run: | + python -m pip install -e ".[dev]" - - name: Lint with flake8 - run: | - python -m flake8 jupyter_power_usage + - name: Lint with flake8 + run: | + python -m flake8 jupyter_power_usage - - name: Test with pytest - run: | - python -m pytest + - name: Test with pytest + run: | + python -m pytest check_links: runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a0ff64..af3f912 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,24 +1,43 @@ repos: -- repo: https://github.com/asottile/reorder-python-imports - rev: v3.12.0 - hooks: - - id: reorder-python-imports - language_version: python3 -- repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black -- repo: https://github.com/PyCQA/flake8 - rev: "6.1.0" - hooks: - - id: flake8 -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 - hooks: - - id: end-of-file-fixer - - id: check-json - - id: check-yaml - exclude: ^helm-chart/nbviewer/templates/ - - id: check-case-conflict - - id: check-executables-have-shebangs - - id: requirements-txt-fixer + - repo: https://github.com/asottile/reorder-python-imports + rev: v3.12.0 + hooks: + - id: reorder-python-imports + language_version: python3 + - repo: https://github.com/psf/black + rev: 23.9.1 + hooks: + - id: black + - repo: https://github.com/PyCQA/flake8 + rev: '6.1.0' + hooks: + - id: flake8 + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v2.1.1 + hooks: + - id: prettier + additional_dependencies: + - prettier@2.1.1 + - repo: https://github.com/pre-commit/mirrors-eslint + rev: v7.32.0 + hooks: + - id: eslint + files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx + types: [file] + additional_dependencies: + - '@typescript-eslint/eslint-plugin@4.8.1' + - '@typescript-eslint/parser@4.8.1' + - eslint@^7.14.0 + - eslint-config-prettier@6.15.0 + - eslint-plugin-prettier@3.1.4 + - typescript@4.1.3 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: end-of-file-fixer + - id: check-json + - id: check-yaml + exclude: ^helm-chart/nbviewer/templates/ + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: requirements-txt-fixer diff --git a/binder/environment.yml b/binder/environment.yml index 102d194..02bde57 100644 --- a/binder/environment.yml +++ b/binder/environment.yml @@ -1,7 +1,7 @@ name: jupyter-resource-usage channels: -- conda-forge + - conda-forge dependencies: -- python=3 -- jupyterlab=3 -- nodejs=18 + - python=3 + - jupyterlab=3 + - nodejs=18