remove tox run from deploy-chatmail and use 'cmdeploy fmt' and 'pytest' directly

This commit is contained in:
holger krekel
2023-12-11 13:51:45 +01:00
parent 071d708a89
commit 56c7853e5b
4 changed files with 62 additions and 31 deletions

View File

@@ -6,7 +6,7 @@ on:
jobs: jobs:
tox: tox:
name: chatmail tests name: isolated chatmaild tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -15,15 +15,8 @@ jobs:
working-directory: chatmaild working-directory: chatmaild
run: pipx run tox 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: scripts:
name: cmdeploy invocations name: deploy-chatmail tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -31,5 +24,15 @@ jobs:
- name: initenv - name: initenv
run: scripts/initenv.sh 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 - name: initialize with chatmail domain
run: venv/bin/cmdeploy init chat.example.org run: venv/bin/cmdeploy init chat.example.org
# all other cmdeploy commands require a staging server
# see https://github.com/deltachat/chatmail/issues/100

View File

@@ -25,20 +25,3 @@ cmdeploy = "deploy_chatmail.cmdeploy:main"
[tool.pytest.ini_options] [tool.pytest.ini_options]
addopts = "-v -ra --strict-markers" 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/
"""

View File

@@ -6,6 +6,7 @@ import argparse
import datetime import datetime
import shutil import shutil
import subprocess import subprocess
import importlib.resources
import importlib.util import importlib.util
import os import os
import sys import sys
@@ -132,6 +133,51 @@ def test_cmd(args, out):
return 0 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): def bench_cmd(args, out):
"""Run benchmarks against an online chatmail instance.""" """Run benchmarks against an online chatmail instance."""
pytest_path = shutil.which("pytest") pytest_path = shutil.which("pytest")
@@ -168,8 +214,9 @@ class Out:
self(f"[$ {arg}]", file=sys.stderr) self(f"[$ {arg}]", file=sys.stderr)
return subprocess.check_output(arg, shell=True).decode() return subprocess.check_output(arg, shell=True).decode()
def check_call(self, arg, env=None): def check_call(self, arg, env=None, quiet=False):
self(f"[$ {arg}]", file=sys.stderr) if not quiet:
self(f"[$ {arg}]", file=sys.stderr)
return subprocess.check_call(arg, shell=True, env=env) return subprocess.check_call(arg, shell=True, env=env)
@@ -228,7 +275,7 @@ def main(args=None):
return parser.parse_args(["-h"]) return parser.parse_args(["-h"])
out = Out() out = Out()
kwargs = {} kwargs = {}
if args.func.__name__ != "init_cmd": if args.func.__name__ not in ("init_cmd", "fmt_cmd"):
if not args.inipath.exists(): if not args.inipath.exists():
out.red(f"expecting {args.inipath} to exist, run init first?") out.red(f"expecting {args.inipath} to exist, run init first?")
raise SystemExit(1) raise SystemExit(1)

View File

@@ -6,8 +6,6 @@ import subprocess
import imaplib import imaplib
import smtplib import smtplib
import itertools import itertools
from email.parser import BytesParser
from email import policy
from pathlib import Path from pathlib import Path
import pytest import pytest