Skip to content

Commit

Permalink
ci: bring ci files up to date, update ruff config
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Oct 1, 2024
1 parent 250f648 commit d969672
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 27 deletions.
6 changes: 5 additions & 1 deletion .ci/run
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if ! command -v sudo; then
}
fi

# --parallel-live to show outputs while it's running
tox_cmd='run-parallel --parallel-live'
if [ -n "${CI-}" ]; then
# install OS specific stuff here
case "$OSTYPE" in
Expand All @@ -21,6 +23,8 @@ if [ -n "${CI-}" ]; then
cygwin* | msys* | win*)
# windows
:
# ugh. parallel stuff seems super flaky under windows, some random failures, "file used by other process" and crap like that
tox_cmd='run'
;;
*)
# must be linux?
Expand All @@ -37,4 +41,4 @@ if ! command -v python3 &> /dev/null; then
fi

"$PY_BIN" -m pip install --user tox
"$PY_BIN" -m tox --parallel --parallel-live "$@"
"$PY_BIN" -m tox $tox_cmd "$@"
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
- if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: .coverage.mypy_${{ matrix.platform }}_${{ matrix.python-version }}
path: .coverage.mypy/

Expand Down
5 changes: 2 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[mypy]
namespace_packages = True
pretty = True
show_error_context = True
show_error_codes = True
show_column_numbers = True
show_error_end = True
warn_redundant_casts = True
warn_unused_ignores = True
check_untyped_defs = True
enable_error_code = possibly-undefined
strict_equality = True
enable_error_code = possibly-undefined

# an example of suppressing
# [mypy-my.config.repos.pdfannots.pdfannots]
Expand Down
14 changes: 7 additions & 7 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
target-version = "py38" # NOTE: inferred from pyproject.toml if present

lint.extend-select = [
"F", # flakes rules -- default, but extend just in case
"E", # pycodestyle -- default, but extend just in case
Expand All @@ -26,10 +24,10 @@ lint.extend-select = [
"TID", # various imports suggestions
"TRY", # various exception handling rules
"UP", # detect deprecated python stdlib stuff
# "FA", # TODO enable later after we make sure cachew works?
# "PTH", # pathlib migration -- TODO enable later
# "FA", # suggest using from __future__ import annotations
"PTH", # pathlib migration
# "ARG", # TODO useful, but results in some false positives in pytest fixtures... maybe later
# "A", # TODO builtin shadowing -- handle later
"A", # builtin shadowing
# "EM", # TODO hmm could be helpful to prevent duplicate err msg in traceback.. but kinda annoying

# "ALL", # uncomment this to check for new rules!
Expand Down Expand Up @@ -63,8 +61,8 @@ lint.ignore = [
"E402", # Module level import not at top of file

### maybe consider these soon
# sometimes it's useful to give a variable a name even if we don't use it as a documentation
# on the other hand, often is a sign of error
# sometimes it's useful to give a variable a name even if we don't use it as a documentation
# on the other hand, often is a sign of error
"F841", # Local variable `count` is assigned to but never used
"F401", # imported but unused
###
Expand Down Expand Up @@ -132,6 +130,8 @@ lint.ignore = [

"TID252", # Prefer absolute imports over relative imports from parent modules

"UP038", # suggests using | (union) in isisntance checks.. but it results in slower code

## too annoying
"T20", # just complains about prints and pprints
"Q", # flake quotes, too annoying
Expand Down
2 changes: 1 addition & 1 deletion src/cachew/backend/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ def flush_blobs(self, chunk: Sequence[bytes]) -> None:

def finalize(self, new_hash: SourceHash) -> None:
# TODO defensive??
os.rename(self.jsonl_tmp, self.jsonl)
self.jsonl_tmp.rename(self.jsonl)
5 changes: 3 additions & 2 deletions src/cachew/tests/marshall.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ def do_test(*, test_name: str, Type, factory, count: int, impl: Impl = 'cachew')

converter = Converter()

import types
from typing import Union, get_args, get_origin
from typing import get_args

# TODO use later
# from typing import Union, get_origin
# import types
# def is_union(type_) -> bool:
# origin = get_origin(type_)
# return origin is Union or origin is types.UnionType
Expand Down
2 changes: 1 addition & 1 deletion src/cachew/tests/test_cachew.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from itertools import chain, islice
from pathlib import Path
from random import Random
from subprocess import PIPE, check_call, check_output, run
from subprocess import check_call, check_output, run
from time import sleep
from typing import (
Any,
Expand Down
22 changes: 10 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,36 @@ passenv =
PYTHONPYCACHEPREFIX
MYPY_CACHE_DIR
RUFF_CACHE_DIR
usedevelop = true # for some reason tox seems to ignore "-e ." in deps section??
# note: --use-pep517 here is necessary for tox --parallel flag to work properly
# otherwise it seems that it tries to modify .eggs dir in parallel and it fails
install_command = {envpython} -m pip install --use-pep517 {opts} {packages}


[testenv:ruff]
deps =
-e .[testing]
commands =
{envpython} -m pip install --use-pep517 -e .[testing]
{envpython} -m ruff check src/


# note: --use-pep517 here is necessary for tox --parallel flag to work properly
# otherwise it seems that it tries to modify .eggs dir in parallel and it fails
[testenv:tests]
deps =
-e .[testing]
commands =
{envpython} -m pip install --use-pep517 -e .[testing]
# posargs allow test filtering, e.g. tox ... -- -k test_name
{envpython} -m pytest \
--pyargs {[testenv]package_name} \
{posargs}


[testenv:mypy]
deps =
-e .[testing,optional]
commands =
{envpython} -m pip install --use-pep517 -e .[testing,optional]
{envpython} -m mypy --install-types --non-interactive \
-p {[testenv]package_name} \
# txt report is a bit more convenient to view on CI
--txt-report .coverage.mypy \
--html-report .coverage.mypy \
{posargs}


# todo not sure if really need bandit at all?
[testenv:bandit]
commands =
{envpython} -m pip install -e .[testing]
{envpython} -m bandit -c .bandit.yml -r src/cachew

0 comments on commit d969672

Please sign in to comment.