Skip to content

Commit 4481264

Browse files
committed
Refactor deployment checks and update dependencies
- Refactor `wait_for_deploy` to accept `expected_version` argument - Update callers in `bot.py` to pass the version. - Update tests in `wait_for_deploy_test.py` and `bot_test.py`. - Replace deprecated `pkg_resources` with `packaging` for version parsing. - Improve Python package publishing in `publish.py`: - Use `python -m build .` for building sdist and wheel. - Use `check_call` to ensure build errors are raised. - Fix virtual environment handling to ensure `build` module is found. - Update GitHub Actions CI workflow to use `uv` instead of `pip`. - Address various Pylint errors in `publish.py` and `wait_for_deploy.py`.
1 parent 093b4d7 commit 4481264

File tree

11 files changed

+620
-72
lines changed

11 files changed

+620
-72
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,28 @@ name: CI
22
on: [push]
33
jobs:
44
python-tests:
5-
runs-on: ubuntu-20.04
5+
runs-on: ubuntu-latest
66

77
steps:
88
- uses: actions/checkout@v2
99

1010
- name: Set up JS requirements
1111
run: npm install
1212

13-
- name: Set up Python
14-
uses: actions/setup-python@v2
15-
with:
16-
python-version: "3.9"
13+
- name: Install uv
14+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
1715

18-
- id: cache
19-
uses: actions/cache@v1
20-
with:
21-
path: ~/.cache/pip
22-
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/test_requirements.txt') }}
23-
restore-keys: |
24-
${{ runner.os }}-pip-
25-
26-
- name: Install dependencies
27-
run: pip install -r requirements.txt -r test_requirements.txt
16+
- name: Install Python dependencies with uv
17+
run: uv sync --locked
2818

2919
- name: Lint
30-
run: pylint *.py
20+
run: uv run pylint *.py
3121

3222
- name: Black
33-
run: black --version && black . --check
23+
run: uv run black --version && uv run black . --check
3424

3525
- name: Tests
36-
run: pytest . && coverage xml
26+
run: uv run pytest . && uv run coverage xml
3727

3828
# - name: Upload coverage to CodeCov
3929
# uses: codecov/codecov-action@v1

