Skip to content

Commit 8fbc5f4

Browse files
authored
Add GitHub workflows for linting, testing, building, and publishing (y-scope#32)
1 parent 23bdc28 commit 8fbc5f4

File tree

10 files changed

+306
-126
lines changed

10 files changed

+306
-126
lines changed

.github/workflows/package.yaml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Lint, build, and test package
2+
3+
on:
4+
pull_request:
5+
push:
6+
workflow_call:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: ["3.8", "3.11"]
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- uses: actions/setup-python@v4
18+
with:
19+
python-version: ${{ matrix.python-version }}
20+
21+
- run: pip install --upgrade
22+
pip
23+
.[dev]
24+
25+
- run: docformatter --check --diff src tests
26+
27+
- run: black --diff --check src/ tests/
28+
29+
- run: ruff check --format=github src/ tests/
30+
31+
- run: mypy src/ tests/
32+
33+
- run: python -m build
34+
35+
- uses: actions/upload-artifact@v3
36+
with:
37+
name: wheel-${{ matrix.python-version }}
38+
path: dist/*
39+
retention-days: 1
40+
41+
test:
42+
needs: [build]
43+
strategy:
44+
matrix:
45+
os: [macos-latest, ubuntu-latest]
46+
python-version: ["3.8", "3.11"]
47+
runs-on: ${{ matrix.os }}
48+
steps:
49+
- uses: actions/checkout@v3
50+
51+
- uses: actions/setup-python@v4
52+
with:
53+
python-version: ${{ matrix.python-version }}
54+
55+
- uses: actions/download-artifact@v3
56+
with:
57+
name: wheel-${{ matrix.python-version }}
58+
path: dist/
59+
60+
- run: pip install --upgrade
61+
pip
62+
dist/clp_logging-*.whl
63+
-r requirements-test.txt
64+
65+
- run: python -m unittest -fv
66+
67+
test-py36:
68+
needs: [build]
69+
strategy:
70+
matrix:
71+
os: [macos-latest, ubuntu-20.04]
72+
runs-on: ${{ matrix.os }}
73+
steps:
74+
- uses: actions/checkout@v3
75+
76+
- uses: actions/setup-python@v4
77+
with:
78+
python-version: "3.6"
79+
80+
- uses: actions/download-artifact@v3
81+
with:
82+
name: wheel-3.8
83+
path: dist/
84+
85+
- run: pip install --upgrade
86+
pip
87+
dist/clp_logging-*.whl
88+
-r requirements-test.txt
89+
90+
- run: python -m unittest -fv

.github/workflows/release.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Upload package to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
package:
10+
uses: ./.github/workflows/package.yaml
11+
12+
# https://docs.pypi.org/trusted-publishers/using-a-publisher/
13+
pypi-publish:
14+
needs: [package]
15+
runs-on: ubuntu-latest
16+
environment: release
17+
permissions:
18+
id-token: write
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
- uses: actions/setup-python@v4
23+
with:
24+
python-version: "3.8"
25+
26+
- uses: actions/download-artifact@v3
27+
with:
28+
name: wheel-3.8
29+
path: dist/
30+
31+
- name: Publish to test.pypi.org
32+
if: ${{ 'y-scope' != github.repository_owner }}
33+
uses: pypa/gh-action-pypi-publish@release/v1
34+
with:
35+
repository-url: https://test.pypi.org/legacy/
36+
37+
- name: Publish to pypi.org
38+
if: ${{ 'y-scope' == github.repository_owner }}
39+
uses: pypa/gh-action-pypi-publish@release/v1

README.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -198,33 +198,34 @@ logging.getLogger(__name__).addHandler(clp_handler)
198198

199199
## Compatibility
200200

201-
Tested on Python 3.6 and 3.8 and should work on any newer version.
201+
Tested on Python 3.6, 3.8, and 3.11 (should also work on newer versions).
202202
Built/packaged on Python 3.8 for convenience regarding type annotation.
203203

204-
## Building/Packaging
204+
## Development
205+
206+
### Setup environment
205207

206208
1. Create and enter a virtual environment:
207209
`python3.8 -m venv venv; . ./venv/bin/activate`
208-
2. Install development dependencies:
209-
`pip install -r requirements-dev.txt`
210-
3. Build:
210+
2. Install the project in editable mode, the development dependencies, and the test dependencies:
211+
`pip install -e .[dev,test]`
212+
213+
Note: you may need to upgrade pip first for `-e` to work. If so, run: `pip install --upgrade pip`
214+
215+
### Packaging
216+
217+
To build a package for distribution run:
211218
`python -m build`
212219

213-
## Testing
220+
### Testing
214221

215-
Note the baseline comparison logging handler and the CLP handler both get
222+
To run the unit tests run:
223+
`python -m unittest -bv`
224+
225+
Note: the baseline comparison logging handler and the CLP handler both get
216226
unique timestamps. It is possible for these timestamps to differ, which will
217227
result in a test reporting a false positive error.
218228

219-
1. Create and enter a virtual environment:
220-
`python -m venv venv; . ./venv/bin/activate`
221-
2. Install development dependencies:
222-
`pip install -r requirements-dev.txt`
223-
3. Install:
224-
`pip install dist/clp_logging-*-py3-none-any.whl` or `pip install -e .`
225-
4. Run unittest:
226-
`python -m unittest -bv`
227-
228229
## Contributing
229230

230231
Before submitting a pull request, run the following error-checking and
@@ -239,6 +240,9 @@ formatting tools (found in [requirements-dev.txt](requirements-dev.txt)):
239240
* [Black][6]: `black src tests`
240241
* This formats the code according to Black's code-style rules. You should
241242
review and add any changes to your PR.
243+
* [ruff][8]: `ruff check --fix src tests`
244+
* This performs linting according to PEPs. You should review and add any
245+
changes to your PR.
242246

243247
Note that `docformatter` should be run before `black` to give Black the [last
244248
word][7].
@@ -251,3 +255,4 @@ word][7].
251255
[5]: https://docformatter.readthedocs.io/en/latest/
252256
[6]: https://black.readthedocs.io/en/stable/index.html
253257
[7]: https://docformatter.readthedocs.io/en/latest/faq.html#interaction-with-black
258+
[8]: https://beta.ruff.rs/docs/

pyproject.toml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,35 @@ readme = "README.md"
1414
requires-python = ">=3.6"
1515
dependencies = [
1616
"python-dateutil >= 2.7.0",
17-
"smart_open >= 6.3.0",
1817
"typing-extensions >= 3.7.4",
1918
"zstandard >= 0.18.0",
2019
]
2120
classifiers = [
2221
"License :: OSI Approved :: Apache Software License",
2322
]
2423

24+
[project.optional-dependencies]
25+
dev = [
26+
"black >= 22.10.0",
27+
"build >= 0.8.0",
28+
"docformatter >= 1.5.1",
29+
"mypy >= 0.982",
30+
"ruff >= 0.0.275",
31+
"types-python-dateutil >= 2.8.19.2",
32+
]
33+
test = [
34+
"smart_open >= 6.3.0",
35+
]
36+
2537
[project.urls]
2638
"Homepage" = "https://github.com/y-scope/clp-loglib-py"
2739
"Bug Tracker" = "https://github.com/y-scope/clp-loglib-py/issues"
2840

29-
[tool.setuptools_scm]
30-
31-
[tool.mypy]
32-
strict = true
33-
pretty = true
41+
[tool.black]
42+
line-length = 100
43+
target-version = ["py311"]
44+
color = true
45+
preview = true
3446

3547
[tool.docformatter]
3648
make-summary-multi-line = true
@@ -39,8 +51,12 @@ recursive = true
3951
wrap-summaries = 80
4052
wrap-descriptions = 80
4153

42-
[tool.black]
54+
[tool.mypy]
55+
strict = true
56+
pretty = true
57+
58+
[tool.ruff]
4359
line-length = 100
44-
target-version = ["py311"]
45-
color = true
46-
preview = true
60+
src = ["src"]
61+
62+
[tool.setuptools_scm]

requirements-dev.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
smart_open>=6.3.0

src/clp_logging/decoder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Dict, Optional, Tuple
2+
from typing import Optional, Tuple
33

44
from clp_logging.protocol import (
55
BYTE_ORDER,

src/clp_logging/encoder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from math import floor
33
import re
44
import time
5-
from typing import Dict, Match, Pattern
5+
from typing import Match, Pattern
66

77
from clp_logging.protocol import (
88
BYTE_ORDER,
@@ -72,11 +72,11 @@ def emit_preamble(timestamp: int, timestamp_format: str, timezone: str) -> bytea
7272
Create the encoded CLP preamble for a stream of encoded log messages.
7373
7474
:param timestamp: Reference timestamp used to calculate deltas emitted
75-
with each message.
75+
with each message.
7676
:param timestamp_format: Timestamp format to be use when generating the
77-
logs with a reader.
77+
logs with a reader.
7878
:param timezone: Timezone in TZID format to be use when generating the
79-
timestamp from Unix epoch time.
79+
timestamp from Unix epoch time.
8080
:raises NotImplementedError: If metadata length too large
8181
:return: The encoded preamble
8282
"""
@@ -233,7 +233,7 @@ def emit_token(token_m: Match[bytes], clp_msg: bytearray) -> bytes:
233233
Encode `token_m` appending it to `clp_msg` if it is a variable.
234234
235235
:return: If the token was a variable returns the delimiter to append to
236-
logtype, otherwise returns the static text to append to the logtype.
236+
logtype, otherwise returns the static text to append to the logtype.
237237
"""
238238
token: bytes = token_m.group(0)
239239

0 commit comments

Comments
 (0)