From 8d6f69884cda8a0d5c157c6343c3ca7619b9790d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 8 Dec 2022 21:40:21 -0600 Subject: [PATCH 1/3] adopt linters and releaser --- .github/dependabot.yml | 6 ++- .github/workflows/python-tests.yml | 45 ++++++++++++++--- comm/__init__.py | 3 +- comm/base_comm.py | 16 +++--- pyproject.toml | 79 +++++++++++++++++++++++++++++- tests/test_comm.py | 5 +- 6 files changed, 131 insertions(+), 23 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f10a5bc..cbd920f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,8 +1,10 @@ version: 2 updates: - # Set update schedule for GitHub Actions - package-ecosystem: "github-actions" directory: "/" schedule: - # Check for updates to GitHub Actions every weekday + interval: "weekly" + - package-ecosystem: "pip" + directory: "/" + schedule: interval: "weekly" diff --git a/.github/workflows/python-tests.yml b/.github/workflows/python-tests.yml index 8567aa0..7d10863 100644 --- a/.github/workflows/python-tests.yml +++ b/.github/workflows/python-tests.yml @@ -14,14 +14,14 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.7", "3.10"] + python-version: ["3.7", "3.11"] include: - os: windows-latest python-version: "3.9" - os: ubuntu-latest python-version: "pypy-3.8" - os: ubuntu-latest - python-version: "3.11" + python-version: "3.10" - os: macos-latest python-version: "3.8" steps: @@ -29,7 +29,40 @@ jobs: uses: actions/checkout@v3 - name: Base Setup uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - - name: Install and test - run: - pip install -e .[test] - pytest + - name: Run test + run: hatch run test:test + + test_lint: + name: Test Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + - name: Run Linters + run: | + hatch run typing:test + hatch run lint:style + pipx run 'validate-pyproject[all]' pyproject.toml + + check_release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Base Setup + uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + - name: Install Dependencies + run: | + pip install -e . + - name: Check Release + uses: jupyter-server/jupyter_releaser/.github/actions/check-release@v2 + with: + version_spec: 100.100.100 + token: ${{ secrets.GITHUB_TOKEN }} + + check_links: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + - uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1 diff --git a/comm/__init__.py b/comm/__init__.py index f8c66a0..ee9e76a 100644 --- a/comm/__init__.py +++ b/comm/__init__.py @@ -3,7 +3,8 @@ Copyright (c) IPython Development Team. Distributed under the terms of the Modified BSD License. -This package provides a way to register a Kernel Comm implementation, as per the Jupyter kernel protocol. +This package provides a way to register a Kernel Comm implementation, as per +the Jupyter kernel protocol. It also provides a base Comm implementation and a default CommManager for the IPython case. """ diff --git a/comm/base_comm.py b/comm/base_comm.py index 0b51ef8..eeddfdc 100644 --- a/comm/base_comm.py +++ b/comm/base_comm.py @@ -4,14 +4,14 @@ # Copyright (c) IPython Development Team. # Distributed under the terms of the Modified BSD License. -import uuid import logging -import comm +import uuid from traitlets.utils.importstring import import_item -logger = logging.getLogger('Comm') +import comm +logger = logging.getLogger("Comm") class BaseComm: @@ -35,7 +35,7 @@ def __init__( _close_data=None, **kwargs, ): - super(BaseComm, self).__init__(**kwargs) + super().__init__(**kwargs) self.comm_id = comm_id if comm_id else uuid.uuid4().hex self.primary = primary @@ -66,7 +66,7 @@ def __del__(self): # publishing messages - def open(self, data=None, metadata=None, buffers=None): + def open(self, data=None, metadata=None, buffers=None): # noqa """Open the frontend-side version of this comm""" if data is None: @@ -149,7 +149,7 @@ def handle_msg(self, msg): """Handle a comm_msg message""" logger.debug("handle_msg[%s](%s)", self.comm_id, msg) if self._msg_callback: - from IPython import get_ipython + from IPython import get_ipython # type:ignore shell = get_ipython() if shell: @@ -237,9 +237,7 @@ def comm_open(self, stream, ident, msg): f(comm, msg) return except Exception: - logger.error( - "Exception opening comm with target: %s", target_name, exc_info=True - ) + logger.error("Exception opening comm with target: %s", target_name, exc_info=True) # Failure. try: diff --git a/pyproject.toml b/pyproject.toml index 4070079..a70065a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["hatchling>1.10"] +requires = ["hatchling>=1.10"] build-backend = "hatchling.build" [project] @@ -22,11 +22,11 @@ classifiers = [ "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", ] dependencies = [ "traitlets>=5.3", @@ -36,6 +36,13 @@ dependencies = [ test = [ "pytest", ] +lint = [ + "black>=22.6.0", + "mdformat>0.7", + "mdformat-gfm>=0.3.5", + "ruff>=0.0.156" +] +typing = ["mypy>=0.990"] [project.urls] Homepage = "https://github.com/ipython/comm" @@ -48,6 +55,74 @@ include = [ "/comm", ] +[tool.hatch.envs.test] +features = ["test"] +[tool.hatch.envs.test.scripts] +test = "python -m pytest -vv {args}" +nowarn = "test -W default {args}" + +[tool.hatch.envs.typing] +features = ["typing", "test"] +[tool.hatch.envs.typing.scripts] +test = "mypy --install-types --non-interactive {args:comm tests}" + +[tool.hatch.envs.lint] +features = ["lint"] +[tool.hatch.envs.lint.scripts] +style = [ + "ruff {args:.}", + "black --check --diff {args:.}", + "mdformat --check {args:*.md}" +] +fmt = [ + "black {args:.}", + "ruff --fix {args:.}", + "mdformat {args:*.md}" +] + [tool.pytest.ini_options] addopts = "-raXs --durations 10 --color=yes" filterwarnings = ["error"] + +[tool.mypy] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_untyped_decorators = true +no_implicit_optional = true +no_implicit_reexport = true +pretty = true +show_error_context = true +show_error_codes = true +strict_equality = true +strict_optional = true +warn_unused_configs = true +warn_redundant_casts = true +warn_return_any = true +warn_unused_ignores = true + +[tool.black] +line-length = 100 +skip-string-normalization = true +target-version = ["py37"] + +[tool.ruff] +target-version = "py37" +line-length = 100 +select = [ + "A", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T", + "UP", "W", "YTT", +] +ignore = [ + # FBT002 Boolean default value in function definition + "FBT002", "FBT003", +] +unfixable = [ + # Don't touch print statements + "T201", + # Don't touch noqa lines + "RUF100", +] + +[tool.ruff.per-file-ignores] +# S101 Use of `assert` detected +"tests/*" = ["S101"] diff --git a/tests/test_comm.py b/tests/test_comm.py index 9e8f8e1..15bdb99 100644 --- a/tests/test_comm.py +++ b/tests/test_comm.py @@ -1,8 +1,7 @@ -from comm.base_comm import CommManager, BaseComm +from comm.base_comm import BaseComm, CommManager class MyComm(BaseComm): - def publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys): pass @@ -14,4 +13,4 @@ def test_comm_manager(): def test_base_comm(): test = MyComm() - assert test.target_name == "comm" \ No newline at end of file + assert test.target_name == "comm" From 9274668178d486dc0adacf9b2e5ad7bbb0bfb242 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 8 Dec 2022 21:45:18 -0600 Subject: [PATCH 2/3] add changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6981c95 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +All notable changes to this project will be documented in this file. + + + +## 0.1.2 + +Initial release + + From a0625fe81c98136b74c91c9b1229f0a11cdebc8d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Thu, 8 Dec 2022 21:46:03 -0600 Subject: [PATCH 3/3] add releaser workflows --- .github/workflows/prep-release.yml | 42 +++++++++++++++++++++ .github/workflows/publish-release.yml | 54 +++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 .github/workflows/prep-release.yml create mode 100644 .github/workflows/publish-release.yml diff --git a/.github/workflows/prep-release.yml b/.github/workflows/prep-release.yml new file mode 100644 index 0000000..7a2a18d --- /dev/null +++ b/.github/workflows/prep-release.yml @@ -0,0 +1,42 @@ +name: "Step 1: Prep Release" +on: + workflow_dispatch: + inputs: + version_spec: + description: "New Version Specifier" + default: "next" + required: false + branch: + description: "The branch to target" + required: false + post_version_spec: + description: "Post Version Specifier" + required: false + since: + 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" + required: false + type: boolean +jobs: + prep_release: + runs-on: ubuntu-latest + steps: + - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + + - name: Prep Release + id: prep-release + uses: jupyter-server/jupyter_releaser/.github/actions/prep-release@v2 + with: + token: ${{ secrets.ADMIN_GITHUB_TOKEN }} + version_spec: ${{ github.event.inputs.version_spec }} + post_version_spec: ${{ github.event.inputs.post_version_spec }} + target: ${{ github.event.inputs.target }} + branch: ${{ github.event.inputs.branch }} + since: ${{ github.event.inputs.since }} + since_last_stable: ${{ github.event.inputs.since_last_stable }} + + - 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 new file mode 100644 index 0000000..dbaaeaa --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,54 @@ +name: "Step 2: Publish Release" +on: + workflow_dispatch: + inputs: + branch: + description: "The target branch" + required: false + release_url: + description: "The URL of the draft GitHub release" + required: false + steps_to_skip: + description: "Comma separated list of steps to skip" + required: false + +jobs: + publish_release: + runs-on: ubuntu-latest + steps: + - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 + + - name: Populate Release + id: populate-release + uses: jupyter-server/jupyter_releaser/.github/actions/populate-release@v2 + with: + token: ${{ secrets.ADMIN_GITHUB_TOKEN }} + target: ${{ github.event.inputs.target }} + branch: ${{ github.event.inputs.branch }} + release_url: ${{ github.event.inputs.release_url }} + steps_to_skip: ${{ github.event.inputs.steps_to_skip }} + + - name: Finalize Release + id: finalize-release + env: + PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} + PYPI_TOKEN_MAP: ${{ secrets.PYPI_TOKEN_MAP }} + TWINE_USERNAME: __token__ + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + uses: jupyter-server/jupyter-releaser/.github/actions/finalize-release@v2 + with: + token: ${{ secrets.ADMIN_GITHUB_TOKEN }} + target: ${{ github.event.inputs.target }} + release_url: ${{ steps.populate-release.outputs.release_url }} + + - name: "** Next Step **" + if: ${{ success() }} + run: | + echo "Verify the final release" + echo ${{ steps.finalize-release.outputs.release_url }} + + - name: "** Failure Message **" + if: ${{ failure() }} + run: | + echo "Failed to Publish the Draft Release Url:" + echo ${{ steps.populate-release.outputs.release_url }}