From d70eb78a76c84dca5564266a9c37c61a0ea11fc9 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 11 Dec 2023 13:51:45 +0100 Subject: [PATCH] remove tox run from deploy-chatmail and use 'cmdeploy fmt' and 'pytest' directly --- .github/workflows/ci.yaml | 21 ++++---- deploy-chatmail/pyproject.toml | 17 ------ .../src/deploy_chatmail/cmdeploy.py | 53 +++++++++++++++++-- tests/conftest.py | 2 - 4 files changed, 62 insertions(+), 31 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f8c593ca..67984fbf 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,7 +6,7 @@ on: jobs: tox: - name: chatmail tests + name: isolated chatmaild tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -15,15 +15,8 @@ jobs: working-directory: chatmaild run: pipx run tox - - name: run deploy-chatmail offline tests - working-directory: deploy-chatmail - run: pipx run tox - - name: run deploy-chatmail offline tests - working-directory: deploy-chatmail - run: pipx run tox - scripts: - name: cmdeploy invocations + name: deploy-chatmail tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -31,5 +24,15 @@ jobs: - name: initenv run: scripts/initenv.sh + - name: run formatting checks + run: venv/bin/cmdeploy fmt -v + + - name: run deploy-chatmail offline tests + working-directory: deploy-chatmail + run: venv/bin/pytest tests + - name: initialize with chatmail domain run: venv/bin/cmdeploy init chat.example.org + + # all other cmdeploy commands require a staging server + # see https://github.com/deltachat/chatmail/issues/100 diff --git a/deploy-chatmail/pyproject.toml b/deploy-chatmail/pyproject.toml index f480bec1..c2e429b4 100644 --- a/deploy-chatmail/pyproject.toml +++ b/deploy-chatmail/pyproject.toml @@ -25,20 +25,3 @@ cmdeploy = "deploy_chatmail.cmdeploy:main" [tool.pytest.ini_options] addopts = "-v -ra --strict-markers" - -[tool.tox] -legacy_tox_ini = """ -[tox] -isolated_build = true -envlist = lint - -[testenv:lint] -skipdist = True -skip_install = True -deps = - ruff - black -commands = - black --quiet --check --diff src/ - ruff src/ -""" diff --git a/deploy-chatmail/src/deploy_chatmail/cmdeploy.py b/deploy-chatmail/src/deploy_chatmail/cmdeploy.py index cf37f28e..25f11ab5 100644 --- a/deploy-chatmail/src/deploy_chatmail/cmdeploy.py +++ b/deploy-chatmail/src/deploy_chatmail/cmdeploy.py @@ -6,6 +6,7 @@ import argparse import datetime import shutil import subprocess +import importlib.resources import importlib.util import os import sys @@ -132,6 +133,51 @@ def test_cmd(args, out): return 0 +def fmt_cmd_options(parser): + parser.add_argument( + "--verbose", + "-v", + dest="verbose", + action="store_true", + help="provide information on invocations", + ) + + parser.add_argument( + "--check", + "-c", + action="store_true", + help="only check but don't fix problems", + ) + + +def fmt_cmd(args, out): + """Run formattting fixes (fuff and black) on all chatmail source code.""" + + chatmaild = importlib.resources.files("chatmaild") + deploy_chatmail = importlib.resources.files("deploy_chatmail") + tests = deploy_chatmail.joinpath("../../../tests") + sources = list(str(x) for x in [chatmaild, deploy_chatmail, tests]) + + black_args = [shutil.which("black")] + ruff_args = [shutil.which("ruff")] + + if args.check: + black_args.append("--check") + else: + ruff_args.append("--fix") + + if not args.verbose: + black_args.append("-q") + ruff_args.append("-q") + + black_args.extend(sources) + ruff_args.extend(sources) + + out.check_call(" ".join(black_args), quiet=not args.verbose) + out.check_call(" ".join(ruff_args), quiet=not args.verbose) + return 0 + + def bench_cmd(args, out): """Run benchmarks against an online chatmail instance.""" pytest_path = shutil.which("pytest") @@ -168,8 +214,9 @@ class Out: self(f"[$ {arg}]", file=sys.stderr) return subprocess.check_output(arg, shell=True).decode() - def check_call(self, arg, env=None): - self(f"[$ {arg}]", file=sys.stderr) + def check_call(self, arg, env=None, quiet=False): + if not quiet: + self(f"[$ {arg}]", file=sys.stderr) return subprocess.check_call(arg, shell=True, env=env) @@ -228,7 +275,7 @@ def main(args=None): return parser.parse_args(["-h"]) out = Out() kwargs = {} - if args.func.__name__ != "init_cmd": + if args.func.__name__ not in ("init_cmd", "fmt_cmd"): if not args.inipath.exists(): out.red(f"expecting {args.inipath} to exist, run init first?") raise SystemExit(1) diff --git a/tests/conftest.py b/tests/conftest.py index d3a4e970..cbbf75a0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,8 +6,6 @@ import subprocess import imaplib import smtplib import itertools -from email.parser import BytesParser -from email import policy from pathlib import Path import pytest