Skip to content

Commit

Permalink
Adopt pre-commit-ci for linting and typecheck (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol authored May 16, 2023
1 parent fa06194 commit 9ec9910
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 79 deletions.
4 changes: 3 additions & 1 deletion .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
---

codecov:
branch: main
notify:
Expand All @@ -6,7 +8,7 @@ codecov:
coverage:
range: "95..100"
status:
project: no
project: false

flags:
library:
Expand Down
1 change: 1 addition & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
version: 2
updates:
- package-ecosystem: pip
Expand Down
119 changes: 60 additions & 59 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
name: CI

on:
on: # yamllint disable-line rule:truthy
push:
branches: ["main"]
pull_request:
branches: ["main"]
release:
types: [created]
branches:
- 'main'
- 'main'
workflow_dispatch:

env:
Expand All @@ -27,29 +28,29 @@ jobs:
runs-on: ubuntu-latest
# if: github.event_name == 'release' && github.event.action == 'created'
steps:
- name: Checkout project
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_LATEST }}
cache: pip
- run: python -m pip install build
name: Install core libraries for build and install
- name: Build artifacts
run: python -m build
- name: Upload built artifacts for testing
uses: actions/upload-artifact@v3
with:
name: ${{ env.sdist-artifact }}
# NOTE: Exact expected file names are specified here
# NOTE: as a safety measure — if anything weird ends
# NOTE: up being in this dir or not all dists will be
# NOTE: produced, this will fail the workflow.
path: dist/${{ env.sdist-name }}
retention-days: 15
- name: Checkout project
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_LATEST }}
cache: pip
- run: python -m pip install build
name: Install core libraries for build and install
- name: Build artifacts
run: python -m build
- name: Upload built artifacts for testing
uses: actions/upload-artifact@v3
with:
name: ${{ env.sdist-artifact }}
# NOTE: Exact expected file names are specified here
# NOTE: as a safety measure — if anything weird ends
# NOTE: up being in this dir or not all dists will be
# NOTE: produced, this will fail the workflow.
path: dist/${{ env.sdist-name }}
retention-days: 15

lint:
uses: ./.github/workflows/lint.yml
Expand All @@ -63,34 +64,34 @@ jobs:
fail-fast: true
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
experimental: [false]
include:
- python-version: "~3.12.0-0"
experimental: true
- python-version: "~3.12.0-0"
experimental: true
steps:
- name: Checkout the source code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
setup.cfg
requirements-dev.txt
- name: Install dependencies
run: |
pip install -U -r requirements-dev.txt
- name: Run tests
run: python -m pytest --cov=aiomonitor -v tests
- name: Upload coverage data
uses: codecov/codecov-action@v3
- name: Checkout the source code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
setup.cfg
requirements-dev.txt
- name: Install dependencies
run: |
pip install -U -r requirements-dev.txt
- name: Run tests
run: python -m pytest --cov=aiomonitor -v tests
- name: Upload coverage data
uses: codecov/codecov-action@v3

check: # This job does nothing and is only used for the branch protection
name: ✅ Ensure the required checks passing
Expand All @@ -110,12 +111,12 @@ jobs:
environment: pypi
if: github.event_name == 'release' && github.event.action == 'created'
steps:
- name: Download the sdist artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.sdist-artifact }}
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Download the sdist artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.sdist-artifact }}
path: dist
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 3 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---

name: Linters

on:
on: # yamllint disable-line rule:truthy
workflow_call:
workflow_dispatch:

Expand Down
38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---

ci:
autoupdate_schedule: quarterly
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.2.0
hooks:
- id: mypy
additional_dependencies:
- types-requests
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.30.0
hooks:
- id: yamllint
types:
- file
- yaml
args:
- --strict
1 change: 1 addition & 0 deletions .pyup.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
# Label PRs with `deps-update` label
label_prs: deps-update

Expand Down
3 changes: 2 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Required
---

version: 2

# Build documentation in the docs/ directory with Sphinx
Expand Down
10 changes: 10 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

extends: default

rules:
indentation:
level: error
indent-sequences: false

...
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,3 @@ Apache License
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Now from separate terminal it is possible to connect to the application::
or the included python client::

$ python -m aiomonitor.cli


Tutorial
--------

Expand Down Expand Up @@ -122,9 +122,9 @@ Now you can type commands, for instance, ``help``::

monitor >>> help
Usage: help [OPTIONS] COMMAND [ARGS]...

To see the usage of each command, run them with "--help" option.

Commands:
cancel Cancel an indicated task
console Switch to async Python REPL
Expand Down
4 changes: 2 additions & 2 deletions aiomonitor/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def _trace_termination(self, _: "asyncio.Task[Any]") -> None:
self_id,
name=self.get_name(),
coro=_format_coroutine(self._orig_coro).partition(" ")[0],
cancelled=self.cancelled(),
exc_repr=exc_repr,
started_at=self._started_at,
terminated_at=time.perf_counter(),
cancelled=self.cancelled(),
termination_stack=self._termination_stack,
canceller_stack=None,
exc_repr=exc_repr,
persistent=self._persistent,
)
self._termination_info_queue.put_nowait(task_info)
Expand Down
9 changes: 4 additions & 5 deletions aiomonitor/types.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
import traceback
from dataclasses import dataclass
from typing import List, Optional

from attrs import define


@define
@dataclass
class TerminatedTaskInfo:
id: str
name: str
coro: str
started_at: float
terminated_at: float
cancelled: bool
termination_stack: Optional[List[traceback.FrameSummary]]
termination_stack: Optional[List[traceback.FrameSummary]] = None
canceller_stack: Optional[List[traceback.FrameSummary]] = None
exc_repr: Optional[str] = None
persistent: bool = False


@define
@dataclass
class CancellationChain:
target_id: str
canceller_id: str
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
7 changes: 4 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@
# needs_sphinx = '1.0'

import pathlib
from importlib.metadata import version
from importlib.metadata import version as get_version
from typing import Mapping

_docs_path = pathlib.Path(__file__).parent


try:
_version_info = version("aiomonitor")
_version_info = get_version("aiomonitor")
except IndexError:
raise RuntimeError("Unable to determine version.")

Expand Down Expand Up @@ -130,7 +131,7 @@

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
latex_elements: Mapping[str, str] = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
Expand Down
1 change: 0 additions & 1 deletion tests/test_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def console_enabled(request):

@pytest.mark.asyncio
async def test_ctor(event_loop, unused_port, console_enabled):

with Monitor(event_loop, console_enabled=console_enabled):
await asyncio.sleep(0.01)
with start_monitor(event_loop, console_enabled=console_enabled) as m:
Expand Down

0 comments on commit 9ec9910

Please sign in to comment.