Skip to content

Commit

Permalink
ci updates: sync with pympalte
Browse files Browse the repository at this point in the history
- use python 3.12
- use ruff instead of pylint
- use pyproject.toml
  • Loading branch information
karlicoss committed Oct 4, 2023
1 parent f71a505 commit 1e9f3dd
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 127 deletions.
6 changes: 3 additions & 3 deletions .ci/release
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import shutil

is_ci = os.environ.get('CI') is not None

def main():
def main() -> None:
import argparse
p = argparse.ArgumentParser()
p.add_argument('--test', action='store_true', help='use test pypi')
args = p.parse_args()

extra = []
if args.test:
extra.extend(['--repository-url', 'https://test.pypi.org/legacy/'])
extra.extend(['--repository', 'testpypi'])

root = Path(__file__).absolute().parent.parent
os.chdir(root) # just in case
Expand All @@ -42,7 +42,7 @@ def main():
if dist.exists():
shutil.rmtree(dist)

check_call('python3 setup.py sdist bdist_wheel', shell=True)
check_call(['python3', '-m', 'build'])

TP = 'TWINE_PASSWORD'
password = os.environ.get(TP)
Expand Down
2 changes: 1 addition & 1 deletion .ci/run
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ if ! command -v python3 &> /dev/null; then
fi

"$PY_BIN" -m pip install --user tox
"$PY_BIN" -m tox "$@"
"$PY_BIN" -m tox --parallel --parallel-live "$@"
12 changes: 5 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ on:
jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest] # TODO windows-latest??
python-version: ['3.8', '3.9', '3.10', '3.11']
platform: [ubuntu-latest, macos-latest] # todo windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
# vvv just an example of excluding stuff from matrix
# exclude: [{platform: macos-latest, python-version: '3.6'}]

Expand All @@ -33,9 +34,6 @@ jobs:
steps:
# ugh https://github.com/actions/toolkit/blob/main/docs/commands.md#path-manipulation
- run: echo "$HOME/.local/bin" >> $GITHUB_PATH
- if: ${{ matrix.platform == 'macos-latest' && matrix.python-version == '3.11' }}
# hmm somehow only seems necessary for 3.11 on osx??
run: echo "$HOME/Library/Python/${{ matrix.python-version }}/bin" >> $GITHUB_PATH

- uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -80,12 +78,12 @@ jobs:
if: github.event_name != 'pull_request' && github.event.ref == 'refs/heads/master'
env:
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD_TEST }}
run: pip3 install --user wheel twine && .ci/release --test
run: pip3 install --user --upgrade build twine && .ci/release --test

- name: 'release to pypi'
# always deploy tags to release pypi
# NOTE: release tags are guarded by on: push: tags on the top
if: github.event_name != 'pull_request' && startsWith(github.event.ref, 'refs/tags')
env:
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: pip3 install --user wheel twine && .ci/release
run: pip3 install --user --upgrade build twine && .ci/release
32 changes: 0 additions & 32 deletions .pylintrc

This file was deleted.

59 changes: 59 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# see https://github.com/karlicoss/pymplate for up-to-date reference
[project]
dynamic = ["version"] # version is managed by setuptools_scm
name = "cachew"
dependencies = [
"appdirs" , # default cache dir
"sqlalchemy>=1.0", # cache DB interaction
"orjson", # fast json serialization
"pytz", # used to properly marshall pytz datatimes
]
requires-python = ">=3.8"

## these need to be set if you're planning to upload to pypi
# description = "TODO"
license = {file = "LICENSE.txt"}
authors = [
{name = "Dima Gerasimov (@karlicoss)", email = "karlicoss@gmail.com"},
]
maintainers = [
{name = "Dima Gerasimov (@karlicoss)", email = "karlicoss@gmail.com"},
]
# keywords = []
# # see: http://pypi.python.org/pypi?%3Aaction=list_classifiers
# classifiers = [
# ]


[project.urls]
Homepage = "https://github.com/karlicoss/cachew"
##


[project.optional-dependencies]
testing = [
"pytest",
"more-itertools",
"patchy", # for injecting sleeps and testing concurrent behaviour
"enlighten", # used in logging helper, but not really required
"cattrs", # benchmarking alternative marshalling implementation
"pyinstrument", # for profiling from within tests
"codetiming", # Timer context manager

"ruff",

"mypy",
"lxml", # for mypy html coverage
]
optional = [
"colorlog",
]


[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
version_scheme = "python-simplified-semver"
local_scheme = "dirty-tag"
25 changes: 25 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ignore = [
### too opinionated style checks
"E501", # too long lines
"E702", # Multiple statements on one line (semicolon)
"E731", # assigning lambda instead of using def
"E741", # Ambiguous variable name: `l`
"E742", # Ambiguous class name: `O
"E401", # Multiple imports on one line
"F403", # import *` used; unable to detect undefined names
###

###
"E722", # Do not use bare `except` ## Sometimes it's useful for defensive imports and that sort of thing..
"F811", # Redefinition of unused # this gets in the way of pytest fixtures (e.g. in cachew)

## might be nice .. but later and I don't wanna make it strict
"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
"F841", # Local variable `count` is assigned to but never used
"F401", # imported but unused
###
]
69 changes: 0 additions & 69 deletions setup.py

This file was deleted.

32 changes: 17 additions & 15 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,26 +1,35 @@
[tox]
minversion = 3.5
minversion = 3.21
# relies on the correct version of Python installed
envlist = tests,pylint,mypy
envlist = ruff,tests,mypy
# https://github.com/tox-dev/tox/issues/20#issuecomment-247788333
# hack to prevent .tox from crapping to the project directory
toxworkdir={env:TOXWORKDIR_BASE:}{toxinidir}/.tox
toxworkdir = {env:TOXWORKDIR_BASE:}{toxinidir}/.tox

[testenv]
# TODO how to get package name from setuptools?
package_name = "cachew"
passenv =
# useful for tests to know they are running under ci
CI
CI_*
CIRCLE*
# respect user's cache dirs to prevent tox from crapping into project dir
MYPY_CACHE_DIR
# respect user's cache dirs to prevent tox from crapping into project dir
PYTHONPYCACHEPREFIX
MYPY_CACHE_DIR
RUFF_CACHE_DIR


[testenv:ruff]
commands =
{envpython} -m pip install --use-pep517 -e .[testing]
{envpython} -m ruff 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]
commands =
{envpython} -m pip install -e .[testing]
{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} \
Expand All @@ -29,7 +38,7 @@ commands =

[testenv:mypy]
commands =
{envpython} -m pip install -e .[testing,optional]
{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
Expand All @@ -38,13 +47,6 @@ commands =
{posargs}


# todo get rid of pylint? it has limited value...
[testenv:pylint]
commands =
{envpython} -m pip install -e .[testing]
{envpython} -m pylint src/cachew {posargs}


# todo not sure if really need bandit at all?
[testenv:bandit]
commands =
Expand Down

0 comments on commit 1e9f3dd

Please sign in to comment.