Skip to content

Commit 5da353d

Browse files
authored
use uv (#9)
1 parent 0805f36 commit 5da353d

File tree

21 files changed

+3082
-177
lines changed

21 files changed

+3082
-177
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,43 @@ name: build
22

33
on:
44
push:
5-
pull_request:
5+
6+
env:
7+
PROJECT_NAME: genesis-notification
8+
REPO_ENDPOINT_PUT: http://10.20.0.1:8082
69

710
jobs:
811
Build:
912
runs-on: self-hosted
1013
strategy:
1114
fail-fast: true
1215
steps:
13-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v5
1417
- name: Build Genesis Core
1518
run: |
1619
set -eux
1720
1821
genesis build $(pwd)
1922
20-
# Temporary upload step is done in the build script
2123
VERSION="$(genesis get-version .)"
22-
ELEMENT_PATH="/var/lib/repository/genesis_notification"
24+
25+
# Prepare `raw` and `raw.gz` images
26+
cd output
27+
qemu-img convert -f qcow2 genesis-notification.qcow2 -O raw genesis-notification.raw
28+
gzip -5 -k < genesis-notification.raw > genesis-notification.raw.gz
29+
30+
# Upload the VM images
31+
curl -X PUT --upload-file genesis-notification.qcow2 \
32+
${REPO_ENDPOINT_PUT}/${PROJECT_NAME}/${VERSION}/genesis-notification.qcow2
33+
curl -X PUT --upload-file genesis-notification.raw.gz \
34+
${REPO_ENDPOINT_PUT}/${PROJECT_NAME}/${VERSION}/genesis-notification.raw.gz
35+
curl -X PUT --upload-file genesis-notification.raw \
36+
${REPO_ENDPOINT_PUT}/${PROJECT_NAME}/${VERSION}/genesis-notification.raw
37+
38+
sha256sum genesis-notification.qcow2 >> SHA256SUMS
39+
sha256sum genesis-notification.raw.gz >> SHA256SUMS
40+
sha256sum genesis-notification.raw >> SHA256SUMS
2341
24-
rm -fr "${ELEMENT_PATH}/${VERSION}"
25-
mkdir -p "${ELEMENT_PATH}/${VERSION}"
26-
mv output/genesis-notification.qcow2 "${ELEMENT_PATH}/${VERSION}/"
27-
cd ${ELEMENT_PATH}/${VERSION}/ && \
28-
sha256sum genesis-notification.qcow2 >> ${ELEMENT_PATH}/${VERSION}/SHA256SUMS
42+
curl -X PUT --upload-file SHA256SUMS \
43+
${REPO_ENDPOINT_PUT}/${PROJECT_NAME}/${VERSION}/SHA256SUMS
44+
cd -

.github/workflows/publish-to-pypi.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
steps:
14-
- uses: actions/checkout@v4
14+
- uses: actions/checkout@v5
1515
with:
1616
persist-credentials: false
1717
- name: Set up Python
@@ -27,7 +27,7 @@ jobs:
2727
- name: Build a binary wheel and a source tarball
2828
run: python3 -m build
2929
- name: Store the distribution packages
30-
uses: actions/upload-artifact@v4
30+
uses: actions/upload-artifact@v5
3131
with:
3232
name: python-package-distributions
3333
path: dist/
@@ -46,7 +46,7 @@ jobs:
4646

4747
steps:
4848
- name: Download all the dists
49-
uses: actions/download-artifact@v4
49+
uses: actions/download-artifact@v5
5050
with:
5151
name: python-package-distributions
5252
path: dist/
@@ -67,7 +67,7 @@ jobs:
6767

6868
steps:
6969
- name: Download all the dists
70-
uses: actions/download-artifact@v4
70+
uses: actions/download-artifact@v5
7171
with:
7272
name: python-package-distributions
7373
path: dist/

.github/workflows/tests.yaml

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ name: tests
22

33
on:
44
push:
5+
paths-ignore:
6+
- 'docs/**'
7+
- 'mkdocs.yml'
8+
- '.markdownlint.yaml'
59
pull_request:
6-
10+
paths-ignore:
11+
- 'docs/**'
12+
- 'mkdocs.yml'
13+
- '.markdownlint.yaml'
714
jobs:
815
Lint:
916
runs-on: ubuntu-24.04
@@ -12,22 +19,26 @@ jobs:
1219
matrix:
1320
python-version: ["3.12"]
1421
steps:
15-
- uses: actions/checkout@v3
22+
- uses: actions/checkout@v5
1623
- name: Set up Python ${{ matrix.python-version }}
1724
uses: actions/setup-python@v3
1825
with:
1926
python-version: ${{ matrix.python-version }}
2027
- name: Install requirements
2128
run: sudo apt update && sudo apt install --yes tox libev-dev libvirt-dev
22-
- name: Black
29+
- name: Install uv
30+
uses: astral-sh/setup-uv@v7
31+
- name: Install tox-uv
32+
run: uv tool install tox --with tox-uv
33+
- name: ruff
2334
run: |
24-
tox -e black-check
35+
tox -e ruff-check
2536
Tests:
2637
runs-on: ubuntu-24.04
2738
strategy:
2839
fail-fast: true
2940
matrix:
30-
python-version: ["3.8", "3.10", "3.12", "3.13"]
41+
python-version: ["3.8", "3.10", "3.11", "3.12", "3.13", "3.14"]
3142
services:
3243
postgresql:
3344
image: postgres:latest
@@ -43,13 +54,17 @@ jobs:
4354
# Maps tcp port 5432 on service container to the host
4455
- 5432:5432
4556
steps:
46-
- uses: actions/checkout@v3
57+
- uses: actions/checkout@v5
4758
- name: Set up Python ${{ matrix.python-version }}
48-
uses: actions/setup-python@v3
59+
uses: actions/setup-python@v6
4960
with:
5061
python-version: ${{ matrix.python-version }}
51-
- name: Install tox
52-
run: sudo apt update && sudo apt install --yes tox libev-dev libvirt-dev
62+
- name: Install requirements
63+
run: sudo apt update && sudo apt install --yes libev-dev libvirt-dev
64+
- name: Install uv
65+
uses: astral-sh/setup-uv@v7
66+
- name: Install tox-uv
67+
run: uv tool install tox --with tox-uv
5368
- name: Unit tests
5469
run: |
5570
tox -e ${{ matrix.python-version }}
@@ -65,13 +80,17 @@ jobs:
6580
matrix:
6681
python-version: ["3.12"]
6782
steps:
68-
- uses: actions/checkout@v3
83+
- uses: actions/checkout@v5
6984
- name: Set up Python ${{ matrix.python-version }}
70-
uses: actions/setup-python@v3
85+
uses: actions/setup-python@v6
7186
with:
7287
python-version: ${{ matrix.python-version }}
73-
- name: Install tox
74-
run: sudo apt update && sudo apt install --yes tox libev-dev libvirt-dev
88+
- name: Install requirements
89+
run: sudo apt update && sudo apt install --yes libev-dev
90+
- name: Install uv
91+
uses: astral-sh/setup-uv@v7
92+
- name: Install tox-uv
93+
run: uv tool install tox --with tox-uv
7594
- name: Coverage
7695
run: |
7796
tox -e begin,${{ matrix.python-version }},end

.gitignore

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ __pycache__/
1111

1212
# IDE
1313
.idea/
14-
.vscode
14+
.vscode/
1515

1616
# Distribution / packaging
1717
.Python
1818
build/
19-
output/
2019
develop-eggs/
2120
dist/
22-
deps/
2321
docker/common/bin
2422
downloads/
2523
eggs/
@@ -37,7 +35,6 @@ MANIFEST
3735
AUTHORS
3836
ChangeLog
3937
cover/
40-
version.txt
4138

4239
# OS
4340
.DS_Store
@@ -108,6 +105,7 @@ venv/
108105
ENV/
109106
env.bak/
110107
venv.bak/
108+
*.conf
111109

112110
# Spyder project settings
113111
.spyderproject
@@ -129,6 +127,5 @@ docs/source/*.png
129127
# Vagrant
130128
.vagrant/
131129

132-
# Configs
133-
etc/genesis_notification/genesis_notification.d/*.conf
134-
130+
# GC build
131+
output/

genesis/images/install.sh

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ set -o pipefail
2424
GC_PATH="/opt/genesis_notification"
2525
GC_CFG_DIR=/etc/genesis_notification
2626
VENV_PATH="$GC_PATH/.venv"
27-
BOOTSTRAP_PATH="/var/lib/genesis/bootstrap/scripts"
2827

2928
GC_PG_USER="genesis_notification"
3029
GC_PG_PASS="pass"
@@ -38,6 +37,8 @@ sudo apt dist-upgrade -y
3837
sudo apt install -y \
3938
postgresql \
4039
libev-dev
40+
curl -LsSf https://releases.astral.sh/github/uv/releases/download/0.10.12/uv-installer.sh | sh
41+
source "$HOME"/.local/bin/env
4142

4243
# Default creds for genesis notification services
4344
sudo -u postgres psql -c "CREATE ROLE $GC_PG_USER WITH LOGIN PASSWORD '$GC_PG_PASS';"
@@ -48,12 +49,9 @@ sudo mkdir -p $GC_CFG_DIR
4849
sudo cp "$GC_PATH/etc/genesis_notification/genesis_notification.conf" $GC_CFG_DIR/
4950
sudo cp "$GC_PATH/etc/genesis_notification/logging.yaml" $GC_CFG_DIR/
5051

51-
mkdir -p "$VENV_PATH"
52-
python3 -m venv "$VENV_PATH"
52+
cd "$GC_PATH"
53+
uv sync
5354
source "$GC_PATH"/.venv/bin/activate
54-
pip install pip --upgrade
55-
pip install -r "$GC_PATH"/requirements.txt
56-
pip install -e "$GC_PATH"
5755

5856
# Apply migrations
5957
ra-apply-migration --config-dir "$GC_PATH/etc/genesis_notification/" --path "$GC_PATH/migrations"

genesis_notification/clients/iam.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020

2121
class IAMClient(common.RESTClientMixIn):
22-
2322
USER_PATH = "iam/users"
2423

2524
def __init__(self, endpoint, token, timeout=5):

genesis_notification/cmd/user_api.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ def main():
8585
)
8686

8787
service.add_setup(
88-
lambda: engines.engine_factory.configure_postgresql_factory(
89-
conf=CONF
90-
)
88+
lambda: engines.engine_factory.configure_postgresql_factory(conf=CONF)
9189
)
9290

9391
service_hub.add_service(service)

genesis_notification/dm/models.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def calulator():
4747

4848

4949
class ModelWithAlwaysActiveStatus(models.Model):
50-
5150
STATUS = c.AlwaysActiveStatus
5251

5352
status = properties.property(
@@ -195,7 +194,6 @@ class EventType(
195194

196195

197196
class AbstractContent(types_dynamic.AbstractKindModel):
198-
199197
def get_id(self):
200198
return "%s" % self.__class__.__name__.lower()
201199

@@ -219,9 +217,7 @@ class EmailContent(RenderedEmailContent):
219217
def render(self, params):
220218
return RenderedEmailContent(
221219
title=jinja2.Template(self.title).render(**params),
222-
bodies=[
223-
jinja2.Template(body).render(**params) for body in self.bodies
224-
],
220+
bodies=[jinja2.Template(body).render(**params) for body in self.bodies],
225221
)
226222

227223

@@ -270,9 +266,7 @@ class RenderedDirectMessageContent(AbstractContent):
270266
KIND = "rendered_zulip_direct_message"
271267

272268
to = properties.property(
273-
types.TypedList(
274-
nested_type=types.String(min_length=1, max_length=256)
275-
),
269+
types.TypedList(nested_type=types.String(min_length=1, max_length=256)),
276270
required=True,
277271
)
278272
content = properties.property(
@@ -297,9 +291,7 @@ def render(self, params):
297291
return RenderedDirectMessageContent(
298292
to=[
299293
user.strip()
300-
for user in jinja2.Template(self.to)
301-
.render(**params)
302-
.split(",")
294+
for user in jinja2.Template(self.to).render(**params).split(",")
303295
],
304296
content=jinja2.Template(self.content).render(**params),
305297
)
@@ -404,7 +396,6 @@ class Binding(
404396

405397

406398
class StatusMixin(models.Model):
407-
408399
next_retry_delta = 60 # 60 sec
409400
last_retry_delta = 1 * 24 * 60 * 60 # 1 day
410401

@@ -433,9 +424,7 @@ class StatusMixin(models.Model):
433424

434425
def reset_next_retry(self):
435426
now = datetime.datetime.now(datetime.timezone.utc)
436-
self.next_retry_at = now + datetime.timedelta(
437-
seconds=self.next_retry_delta
438-
)
427+
self.next_retry_at = now + datetime.timedelta(seconds=self.next_retry_delta)
439428

440429
def set_error_status(self, error_message):
441430
self.status_description = str(error_message)

genesis_notification/services/builders/agents.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929

3030
class EventBuilderAgent(basic.BasicService):
31-
3231
def __init__(self, iam_client, butch_size=100, **kwargs):
3332
self._iam_client = iam_client
3433
self._butch_size = butch_size

genesis_notification/services/providers/agents.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929

3030
class SMTPAgent(basic.BasicService):
31-
3231
def __init__(self, butch_size=100, iter_min_period=5, **kwargs):
3332
self._butch_size = butch_size
3433
super().__init__(iter_min_period=iter_min_period, **kwargs)

0 commit comments

Comments
 (0)