Skip to content

Commit 65be776

Browse files
committed
Refactor CI.
1 parent 5621066 commit 65be776

File tree

11 files changed

+201
-96
lines changed

11 files changed

+201
-96
lines changed

.github/workflows/lint_and_test.yml

+46-54
Original file line numberDiff line numberDiff line change
@@ -5,109 +5,101 @@ on:
55
push:
66

77
jobs:
8-
lint:
8+
linting:
99
runs-on: ubuntu-latest
1010
steps:
11-
- name: Setup python 🐍
12-
uses: actions/setup-python@v4
13-
with:
14-
python-version: 3.9
15-
16-
- name: Checkout ⬇️
11+
- name: Checkout 🛎️
1712
uses: actions/checkout@v4
1813
with:
1914
persist-credentials: false
2015

2116
- name: Install dependencies ☕️
22-
run: |
23-
pip install -U pip setuptools
24-
pip install .[dev]
17+
run: pip install .[dev]
2518

2619
- name: Lint 🔍
27-
run: ./tests/lint.sh
20+
run: ./tests/linting.sh
2821

29-
pypi:
22+
typecheck:
3023
runs-on: ubuntu-latest
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
python: ["38", "39", "310", "311"]
28+
name: typecheck (python ${{ matrix.python }})
3129
steps:
32-
- name: Setup python 🐍
33-
uses: actions/setup-python@v4
34-
with:
35-
python-version: 3.9
36-
37-
- name: Checkout ⬇️
30+
- name: Checkout 🛎️
3831
uses: actions/checkout@v4
3932
with:
4033
persist-credentials: false
4134

4235
- name: Install dependencies ☕️
43-
run: |
44-
pip install -U pip setuptools
45-
pip install -U twine build
36+
run: pip install .[dev]
4637

47-
- name: Check bundling 📦
48-
run: python -m build
38+
- name: Typecheck 📋
39+
run: ./tests/typecheck.sh
4940

50-
- name: Check setup 🚦
51-
run: twine check "dist/order-*.tar.gz"
52-
53-
test:
41+
unittest:
5442
runs-on: ubuntu-latest
5543
strategy:
5644
fail-fast: false
5745
matrix:
58-
python-version:
59-
- "3.7"
60-
- "3.8"
61-
- "3.9"
62-
- "3.10"
63-
- "3.11"
64-
- "3.12"
65-
name: test (python ${{ matrix.python-version }})
46+
python: ["37", "38", "39", "310", "311"]
47+
name: unittest (python ${{ matrix.python }})
6648
steps:
67-
- name: Setup Python ${{ matrix.python-version }} 🐍
68-
uses: actions/setup-python@v4
69-
with:
70-
python-version: ${{ matrix.python-version }}
71-
72-
- name: Checkout ⬇️
49+
- name: Checkout 🛎️
7350
uses: actions/checkout@v4
7451
with:
7552
persist-credentials: false
7653

7754
- name: Install dependencies ☕️
78-
run: |
79-
pip install -U pip setuptools
80-
pip install .[dev]
55+
run: pip install .[dev]
8156

8257
- name: Test 🎢
83-
run: |
84-
./tests/test.sh
58+
run: ./tests/unittest.sh
8559

86-
coverage:
60+
pypi:
8761
runs-on: ubuntu-latest
8862
steps:
63+
- name: Checkout 🛎️
64+
uses: actions/checkout@v4
65+
with:
66+
persist-credentials: false
67+
8968
- name: Setup python 🐍
90-
uses: actions/setup-python@v4
69+
uses: actions/setup-python@v5
9170
with:
9271
python-version: 3.9
9372

73+
- name: Install dependencies ☕️
74+
run: |
75+
pip install -U pip setuptools
76+
pip install -U twine build
77+
78+
- name: Check bundling 📦
79+
run: python -m build
80+
81+
- name: Check setup 🚦
82+
run: twine check "dist/order-*.tar.gz"
83+
84+
coverage:
85+
runs-on: ubuntu-latest
86+
steps:
9487
- name: Checkout ⬇️
9588
uses: actions/checkout@v4
9689
with:
9790
persist-credentials: false
91+
submodules: recursive
9892

9993
- name: Install dependencies ☕️
100-
run: |
101-
pip install -U pip setuptools
102-
pip install .[dev]
94+
run: pip install .[dev]
10395

