Skip to content

Commit

Permalink
Merge pull request #128 from lpsinger/pre-commit
Browse files Browse the repository at this point in the history
Add pre-commit hooks
  • Loading branch information
dakota002 committed Aug 5, 2024
2 parents f06a0bb + 751bf57 commit 6c40fac
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 165 deletions.
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

14 changes: 6 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,20 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: psf/black@stable

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: '3.12'

- name: Install dependencies
run: pip install pre-commit poetry

- name: Install Poetry
run: pip install poetry
- name: Run pre-commit checks
run: pre-commit run --all-files

- name: Install package
run: poetry install

- name: Run flake8 linter
run: poetry run flake8

- name: Run unit tests
run: poetry run pytest . --cov --cov-report=xml

Expand Down
45 changes: 45 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-added-large-files
# Prevent giant files from being committed.
- id: check-case-conflict
# Check for files with names that would conflict on a case-insensitive
# filesystem like MacOS HFS+ or Windows FAT.
- id: check-json
# Attempts to load all json files to verify syntax.
- id: check-merge-conflict
# Check for files that contain merge conflict strings.
- id: check-symlinks
# Checks for symlinks which do not point to anything.
- id: check-toml
# Attempts to load all TOML files to verify syntax.
- id: check-xml
# Attempts to load all xml files to verify syntax.
- id: check-yaml
# Attempts to load all yaml files to verify syntax.
- id: detect-private-key
# Checks for the existence of private keys.
- id: end-of-file-fixer
# Makes sure files end in a newline and only a newline.
- id: trailing-whitespace
# Trims trailing whitespace.
exclude_types: [python] # Covered by Ruff W291.
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.5
hooks:
# Run the linter.
- id: ruff
args: ["--extend-select", "I", "--fix"]
# Run the formatter.
- id: ruff-format
- repo: https://github.com/python-poetry/poetry
rev: "1.8.3"
hooks:
- id: poetry-check
- id: poetry-lock
args: ["--no-update"]
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,18 @@ This package uses [Poetry](https://python-poetry.org) for packaging and Python v

1. [Fork](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo) and [clone](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo#cloning-your-forked-repository) this repository.

2. Install Poetry by following [their installation instructions](https://python-poetry.org/docs/#installation).
2. Install [pre-commit hooks](https://pre-commit.com) by running the following two commands:

3. Install this package and its dependencies by running the following command inside your clone of this repository:
pip install pre-commit
pre-commit install

3. Install Poetry by following [their installation instructions](https://python-poetry.org/docs/#installation).

4. Install this package and its dependencies by running the following command inside your clone of this repository:

poetry install --all-extras

4. Run the following command to launch a shell that is preconfigured with the project's virtual environment:
5. Run the following command to launch a shell that is preconfigured with the project's virtual environment:

poetry shell

Expand Down
5 changes: 2 additions & 3 deletions gcn_classic_to_kafka/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@

import asyncio
import logging
import urllib
import signal
import sys
import urllib

import click
import gcn_kafka
import prometheus_client

from . import heartbeat, metrics
from .socket import client_connected
from . import heartbeat
from . import metrics

log = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions gcn_classic_to_kafka/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# SPDX-License-Identifier: Apache-2.0
#
"""Prometheus metrics."""

import prometheus_client

connected = prometheus_client.Gauge(
Expand Down
4 changes: 2 additions & 2 deletions gcn_classic_to_kafka/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# SPDX-License-Identifier: Apache-2.0
#
"""Protocol handler for GCN socket connection."""

import asyncio
import logging
import struct
Expand All @@ -14,8 +15,8 @@
import gcn
import lxml.etree

from .common import notice_type_int_to_str, topic_for_notice_type_str
from . import metrics
from .common import notice_type_int_to_str, topic_for_notice_type_str

log = logging.getLogger(__name__)

Expand All @@ -29,7 +30,6 @@


def client_connected(producer: confluent_kafka.Producer, timeout: float = 90):

async def client_connected_cb(
reader: asyncio.StreamReader, writer: asyncio.StreamWriter
):
Expand Down
2 changes: 1 addition & 1 deletion gcn_classic_to_kafka/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
# SPDX-License-Identifier: Apache-2.0
#
import asyncio
from unittest import mock
import struct
from unittest import mock

import gcn
import pytest
Expand Down
145 changes: 1 addition & 144 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ pygcn = "*"
prometheus-client = "^0.17.0"

[tool.poetry.group.dev.dependencies]
black = "*"
flake8 = "*"
pytest = "*"
pytest-asyncio = "*"
pytest-cov = "*"
Expand Down

0 comments on commit 6c40fac

Please sign in to comment.