bot_test.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ async def test_release(
443443
repo_url=test_repo.repo_url,
444444
hash_url=test_repo.rc_hash_url,
445445
watch_branch="release-candidate",
446+
expected_version=pr.version,
446447
timeout_seconds=3600,
447448
)
448449
assert doof.said("Now deploying to RC...")
@@ -518,6 +519,7 @@ async def test_hotfix_release(
518519
repo_url=test_repo.repo_url,
519520
hash_url=test_repo.rc_hash_url,
520521
watch_branch="release-candidate",
522+
expected_version=pr.version,
521523
timeout_seconds=3600,
522524
)
523525
assert doof.said("Now deploying to RC...")
@@ -1216,6 +1218,7 @@ async def test_wait_for_deploy_rc(
12161218
repo_url=test_repo.repo_url,
12171219
hash_url=test_repo.rc_hash_url,
12181220
watch_branch="release-candidate",
1221+
expected_version=release_pr.version,
12191222
timeout_seconds=3600,
12201223
)
12211224
get_unchecked.assert_called_once_with(
@@ -1236,26 +1239,17 @@ async def test_wait_for_deploy_prod(
12361239
): # pylint: disable=unused-argument
12371240
"""Bot._wait_for_deploy_prod should wait until repo has been deployed to production"""
12381241
wait_for_deploy_mock = mocker.async_patch("bot.wait_for_deploy")
1239-
version = "1.2.345"
1240-
get_version_tag_mock = mocker.async_patch(
1241-
"bot.get_version_tag", return_value=f"v{version}"
1242-
)
12431242
channel_id = test_repo.channel_id
12441243
release_pr = ReleasePR(
1245-
"version", "https://github.com/org/repo/pulls/123456", "body", 123456, False
1244+
"1.2.345", "https://github.com/org/repo/pulls/123456", "body", 123456, False
12461245
)
12471246

12481247
await doof._wait_for_deploy_prod( # pylint: disable=protected-access
12491248
repo_info=test_repo, manager="me", release_pr=release_pr
12501249
)
12511250

1252-
get_version_tag_mock.assert_called_once_with(
1253-
github_access_token=GITHUB_ACCESS,
1254-
repo_url=test_repo.repo_url,
1255-
commit_hash="origin/release",
1256-
)
12571251
assert doof.said(
1258-
f"My evil scheme v{version} for {test_repo.name} has been released "
1252+
f"My evil scheme {release_pr.version} for {test_repo.name} has been released " # Use release_pr.version
12591253
f"to production at {remove_path_from_url(test_repo.prod_hash_url)}. "
12601254
"And by 'released', I mean completely...um...leased.",
12611255
channel_id=channel_id,
@@ -1265,6 +1259,7 @@ async def test_wait_for_deploy_prod(
12651259
repo_url=test_repo.repo_url,
12661260
hash_url=test_repo.prod_hash_url,
12671261
watch_branch="release",
1262+
expected_version=release_pr.version, # Pass expected_version from PR
12681263
timeout_seconds=3600,
12691264
)
12701265

publish.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from pathlib import Path
44

55
from async_subprocess import (
6-
call,
76
check_call,
87
)
98
from constants import (
@@ -27,13 +26,6 @@ async def upload_to_pypi(project_dir):
2726
# Heroku has both Python 2 and 3 installed but the system libraries aren't configured for our use,
2827
# so make a virtualenv.
2928
async with virtualenv("python3", outer_environ) as (virtualenv_dir, environ):
30-
# Use the virtualenv binaries to act within that environment
31-
pip_path = os.path.join(virtualenv_dir, "bin", "pip")
32-
33-
# Install dependencies. wheel is needed for Python 2. twine uploads the package.
34-
await check_call(
35-
[pip_path, "install", "twine"], env=environ, cwd=project_dir
36-
)
3729
await upload_with_twine(
3830
project_dir=project_dir, virtualenv_dir=virtualenv_dir, environ=environ
3931
)
@@ -55,13 +47,24 @@ async def upload_with_twine(
5547
"TWINE_USERNAME": os.environ["PYPI_USERNAME"],
5648
"TWINE_PASSWORD": os.environ["PYPI_PASSWORD"],
5749
}
58-
50+
# Use the virtualenv binaries to act within that environment
51+
pip_path = os.path.join(virtualenv_dir, "bin", "pip")
5952
python_path = os.path.join(virtualenv_dir, "bin", "python")
53+
# Install dependencies. wheel is needed for Python 2. twine uploads the package.
54+
await check_call(
55+
[pip_path, "install", "setuptools"], env=environ, cwd=project_dir
56+
)
57+
await check_call(
58+
[pip_path, "install", "build"], env=environ, cwd=project_dir
59+
)
60+
await check_call(
61+
[pip_path, "install", "twine"], env=environ, cwd=project_dir
62+
)
6063
twine_path = os.path.join(virtualenv_dir, "bin", "twine")
6164

62-
# Create source distribution and wheel.
63-
await call([python_path, "setup.py", "sdist"], env=environ, cwd=project_dir)
64-
await call([python_path, "setup.py", "bdist_wheel"], env=environ, cwd=project_dir)
65+
# Create source distribution and wheel using the virtualenv's python executable
66+
# and explicitly passing the virtualenv's environment.
67+
await check_call([python_path, "-m", "build", "."], env=environ, cwd=project_dir)
6568
dist_files = os.listdir(os.path.join(project_dir, "dist"))
6669
if len(dist_files) != 2:
6770
raise Exception("Expected to find one tarball and one wheel in directory")

publish_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _call(command, *args, **kwargs):
5454
virtualenv_dir=virtualenv_dir,
5555
environ=environ,
5656
)
57-
assert call_mock.call_count == 1
57+
assert call_mock.call_count == 5
5858

5959

6060
async def test_upload_to_npm(mocker, test_repo_directory, library_test_repo):

pyproject.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[project]
2+
name = "doof"
3+
requires-python = "~=3.13"
4+
version = "0.0.1"
5+
dependencies = [
6+
"python-dateutil",
7+
"pytz",
8+
"requests",
9+
"sentry-sdk",
10+
"setuptools>=78.1.0",
11+
"tornado",
12+
"virtualenv",
13+
]
14+
15+
[dependency-groups]
16+
dev = [
17+
"black==22.3.0",
18+
"codecov",
19+
"pdbpp",
20+
"pylint",
21+
"pytest",
22+
"pytest-asyncio",
23+
"pytest-cov",
24+
"pytest-mock",
25+
]
26+
27+
[tool.uv]
28+
package = false

release.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
from subprocess import CalledProcessError
66

7-
from pkg_resources import parse_version
7+
from packaging.version import parse as parse_version
88

99
from async_subprocess import (
1010
call,

requirements.txt

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

test_requirements.txt

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

0 commit comments

Comments
 (0)