Skip to content

Commit

Permalink
update github actions and add black linter for PRs (#475)
Browse files Browse the repository at this point in the history
- update pypi action to use OIDC trusted publisher mgmt
- generalize the flake8 action to a general linting action and add black
- put flake8 config parameters into a separate file (.flake8)
- update versions of actions/pre-commit hooks
- specify uml updates only need to run on PRs to development
- do not run uml updates on PRs into main #449)
- update docs config files to be compliant
- temporarily ignore many flake8 error codes until legacy files are updated
  • Loading branch information
JessicaS11 committed Jan 5, 2024
1 parent 690ef17 commit 5319fb4
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 28 deletions.
41 changes: 41 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[flake8]
#GOAL: max_line_length = 79 or 99
max_line_length = 99
per-file-ignores =
# too many leading '#' for block comment
*/tests/*:E266
# line too long (several test strs)
test_granules.py:E501
# imported but unused
__init__.py:F401
# import not at top of file
doc/source/conf.py:E402

# GOAL: remove these ignores
ignore =
# line too long
E501
# comparison syntax
E711
# comparison syntax
E712
# comparison syntax in tests
E714
# comparison syntax in tests
E721
# bare except
E722
# ambiguous var name
E741
# imported but unused
F401
# unable to detect undefined names
F403
# assigned and unused (in tests)
F841
# line break before binary operator
W503

# GOAL:
# syntax check doctests in docstrings
# doctests = True
17 changes: 0 additions & 17 deletions .github/workflows/flake8_action.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/linter_actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Run linters on PRs

on:
pull_request:
branches:
- development
- main
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run black linter
uses: psf/black@stable
# use the flake8 linter to annotate improperly formatted code
# note linter arguments are supplied via the .flake8 config file
- name: Annotate PR after running flake8
uses: TrueBrain/actions-flake8@v2

7 changes: 4 additions & 3 deletions .github/workflows/publish_to_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ jobs:
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
permissions:
id-token: write
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/

- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags')
permissions:
id-token: write
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/uml_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Update UML diagrams
on:
pull_request_review:
types: [submitted]
branches: development

jobs:
diagrams:
Expand Down
6 changes: 4 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
repos:
- repo: https://github.com/psf/black
rev: 22.6.0
rev: 23.12.0
hooks:
- id: black
- id: black

# you can run `pre-commit autoupdate` to automatically update to the latest version of hooks!
5 changes: 3 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import datetime
import os
import sys

sys.path.insert(0, os.path.abspath("../.."))
sys.path.insert(0, os.path.abspath("../sphinxext"))
import datetime

import icepyx

Expand Down Expand Up @@ -121,7 +121,8 @@ def setup(app):
# this should possibly be moved to the sphinxext directory as a standalone .py file
# -- custom style for pybtex output -------------------------------------------
from pybtex.style.formatting.unsrt import Style as UnsrtStyle
from pybtex.style.labels.alpha import LabelStyle as AlphaLabelStyle

# from pybtex.style.labels.alpha import LabelStyle as AlphaLabelStyle
from pybtex.plugin import register_plugin

# I seem to be unable to figure out how to control what is used for the label. It would
Expand Down
17 changes: 13 additions & 4 deletions doc/sphinxext/announce.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,20 @@
The output is utf8 rst.
Custom extension from the Pandas library: https://github.com/pandas-dev/pandas/blob/1.1.x/doc/sphinxext/announce.py
Custom extension from the Pandas library:
https://github.com/pandas-dev/pandas/blob/1.1.x/doc/sphinxext/announce.py
Copied 10 August 2020 and subsequently modified.
Specifically, get_authors was adjusted to check for a .mailmap file and use the git through the command line in order to utilize it if present. Using a mailmap file is currently not possible in gitpython (from git import Repo), and the recommended solution is to bring in the mailmap file yourself and use it to modify the author list (i.e. replicate the functionality that already exists in git). This felt a bit out of time-scope for right now. Alternatively, the git-fame library (imported as gitfame) uses the mailmap file and compiles statistics, but the python wrapper for this command line tool was taking forever. So, I've reverted to using os.system to use git behind the scenes instead.
Specifically, get_authors was adjusted to check for a .mailmap file
and use the git through the command line in order to utilize it if present.
Using a mailmap file is currently not possible in gitpython
(from git import Repo), and the recommended solution is to
bring in the mailmap file yourself and use it to modify the author list
(i.e. replicate the functionality that already exists in git).
This felt a bit out of time-scope for right now.
Alternatively, the git-fame library (imported as gitfame)
uses the mailmap file and compiles statistics,
but the python wrapper for this command line tool was taking forever.
So, I've reverted to using os.system to use git behind the scenes instead.
Dependencies
------------
Expand Down Expand Up @@ -76,7 +87,6 @@ def get_authors(revision_range):
# "Co-authored by" commits, which come from backports by the bot,
# and one for regular commits.
if ".mailmap" in os.listdir(this_repo.git.working_dir):

xpr = re.compile(r"Co-authored-by: (?P<name>[^<]+) ")

gitcur = list(os.popen("git shortlog -s " + revision_range).readlines())
Expand All @@ -94,7 +104,6 @@ def get_authors(revision_range):
pre = set(pre)

else:

xpr = re.compile(r"Co-authored-by: (?P<name>[^<]+) ")
cur = set(
xpr.findall(
Expand Down

0 comments on commit 5319fb4

Please sign in to comment.