Skip to content

Commit

Permalink
Merge pull request #32 from stfc/dev
Browse files Browse the repository at this point in the history
Merge dev to main
  • Loading branch information
Alex-JG3 authored Mar 22, 2024
2 parents d3afee3 + 1c1657e commit 6a1336f
Show file tree
Hide file tree
Showing 9 changed files with 1,702 additions and 1,342 deletions.
26 changes: 17 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,41 @@ name: lint

on: push

env:
POETRY_VERSION: "1.8.2"
PYTHON_VERSION: "3.9"

jobs:
lint:
name: Run linting tools
runs-on: "ubuntu-latest"
steps:
- name: Checkout code
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Print PYTHON_VERSION
run: echo "Using python==$PYTHON_VERSION"

- name: Setup Python
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: ${{env.PYTHON_VERSION}}


- name: Permacache Poetry
id: cache-poetry
uses: actions/cache@v2.1.6
uses: actions/cache@v3
with:
path: ~/.poetry
key: poetry

- name: Install latest version of Poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
curl -sSL https://install.python-poetry.org | python3 -
POETRY_VERSION=$POETRY_VERSION curl -sSL https://install.python-poetry.org | python3 -
poetry version
- name: Add Poetry to $PATH
run: |
Expand All @@ -41,7 +50,7 @@ jobs:

- name: Cache dependencies
id: cache-deps
uses: actions/cache@v2.1.6
uses: actions/cache@v3
with:
path: ${{github.workspace}}/.venv
key: poetry-${{ hashFiles('**/poetry.lock') }}
Expand All @@ -51,12 +60,11 @@ jobs:
if: steps.cache-deps.cache-hit != 'true'
run: |
poetry config virtualenvs.in-project true
poetry install --no-interaction
poetry install --no-interaction --with dev
- name: Lint code
run: |
poetry run pylint --errors-only hooks
poetry run flake8 hooks
poetry run isort --check hooks
poetry run black --check --diff .
poetry run ruff check hooks
poetry run mypy hooks
17 changes: 11 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,37 @@ on:
tags:
- "v*"

env:
POETRY_VERSION: "1.8.2"
PYTHON_VERSION: "3.9"

jobs:
autorelease:
name: Create Release
runs-on: "ubuntu-latest"
steps:
- name: Checkout code
uses: actions/checkout@v2.3.4
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v4
with:
python-version: "3.9"
python-version: ${{ env.PYTHON_VERSION }}

- name: Permacache Poetry
id: cache-poetry
uses: actions/cache@v2.1.6
uses: actions/cache@v3
with:
path: ~/.poetry
key: poetry

- name: Install latest version of Poetry
if: steps.cache-poetry.outputs.cache-hit != 'true'
run: |
curl -sSL https://install.python-poetry.org | python3 -
POETRY_VERSION=$POETRY_VERSION curl -sSL https://install.python-poetry.org | python3 -
poetry --version
- name: Add Poetry to $PATH
run: |
Expand Down
21 changes: 13 additions & 8 deletions .github/workflows/sphinx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@ on:
tags: "*"
pull_request:
branches:
- master
- main

env:
POETRY_VERSION: "1.8.2"
PYTHON_VERSION: "3.9"

jobs:
build-docs:
runs-on: ubuntu-latest
runs-on: "ubuntu-latest"
steps:
- name: Checkout
uses: actions/checkout@master
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: 3.9

- uses: abatilo/[email protected]
python-version: ${{ env.PYTHON_VERSION }}

- uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: install
run: poetry install --extras docs
run: poetry install --with dev

- name: Build documentation
run: |
Expand Down
19 changes: 10 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/stfc/pre-commit-hooks
rev: v0.3.4
rev: v0.3.7
hooks:
- id: check-mypy-import-errors
- id: check-pylint-import-errors
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.5.0
hooks:
- id: check-toml
- id: check-yaml
Expand All @@ -30,11 +30,12 @@ repos:
hooks:
- id: black
language_version: python3
- repo: https://github.com/pycqa/isort
rev: 5.10.1
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.8
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format
2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ example configuration:
repos:
- repo: https://github.com/stfc/pre-commit-hooks
rev: v0.3.4
rev: v0.3.7
hooks:
- id: check-mypy-import-errors
- id: check-pylint-import-errors
Expand Down
31 changes: 17 additions & 14 deletions hooks/check_pylint_import_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import json
import sys
from io import StringIO
from typing import Optional

from pylint import epylint as lint
from pylint.lint import Run
from pylint.reporters import JSONReporter

from .utils import Hook, PyprojectFile, SetupFile
from .utils.config_file import ConfigFile
Expand Down Expand Up @@ -48,27 +50,28 @@ def run(self) -> int:
return 0

# set some pylint options to match the CI pipeline and use the output here:
pylint_opts = " ".join(
[
setup_file.package_name, # lint package files
f"--rcfile='{setup_file.path}'", # use local config file
" --output-format=json", # return json dict for subsequent parsing
]
)
pylint_output = StringIO() # Custom open stream
reporter = JSONReporter(pylint_output) # report to StringIO
pylint_opts = [
setup_file.package_name, # lint package files
f"--rcfile={setup_file.path}", # use local config file
]
# run pylint:
pylint_stdout, pylint_err = lint.py_run(pylint_opts, return_std=True)
# pylint_stdout, pylint_err = lint.py_run(pylint_opts, return_std=True)
Run(args=pylint_opts, reporter=reporter, exit=False) # New API

# raise any pylint running errors (i.e. not linting issues)
if len(pylint_err.getvalue()) > 0:
raise Exception(pylint_err.getvalue())
# # raise any pylint running errors (i.e. not linting issues)
# if len(pylint_err.getvalue()) > 0:
# raise Exception(pylint_err.getvalue())
# NOTE: Run API should raise these (famous last words...)

# grab lint issues as json dict:
pylint_output = json.loads(pylint_stdout.getvalue())
pylint_output_structure = json.loads(pylint_output.getvalue())

# get any package/module names from pylint import-error messages:
bad_imports = {
msg["message"].split("'")[1]
for msg in pylint_output
for msg in pylint_output_structure
if msg["message-id"] == "E0401"
}
if len(bad_imports) == 0:
Expand Down
1 change: 0 additions & 1 deletion hooks/utils/setup_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ def _generate_mypy_ignores(bad_modules: Union[str, Set[str]]) -> str:
self.contents = new_config

def add_pylint_ignore(self, bad_imports):

self._modify_section_line(
section_name="[pylint]",
line_start="ignored-modules = ",
Expand Down
Loading

0 comments on commit 6a1336f

Please sign in to comment.