10496
- name: Run coverage test 🎢
105-
run: |
106-
pytest --cov=order --cov-report xml:coverage.xml tests
97+
run: ./tests/coverage.sh
10798

10899
- name: Upload report 🔝
109-
uses: codecov/codecov-action@v2
100+
uses: codecov/codecov-action@v3
110101
with:
111102
token: ${{ secrets.CODECOV_TOKEN }}
112103
files: ./coverage.xml
113104
flags: unittests
105+
fail_ci_if_error: false

order/adapters/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,11 @@ def check_cache(
233233

234234
# helper to find a cached file in a directory with the largest timestamp and to invalidate
235235
# too old ones
236-
cre = re.compile(rf"^{h}(|_\d+)\.json$")
237-
238236
def find(directory: str, ts: int, invalidate: bool) -> str | None:
239237
if not os.path.exists(directory):
240238
return None
241239

240+
cre = re.compile(rf"^{h}(|_\d+)\.json$")
242241
files = {
243242
int(m.group(1)[1:] or 0): os.path.join(directory, elem)
244243
for elem in os.listdir(directory)

order/models/dataset.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pydantic import Field, field_validator
1212

1313
from order.types import (
14-
Union, List, Dict, NonEmptyStrictStr, PositiveStrictInt, Lazy, ClassVar, GeneratorType, Any,
14+
Union, List, Dict, NonEmptyStrictStr, PositiveStrictInt, Lazy, ClassVar, Any,
1515
)
1616
# from order.util import validated
1717
from order.models.base import Model, AdapterModel

requirements_dev.txt

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
ipython~=8.8
2-
pytest~=7.1
3-
pytest-cov~=3.0
4-
flake8~=5.0
5-
flake8-commas~=2.1
6-
flake8-quotes~=3.3
7-
pipdeptree~=2.13
1+
mypy~=1.8.0;python_version>="3.8"
2+
flake8~=7.0.0;python_version>="3.8"
3+
flake8~=5.0.0;python_version<"3.8"
4+
flake8-commas~=2.1.0
5+
flake8-quotes~=3.3.2
6+
pytest~=7.4.4
7+
pytest-cov~=4.1.0
8+
ipykernel~=6.29.0;python_version>="3.8"
9+
ipykernel~=6.16.0;python_version<"3.8"
10+
types-docutils~=0.20.0;python_version>="3.8"
11+
types-docutils~=0.20.0;python_version<"3.8"
812
cloudpickle>=1.3
913
mermaidmro~=0.1.2

tests/all.sh

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
# Script to run all tests, including linting, type checking and unit tests in this order.
4+
# Arguments:
5+
# 1. The error mode. When "stop", the script stops on the first error. No default.
6+
# 2. Which steps to run. Defaults to "linting typecheck unittest".
7+
8+
action() {
9+
local shell_is_zsh="$( [ -z "${ZSH_VERSION}" ] && echo "false" || echo "true" )"
10+
local this_file="$( ${shell_is_zsh} && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )"
11+
local this_dir="$( cd "$( dirname "${this_file}" )" && pwd )"
12+
13+
# default error mode
14+
local error_mode="${1:-}"
15+
local what="${2:-linting typecheck unittest}"
16+
17+
# return codes
18+
local global_ret="0"
19+
local ret
20+
21+
# linting
22+
if [[ "${what}" =~ "linting" ]]; then
23+
echo -e "\n\x1b[0;49;35m--- linting ----------------------------\x1b[0m\n"
24+
bash "${this_dir}/linting.sh"
25+
ret="$?"
26+
[ "${error_mode}" = "stop" ] && [ "${ret}" -ne "0" ] && return "${ret}"
27+
[ "${global_ret}" -eq "0" ] && global_ret="${ret}"
28+
fi
29+
30+
# type checking
31+
if [[ "${what}" =~ "typecheck" ]]; then
32+
echo -e "\n\n\x1b[0;49;35m--- type checking ----------------------\x1b[0m\n"
33+
bash "${this_dir}/typecheck.sh"
34+
ret="$?"
35+
[ "${error_mode}" = "stop" ] && [ "${ret}" -ne "0" ] && return "${ret}"
36+
[ "${global_ret}" -eq "0" ] && global_ret="${ret}"
37+
fi
38+
39+
# unit tests
40+
if [[ "${what}" =~ "unittest" ]]; then
41+
echo -e "\n\n\x1b[0;49;35m--- unit tests -------------------------\x1b[0m\n"
42+
bash "${this_dir}/unittest.sh"
43+
ret="$?"
44+
[ "${error_mode}" = "stop" ] && [ "${ret}" -ne "0" ] && return "${ret}"
45+
[ "${global_ret}" -eq "0" ] && global_ret="${ret}"
46+
fi
47+
48+
return "${global_ret}"
49+
}
50+
action "$@"

tests/coverage.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# Script to run coverage tests.
4+
# Arguments:
5+
# 1. The command. Defaults to "pytest --cov=order --cov-report xml:coverage.xml tests".
6+
7+
action() {
8+
local shell_is_zsh="$( [ -z "${ZSH_VERSION}" ] && echo "false" || echo "true" )"
9+
local this_file="$( ${shell_is_zsh} && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )"
10+
local this_dir="$( cd "$( dirname "${this_file}" )" && pwd )"
11+
local repo_dir="$( dirname "${this_dir}" )"
12+
13+
# default test command
14+
local cmd="${1:-pytest --cov=order --cov-report xml:coverage.xml tests}"
15+
16+
# execute it
17+
echo "command: ${cmd}"
18+
(
19+
cd "${repo_dir}"
20+
eval "${cmd}"
21+
)
22+
}
23+
action "$@"

tests/lint.sh

-16
This file was deleted.

tests/linting.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# Script to run linting checks.
4+
# Arguments:
5+
# 1. The command. Defaults to "flake8 order tests docs/conf.py".
6+
7+
action() {
8+
local shell_is_zsh="$( [ -z "${ZSH_VERSION}" ] && echo "false" || echo "true" )"
9+
local this_file="$( ${shell_is_zsh} && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )"
10+
local this_dir="$( cd "$( dirname "${this_file}" )" && pwd )"
11+
local repo_dir="$( dirname "${this_dir}" )"
12+
13+
# default test command
14+
local cmd="${1:-flake8 order tests docs/conf.py}"
15+
16+
# execute it
17+
echo -e "command: \x1b[1;49;39m${cmd}\x1b[0m"
18+
(
19+
cd "${repo_dir}"
20+
eval "${cmd}" && echo -e "\x1b[1;49;32mlinting checks passed\x1b[0m"
21+
)
22+
}
23+
action "$@"

tests/test.sh

-16
This file was deleted.

tests/typecheck.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# Script to run mypy type checks.
4+
# Arguments:
5+
# 1. The command. Defaults to "mypy order tests".
6+
7+
action() {
8+
local shell_is_zsh="$( [ -z "${ZSH_VERSION}" ] && echo "false" || echo "true" )"
9+
local this_file="$( ${shell_is_zsh} && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )"
10+
local this_dir="$( cd "$( dirname "${this_file}" )" && pwd )"
11+
local repo_dir="$( dirname "${this_dir}" )"
12+
13+
# default test command
14+
local cmd="${1:-mypy order tests}"
15+
16+
# execute it
17+
echo -e "command: \x1b[1;49;39m${cmd}\x1b[0m"
18+
(
19+
cd "${repo_dir}"
20+
eval "${cmd}"
21+
)
22+
}
23+
action "$@"

tests/unittest.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
# Script to run all tests.
4+
# Arguments:
5+
# 1. The command. Defaults to "python -m pytest tests".
6+
7+
action() {
8+
local shell_is_zsh="$( [ -z "${ZSH_VERSION}" ] && echo "false" || echo "true" )"
9+
local this_file="$( ${shell_is_zsh} && echo "${(%):-%x}" || echo "${BASH_SOURCE[0]}" )"
10+
local this_dir="$( cd "$( dirname "${this_file}" )" && pwd )"
11+
local repo_dir="$( dirname "${this_dir}" )"
12+
13+
# default test command
14+
local cmd="${1:-python -m pytest tests}"
15+
16+
# execute it
17+
echo -e "command: \x1b[1;49;39m${cmd}\x1b[0m"
18+
(
19+
cd "${repo_dir}"
20+
eval "${cmd}" && echo -e "\x1b[1;49;32munit tests passed\x1b[0m"
21+
)
22+
}
23+
action "$@"

0 commit comments

Comments
 (0)