Skip to content

Commit e0a2c0b

Browse files
authored
Athena API / Client Library - Basics (#1)
* Adds the GRPC codegen and co-routine wrappers * CI pipeline for build and test * pre-commit-config.yaml
1 parent 06b97e7 commit e0a2c0b

26 files changed

Lines changed: 1403 additions & 3 deletions

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/athena_client/generated/* linguist-generated=true

.github/workflows/build_and_test.yml

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ jobs:
1616
- name: Checkout code
1717
uses: actions/checkout@v3
1818

19+
- name: Initialize submodules
20+
env:
21+
GIT_ASKPASS: /bin/echo
22+
GH_PAT: ${{ secrets.GH_PAT }}
23+
run: |
24+
git config --global url."https://${GH_PAT}@github.com/".insteadOf "https://github.com/"
25+
git submodule update --init --recursive
26+
1927
- name: Install uv
2028
uses: astral-sh/setup-uv@v6
2129
with:
@@ -29,18 +37,43 @@ jobs:
2937

3038
- name: Ensure no differences in generated code
3139
run: |
32-
cp -r src/athena_client/generated src/athena_client/generated_backup
33-
./scripts/compile_proto.sh
34-
diff -r src/athena_client/generated src/athena_client/generated_backup || (echo "Generated code differs. Please commit the changes after running compile_proto.sh." && exit 1)
40+
source .venv/bin/activate
41+
GENERATED_DIR="src/athena_client/generated"
42+
BACKUP_DIR="src/athena_client/generated_backup"
43+
44+
cp -r $GENERATED_DIR $BACKUP_DIR
45+
46+
./scripts/compile_proto.sh || (echo "Protobuf compilation failed. Ensure submodules are initialized and the proto file exists." && exit 1)
47+
48+
# Fix imports in generated files
49+
if [[ -f "$GENERATED_DIR/athena/athena_pb2_grpc.py" && -f "$GENERATED_DIR/athena/athena_pb2.py" ]]; then
50+
sed -i "$GENERATED_DIR/athena/athena_pb2_grpc.py" -e 's/^from athena /from athena_client.generated.athena /'
51+
sed -i "$GENERATED_DIR/athena/athena_pb2.py" -e 's/^from athena /from athena_client.generated.athena /'
52+
else
53+
echo "Error: Expected files not found in $GENERATED_DIR/athena"
54+
exit 1
55+
fi
56+
57+
diff -r $GENERATED_DIR $BACKUP_DIR || (echo "Generated code differs. Please commit the changes after running compile_proto.sh." && exit 1)
58+
59+
rm -rf $BACKUP_DIR
3560
3661
- name: Run linter
3762
run: |
3863
uv run ruff check
3964
65+
- name: Run code formatting check
66+
run: |
67+
uv run ruff format --check
68+
4069
- name: Run type checking
4170
run: |
4271
uv run pyright
4372
4473
- name: Run tests
4574
run: |
4675
uv run pytest
76+
77+
- name: Build package
78+
run: |
79+
uv build

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Python-generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
8+
9+
# Virtual environments
10+
.venv

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "athena-protobufs"]
2+
path = athena-protobufs
3+
url = https://github.com/crispthinking/athena-protobufs.git

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.12.7
4+
hooks:
5+
- id: ruff-check
6+
args: [--fix]
7+
- id: ruff-format
8+
- repo: https://github.com/astral-sh/uv-pre-commit
9+
rev: 0.7.15
10+
hooks:
11+
- id: uv-lock
12+
- repo: https://github.com/fsouza/mirrors-pyright
13+
rev: v1.1.403
14+
hooks:
15+
- id: pyright
16+
- repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v5.0.0
18+
hooks:
19+
- id: mixed-line-ending
20+
- id: end-of-file-fixer
21+
- id: trailing-whitespace

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Athena Client Library
2+
3+
This is a Python library for interacting with the Athena API (Resolver Unknown
4+
CSAM Detection).
5+
6+
7+
## Development
8+
This package uses [uv](https://docs.astral.sh/uv/) to manage its packages.
9+
10+
To install dependencies, run:
11+
12+
```bash
13+
uv sync --dev
14+
```
15+
16+
To build the package, run:
17+
18+
```bash
19+
uv build
20+
```
21+
22+
To run the tests, run:
23+
24+
```bash
25+
pytest
26+
```
27+
28+
To lint and format the code, run:
29+
30+
```bash
31+
ruff check
32+
ruff format
33+
```
34+
35+
There are pre-commit hooks that will lint, format, and type check the code.
36+
Install them with:
37+
38+
```bash
39+
pre-commit install
40+
```
41+
42+
To re-compile the protobuf files, run from the repository's root directory:
43+
44+
```bash
45+
bash scripts/compile_proto.sh
46+
```

athena-protobufs

Submodule athena-protobufs added at 3ea354f

pyproject.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[project]
2+
name = "athena_client"
3+
version = "0.1.0"
4+
description = "Athena Client Library"
5+
readme = "README.md"
6+
authors = [{ name = "Resolver Global", email = "opensource@kroll.com" }]
7+
requires-python = ">=3.10"
8+
dependencies = ["grpcio-tools>=1.74.0"]
9+
10+
[dependency-groups]
11+
dev = [
12+
"mypy-protobuf>=3.6.0",
13+
"pre-commit>=4.2.0",
14+
"pyright>=1.1.403",
15+
"pytest>=8.4.1",
16+
"pytest-asyncio>=1.1.0",
17+
"ruff>=0.12.7",
18+
"types-protobuf>=6.30.2.20250703",
19+
]
20+
21+
[build-system]
22+
requires = ["uv_build>=0.7.19,<0.8.0"]
23+
build-backend = "uv_build"
24+
25+
[tool.ruff]
26+
line-length = 80
27+
exclude = ["src/athena_client/generated/*"]
28+
29+
[tool.ruff.lint]
30+
select = ["ALL"]
31+
ignore = ["COM812", "D213", "D211", "D203", "S101"]
32+
33+
[tool.ruff.lint.per-file-ignores]
34+
# Ignore doc lint rules in tests.
35+
"tests/**" = ["D"]
36+
37+
[tool.pyright]
38+
exclude = ["src/athena_client/generated/*", ".venv"]

scripts/compile_proto.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Define paths
4+
PROTO_DIR="athena-protobufs"
5+
OUT_DIR="src/athena_client/generated"
6+
7+
# Ensure output directory exists
8+
mkdir -p "$OUT_DIR"
9+
10+
# Compile .proto files
11+
if [ ! -f "$PROTO_DIR/athena/athena.proto" ]; then
12+
echo "Error: Protobuf file not found at $PROTO_DIR/athena/athena.proto. Ensure the submodule is initialized and updated."
13+
exit 1
14+
fi
15+
16+
python -m grpc_tools.protoc \
17+
--proto_path="$PROTO_DIR" \
18+
--python_out="$OUT_DIR" \
19+
--grpc_python_out="$OUT_DIR" \
20+
--mypy_out="$OUT_DIR" \
21+
"$PROTO_DIR/athena/athena.proto"
22+
23+
# Fix imports in generated files
24+
if [[ "$OSTYPE" == "darwin"* ]]; then
25+
sed -i '' -e 's/^from athena /from athena_client.generated.athena /' "$OUT_DIR/athena/athena_pb2_grpc.py"
26+
sed -i '' -e 's/^from athena /from athena_client.generated.athena /' "$OUT_DIR/athena/athena_pb2.py"
27+
else
28+
sed -i -e 's/^from athena /from athena_client.generated.athena /' "$OUT_DIR/athena/athena_pb2_grpc.py"
29+
sed -i -e 's/^from athena /from athena_client.generated.athena /' "$OUT_DIR/athena/athena_pb2.py"
30+
fi
31+
32+
if [ ! -f "$OUT_DIR/athena/athena_pb2.py" ] || [ ! -f "$OUT_DIR/athena/athena_pb2_grpc.py" ]; then
33+
echo "Error: Protobuf files were not generated successfully in $OUT_DIR."
34+
exit 1
35+
fi
36+
37+
echo "Compilation complete. Files generated in $OUT_DIR"

0 commit comments

Comments
 (0)