Skip to content

Commit

Permalink
Update the style checks for stpipe (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamJamieson committed Nov 7, 2023
1 parent 54a4d99 commit 0b7e4ca
Show file tree
Hide file tree
Showing 29 changed files with 374 additions and 326 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: build

on:
release:
types: [ released ]
types: [released]
pull_request:
workflow_dispatch:

Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: scientific-python/action-check-changelogfile@0.2
env:
CHANGELOG_FILENAME: CHANGES.rst
CHECK_MILESTONE: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: scientific-python/action-check-changelogfile@0.2
env:
CHANGELOG_FILENAME: CHANGES.rst
CHECK_MILESTONE: false
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ on:
branches:
- master
tags:
- '*'
- "*"
pull_request:
schedule:
# Weekly Monday 9AM build
# * is a special character in YAML so you have to quote this string
- cron: '0 9 * * 1'
- cron: "0 9 * * 1"
workflow_dispatch:

concurrency:
Expand Down
126 changes: 57 additions & 69 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,70 +1,58 @@
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-yaml
args: ["--unsafe"]
- id: check-toml
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
exclude: "src/stpipe/cmdline.py"
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: ["--write-changes"]
additional_dependencies:
- tomli

- repo: https://github.com/ikamensh/flynt/
rev: '1.0.1'
hooks:
- id: flynt
exclude: "src/stpipe/extern/.*"

- repo: https://github.com/asottile/pyupgrade
rev: 'v3.15.0'
hooks:
- id: pyupgrade
args: ["--py38-plus"]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.4'
hooks:
- id: ruff
args: ["--fix"]
exclude: "scripts/strun"

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 23.10.1
hooks:
- id: black

- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: ["-r", "-ll"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-case-conflict
- id: check-yaml
args: ["--unsafe"]
- id: check-toml
- id: check-merge-conflict
- id: check-symlinks
- id: debug-statements
exclude: "src/stpipe/cmdline.py"
- id: detect-private-key
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-directive-colons
- id: rst-inline-touching-normal
- id: text-unicode-replacement-char

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: ["--write-changes"]
additional_dependencies:
- tomli

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.4"
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
exclude: "scripts/strun"
- id: ruff-format

- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
additional_dependencies:
- black==22.12.0

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.2"
hooks:
- id: prettier

- repo: https://github.com/scientific-python/cookie
rev: 2023.10.27
hooks:
- id: sp-repo-review
additional_dependencies: ["repo-review[cli]"]
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
0.6.0 (unreleased)
==================

-
- Update style and linting checking [#103]

0.5.1 (2023-10-02)
==================
Expand Down
1 change: 0 additions & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

We expect all "spacetelescope" organization projects to adopt a code of conduct that ensures a productive, respectful environment for all open source contributors and participants. We are committed to providing a strong and enforced code of conduct and expect everyone in our community to follow these guidelines when interacting with others in all forums. Our goal is to keep ours a positive, inclusive, successful, and growing community. The community of participants in open source Astronomy projects is made up of members from around the globe with a diverse set of skills, personalities, and experiences. It is through these differences that our community experiences success and continued growth.


As members of the community,

- We pledge to treat all people with respect and provide a harassment- and bullying-free environment, regardless of sex, sexual orientation and/or gender identity, disability, physical appearance, body size, race, nationality, ethnicity, and religion. In particular, sexual language and imagery, sexist, racist, or otherwise exclusionary jokes are not appropriate.
Expand Down
88 changes: 71 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ strun = 'stpipe.cli.strun:main'
requires = [
'setuptools >=61',
'setuptools_scm[toml] >=3.4',
'wheel',
]
build-backend = 'setuptools.build_meta'

Expand All @@ -62,11 +61,18 @@ zip-safe = true
where = ['src']

[tool.pytest.ini_options]
minversion = 4.6
minversion = 6
log_cli_level = "INFO"
xfail_strict = true
doctest_plus = true
doctest_rst = true
text_file_format = 'rst'
addopts = ''
addopts = [
"--strict-config",
"--strict-markers",
"-ra",
"--color=yes"
]
norecursedirs = [
'src/stpipe/extern',
]
Expand All @@ -76,31 +82,70 @@ testpaths = [
filterwarnings = [
"error::ResourceWarning",
]
markers = [
"soctests",
]

[tool.ruff]
select = [
'E402', # module level import not at top of file
'E501', # line too long
'E711', # comparison to None should be ‘if cond is None:’
'E722', # do not use bare except, specify exception instead
'F', # flakes
'W', # whitespace / deprecation
src = [
"src",
"tests",
"docs",
"setup.py",
]
line-length = 88
extend-exclude = [
'docs',
'src/stpipe/extern',
'scripts/strun',
]
extend-ignore = [
'W605', # invalid escape sequence

[tool.ruff.lint]
extend-select = [
'F', # Pyflakes
'W', 'E', # pycodestyle
'I', # isort
'N', # pep8-naming
'UP', # pyupgrade
'S', # flake8-bandit
# 'BLE', # flake8-blind-except
'B', # flake8-bugbear
'A', # flake8-builtins (prevent shadowing of builtins)
'C4', # flake8-comprehensions (best practices for comprehensions)
'T10', # flake8-debugger (prevent debugger statements in code)
'ISC', # flake8-implicit-str-concat (prevent implicit string concat)
'ICN', # flake8-import-conventions (enforce import conventions)
'INP', # flake8-no-pep420 (prevent use of PEP420, i.e. implicit name spaces)
'G', # flake8-logging-format (best practices for logging)
'PIE', # flake8-pie (misc suggested improvement linting)
'T20', # flake8-print (prevent print statements in code)
'PT', # flake8-pytest-style (best practices for pytest)
'Q', # flake8-quotes (best practices for quotes)
'RSE', # flake8-raise (best practices for raising exceptions)
'RET', # flake8-return (best practices for return statements)
# 'SLF', # flake8-self (prevent private member access)
'TID', # flake8-tidy-imports (prevent banned api and best import practices)
'INT', # flake8-gettext (when to use printf style strings)
'ARG', # flake8-unused-arguments (prevent unused arguments)
# 'PTH', # flake8-use-pathlib (prefer pathlib over os.path)
'ERA', # eradicate (remove commented out code)
'PGH', # pygrep (simple grep checks)
# 'PL', # pylint (general linting, flake8 alternative)
'FLY', # flynt (f-string conversion where possible)
'NPY', # NumPy-specific checks (recommendations from NumPy)
'PERF', # Perflint (performance linting)
'RUF', # ruff specific checks
]
ignore = [
"ISC001", # conflicts with ruff formatter
]

[tool.isort]
profile = "black"
filter_files = true
line_length = 88
extend_skip_glob = ["src/stpipe/extern/*"]
[tool.ruff.lint.extend-per-file-ignores]
"tests/*.py" = ["S101", "S603", "S607", "INP001", "ARG001"]
"src/stpipe/tests/*.py" = ["S101"]
"src/stpipe/cli/*.py" = ["T201"]
"src/stpipe/cmdline.py" = ["T201"]


[tool.black]
line-length = 88
Expand All @@ -123,3 +168,12 @@ exclude = ["src/stpipe/extern/*"]
skip="*.pdf,*.fits,*.asdf,.tox,build,./tags,.git,docs/_build"
# ignore-words-list="""
# """


[tool.repo-review]
ignore = [
"GH200", # Use dependabot
"PC140", # add MyPy to pre-commit
"PC901", # custom pre-comit.ci message
"MY100", # Use MyPy
]
3 changes: 0 additions & 3 deletions src/stpipe/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def get_name(cls):
-------
str
"""
pass

@abc.abstractclassmethod
def add_subparser(cls, subparsers):
Expand All @@ -27,7 +26,6 @@ def add_subparser(cls, subparsers):
----------
subparsers : argparse._SubParsersAction
"""
pass

@abc.abstractclassmethod
def run(cls, args):
Expand All @@ -44,4 +42,3 @@ def run(cls, args):
int
Exit status code.
"""
pass
3 changes: 2 additions & 1 deletion src/stpipe/cli/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import re
import sys

from .. import entry_points
from stpipe import entry_points

from .command import Command


Expand Down
6 changes: 3 additions & 3 deletions src/stpipe/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import sys
import traceback

from ..exceptions import StpipeExitException
from stpipe.exceptions import StpipeExitException

from .list import ListCommand

# New subclasses of Command must be imported
Expand Down Expand Up @@ -90,8 +91,7 @@ def _print_versions():
that register an stpipe.steps entry point.
"""
import stpipe

from .. import entry_points
from stpipe import entry_points

packages = sorted(
{(s.package_name, s.package_version) for s in entry_points.get_steps()},
Expand Down
Loading

0 comments on commit 0b7e4ca

Please sign in to comment.