Skip to content

Commit

Permalink
Merge branch 'main' into issue-46-gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson authored Jun 21, 2024
2 parents 5081a10 + b68f4e2 commit 82bcfb4
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 81 deletions.
13 changes: 0 additions & 13 deletions .flake8

This file was deleted.

25 changes: 7 additions & 18 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,20 @@ jobs:
with:
python-version: "3.10"
cache: pip
cache-dependency-path: '**/setup.cfg'
cache-dependency-path: '**/pyproject.yaml'

- name: Install test dependencies
run: |
python -m pip install --upgrade pip
pip install --use-deprecated=legacy-resolver -e .[dev]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Format check with isort
- name: Lint with Ruff
run: |
isort --check src
ruff check .
- name: Format check with black
- name: Format check with Ruff
run: |
black --check src
- name: Security check with bandit
run: |
bandit -ll -r src
ruff format --check .
test:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -82,8 +71,8 @@ jobs:
shasum -a 256 -c codecov.SHA256SUM
# Upload coverage report
chmod +x codecov
./codecov
./codecov
deploy:
needs:
- cqa
Expand Down
21 changes: 6 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
repos:
- repo: local
hooks:
- id: flake8
name: flake8
entry: flake8
language: system
types: [python]
- id: pyright
name: pyright
entry: pyright
language: system
types: [python]
- id: isort
name: isort
entry: isort
language: system
types: [python]
- id: black
name: black
entry: black
language: system
types: [python]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
- id: ruff-format
args: [ --check ]
16 changes: 7 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,14 @@ tox:

#=> cqa: execute code quality tests
cqa:
flake8 src --show-source --statistics
pyright
isort --check src --profile black
black --check src
bandit -ll -r src
ruff format --check
ruff check

#=> reformat: reformat code
.PHONY: reformat
reformat:
pre-commit
ruff check --fix
ruff format

############################################################################
#= UTILITY TARGETS
Expand Down Expand Up @@ -136,13 +134,13 @@ distclean: cleanest

## <LICENSE>
## Copyright 2023 Source Code Committers
##
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
##
## http://www.apache.org/licenses/LICENSE-2.0
##
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ Try it:
$ python3 -m biocommons.example
Marvin says:
There's only one life-form as intelligent as me within thirty parsecs...
$ marvin-quote

$ marvin-quote
Marvin says:
You think you've got problems? What are you supposed to do if you...

$ ipython
>>> from biocommons.example import __version__, get_quote_from_marvin
>>> __version__
Expand All @@ -73,5 +73,5 @@ Try it:

## DevOps

* Quality tools: Code reformatting with black and isort
* Quality tools: Code linting and reformatting with Ruff
* GitHub Actions for testing and packaging
75 changes: 57 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@ dependencies = [

[project.optional-dependencies]
dev = [
"bandit ~= 1.7",
"black ~= 22.3",
"build ~= 0.8",
"flake8 ~= 4.0",
"ipython ~= 8.4",
"isort ~= 5.10",
"mypy-extensions ~= 1.0",
"pre-commit ~= 3.4",
"pylint ~= 2.14",
"pytest-cov ~= 4.1",
"pytest-optional-tests",
"pytest ~= 7.1",
"pyright~=1.1",
"ruff == 0.4.4",
"tox ~= 3.25",
"vcrpy",
]
Expand Down Expand Up @@ -123,21 +119,64 @@ exclude_lines = [
"if __name__ == .__main__.:",
]

[tool.black]
line-length = 100

[tool.isort]
profile = "black"
src_paths = ["src", "tests"]


[tool.pyright]
include = ["src", "tests"]

[tool.ruff]
src = ["src", "tests"]
line-length = 100

[tool.pylint.'MESSAGES CONTROL']
disable = "R0913"

[tool.ruff.lint]
select = [
"F", # https://docs.astral.sh/ruff/rules/#pyflakes-f
"E", "W", # https://docs.astral.sh/ruff/rules/#pycodestyle-e-w
"I", # https://docs.astral.sh/ruff/rules/#isort-i
"N", # https://docs.astral.sh/ruff/rules/#pep8-naming-n
"UP", # https://docs.astral.sh/ruff/rules/#pyupgrade-up
"YTT", # https://docs.astral.sh/ruff/rules/#flake8-2020-ytt
"S", # https://docs.astral.sh/ruff/rules/#flake8-bandit-s
"B", # https://docs.astral.sh/ruff/rules/#flake8-bugbear-b
"A", # https://docs.astral.sh/ruff/rules/#flake8-builtins-a
"C4", # https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
"DTZ", # https://docs.astral.sh/ruff/rules/#flake8-datetimez-dtz
"EM", # https://docs.astral.sh/ruff/rules/#flake8-errmsg-em
"LOG", # https://docs.astral.sh/ruff/rules/#flake8-logging-log
"G", # https://docs.astral.sh/ruff/rules/#flake8-logging-format-g
"PIE", # https://docs.astral.sh/ruff/rules/#flake8-pie-pie
"PT", # https://docs.astral.sh/ruff/rules/#flake8-pytest-style-pt
"RSE", # https://docs.astral.sh/ruff/rules/#flake8-raise-rse
"RET", # https://docs.astral.sh/ruff/rules/#flake8-return-ret
"SIM", # https://docs.astral.sh/ruff/rules/#flake8-simplify-sim
"ARG", # https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg
"PTH", # https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
"PL", # https://docs.astral.sh/ruff/rules/#pylint-pl
"TRY", # https://docs.astral.sh/ruff/rules/#tryceratops-try
"PERF", # https://docs.astral.sh/ruff/rules/#perflint-perf
"RUF", # https://docs.astral.sh/ruff/rules/#ruff-specific-rules-ruf
]
fixable = [
"F401",
"F541",
"I",
"D",
"UP",
"B",
"C4",
"EM",
"PIE",
"PT",
"RSE",
"RET",
"SIM",
"PERF",
"RUF",
]
ignore = [
# ignore for compatibility with formatter
"W191", "E111", "E114", "E117", "S321",
# other
"PLR0913",
]

[tool.pylint.format]
max-line-length = 100
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"]
2 changes: 1 addition & 1 deletion src/biocommons/example/marvin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_quote() -> str:
"""
_logger.info("Getting quote from Marvin")

quote = random.choice(quotes)
quote = random.choice(quotes) # noqa: S311

_logger.info("Got quote from Marvin (len=%s)", len(quote))

Expand Down
2 changes: 1 addition & 1 deletion src/biocommons/example/marvin_adjacent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

def test_get_quote():
"""test get_quote"""
assert get_quote() is not None
assert get_quote() is not None # noqa: S101
2 changes: 1 addition & 1 deletion src/biocommons/example/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import yaml


@pytest.fixture
@pytest.fixture()
def all_quotes():
quotes_stream = importlib.resources.files("example").joinpath("quotes.yaml").read_text()
return yaml.load(quotes_stream, Loader=yaml.SafeLoader)["quotes"]
2 changes: 1 addition & 1 deletion src/biocommons/example/tests/marvin_subdir_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
def test_get_quote(all_quotes):
"""test get_quote"""
# NB: all_quotes argument is a test fixture; see ./conftest.py
assert get_quote() in all_quotes
assert get_quote() in all_quotes # noqa: S101

0 comments on commit 82bcfb4

Please sign in to comment.