Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the style checks for stpipe #103

Merged
merged 24 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ba8cf92
Enable all pycodestyle checks
WilliamJamieson Aug 22, 2023
838111c
Switch to ruff for isort
WilliamJamieson Aug 22, 2023
223fe0b
Enable pep8 naming enforcement
WilliamJamieson Aug 22, 2023
ac866d3
Switch to pyupgrade to ruff and target python 3.9
WilliamJamieson Oct 31, 2023
0f926c5
Switch to ruff for bandit checks
WilliamJamieson Aug 22, 2023
35aa96f
Enforce flake8 bugbear
WilliamJamieson Aug 22, 2023
739d820
Use flake8 builtin shadowing linting
WilliamJamieson Aug 22, 2023
9c9b6e1
Add flake8 comprehension linting
WilliamJamieson Aug 22, 2023
a13f235
Lint for debugger statements
WilliamJamieson Aug 22, 2023
b4c82fb
Add unnecessary pass linting
WilliamJamieson Aug 22, 2023
321d5c5
Add pytest linting
WilliamJamieson Aug 22, 2023
c8ff9c0
Simplify if/else returns
WilliamJamieson Aug 22, 2023
d291c49
Add import linting
WilliamJamieson Aug 22, 2023
84dc153
Add unused argument checks
WilliamJamieson Aug 22, 2023
f3640f0
Add removal of commented out code
WilliamJamieson Aug 22, 2023
aef6ccf
Apply flint using ruff
WilliamJamieson Aug 22, 2023
cd5baeb
Add performance linting
WilliamJamieson Aug 22, 2023
7f239a1
Add ruff specific rules
WilliamJamieson Aug 29, 2023
b0c4256
Add logging linting
WilliamJamieson Aug 22, 2023
0a4017d
Enable Repo-review
WilliamJamieson Oct 31, 2023
fb88b4a
Use prettier
WilliamJamieson Aug 29, 2023
2567bb5
Update repo-review
WilliamJamieson Oct 31, 2023
8dc4d95
Update changes
WilliamJamieson Oct 31, 2023
ba6ae32
Switch to ruff formatter
WilliamJamieson Oct 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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