Skip to content

Commit

Permalink
Update build system
Browse files Browse the repository at this point in the history
* Use uv for venvs, build and publish (remove poetry)
* Use ruff for lint and format checks
* Simplify ci and release github pipelines
* Make nox use uv
* Clean nox, clean pyproject
  • Loading branch information
bisho committed Nov 26, 2024
1 parent 2c39568 commit f9609eb
Show file tree
Hide file tree
Showing 9 changed files with 369 additions and 476 deletions.
126 changes: 22 additions & 104 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,113 +1,31 @@
name: Continuous Integration

on:
on:
pull_request:
push:
branches:
- main

jobs:
tests:
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.11']
name: Python ${{ matrix.python-version }}
steps:
- uses: actions/checkout@main
- uses: actions/setup-python@main
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- run: pip install -r dev-requirements.txt
- run: nox -p ${{ matrix.python-version }}

deploy-vnext:
runs-on: ubuntu-latest
needs: tests
if: github.ref == 'refs/heads/main'

env:
NODE_ENV: production

steps:
- uses: actions/checkout@main
- name: Set up Python 3.11
uses: actions/setup-python@main
with:
python-version: '3.11'
architecture: x64
- name: Install dependencies
run: |
pip install -r dev-requirements.txt
poetry install
- name: Generate version
id: pkg-info
run: |
git clone --bare ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} ../metadata
pushd ../metadata
latestTag=$(git rev-list --tags --max-count=1)
firstCommit=$(git rev-list --max-parents=0 HEAD)
build="$(git rev-list --count ${latestTag:=${firstCommit}}..HEAD)"
popd
setupVer=$(grep "version = " pyproject.toml | cut -d' ' -f3 | sed "s/\"//g")
version="${setupVer}-dev${build}"
echo ::set-output name=setup_version::${setupVer}
echo ::set-output name=version::${version}
- name: Prep pyproject.toml for release
env:
SETUP_VERSION: ${{ steps.pkg-info.outputs.setup_version }}
PKG_VERSION: ${{ steps.pkg-info.outputs.version }}
run: |
sed -i "s/version = \"${SETUP_VERSION}\"/version = \"${PKG_VERSION}\"/" ./pyproject.toml
- name: Build library package
run: poetry build

- name: Deploy to pypi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}

deploy-latest:
runs-on: ubuntu-latest
needs: tests
if: startsWith(github.ref, 'refs/tags/v')

env:
NODE_ENV: production
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
- name: Lint
run: uv run nox -s lint
- name: Format check
run: uv run nox -s format

tests:
name: Run tests
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@main
- name: Set up Python 3.11
uses: actions/setup-python@main
with:
python-version: '3.11'
architecture: x64
- name: Install dependencies
run: |
pip install -r dev-requirements.txt
poetry install
- name: Generate version
id: pkg-info
run: |
setupVer=$(grep "version = " pyproject.toml | cut -d' ' -f3 | sed "s/\"//g")
echo ::set-output name=setup_version::${setupVer}
echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
- name: Prep pyproject.toml for release
env:
SETUP_VERSION: ${{ steps.pkg-info.outputs.setup_version }}
PKG_VERSION: ${{ steps.pkg-info.outputs.version }}
run: |
sed -i "s/version = \"${SETUP_VERSION}\"/version = \"${PKG_VERSION}\"/" ./pyproject.toml
- name: Build library package
run: poetry build

- name: Deploy to pypi
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_PASSWORD }}
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
- name: Tests
run: uv run nox -s tests
24 changes: 24 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Release

on:
push:
tags:
# Publish on any tag starting with a `v`, e.g. v1.2.3
- v*

jobs:
pypi:
name: Publish to PyPI
runs-on: ubuntu-latest
# Environment and permissions trusted publishing.
environment:
name: production

permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
- run: uv run nox
- run: uv build
- run: uv publish --token ${{ secrets.PYPI_PASSWORD }}
6 changes: 2 additions & 4 deletions benchmark.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import gc
import threading
import time
import timeit
from typing import Any, Callable, Optional

import click
Expand All @@ -19,7 +18,6 @@
)
from meta_memcache.executors.default import DefaultExecutor
from meta_memcache.interfaces.cache_api import CacheApi
from meta_memcache.protocol import Success
from meta_memcache.routers.default import DefaultRouter
from meta_memcache.serializer import MixedSerializer
from meta_memcache.settings import DEFAULT_MARK_DOWN_PERIOD_S
Expand Down Expand Up @@ -141,12 +139,12 @@ def _build_client(self) -> CacheApi:
def getter(self) -> None:
count = 0
for _ in range(self.runs):
start_time = time.time()
start_time = time.perf_counter()
while True:
self.client.get(f"key{count%200}")
count += 1
if count % self.ops_per_run == 0:
elapsed_time = time.time() - start_time
elapsed_time = time.perf_counter() - start_time
ops_per_sec = self.ops_per_run / elapsed_time
us = elapsed_time / self.ops_per_run * 1_000_000
print(f"Gets: {ops_per_sec:.2f} RPS / {us:.2f} us/req")
Expand Down
2 changes: 0 additions & 2 deletions dev-requirements.txt

This file was deleted.

57 changes: 28 additions & 29 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,58 @@


package = "meta_memcache"
nox.options.sessions = "lint", "types", "tests"
locations = "src", "tests", "noxfile.py"
DEFAULT_VERSION = "3.8"
nox.options.sessions = "lint", "format", "types", "tests"
locations = "src", "tests", "noxfile.py", "benchmark.py"
DEFAULT_VERSION = "3.11"
DEFAULT_BENCHMARK_VERSIONS = ["3.11"]
VERSIONS = ["3.8", "3.11"]
VERSIONS = ["3.12", "3.11", "3.10"]

# Default to uv backend:
nox.options.default_venv_backend = "uv|virtualenv"


@session(python=DEFAULT_VERSION)
def black(session: Session) -> None:
"""Run black code formatter."""
def lint(session: Session) -> None:
"""Lint using ruff."""
args = session.posargs or locations
session.install("ruff", ".")
session.run("ruff", "check", *args)


@session(python=DEFAULT_VERSION)
def format(session: Session) -> None:
"""Format check using ruff."""
args = session.posargs or locations
session.install("black", ".")
session.run("black", *args)
session.install("ruff", ".")
session.run("ruff", "format", "--diff", *args)


@session(python=VERSIONS)
def lint(session: Session) -> None:
"""Lint using flake8."""
@session(python=DEFAULT_VERSION)
def fix_format(session: Session) -> None:
"""Fix format using ruff."""
args = session.posargs or locations
session.install(
"flake8",
"flake8-annotations",
"flake8-bandit",
"flake8-black",
"flake8-bugbear",
"flake8-docstrings",
"bandit",
".",
)
session.run("flake8", *args)
session.install("ruff", ".")
session.run("ruff", "format", *args)


@session(python=DEFAULT_VERSION)
def types(session: Session) -> None:
"""Type-check using mypy."""
session.run("poetry", "install", "--with", "extras", external=True)
session.install("mypy", ".")
# session.run("poetry", "install", "--with", "extras", external=True)
# session.install(".[cicd]") # Install the project and optional dependencies
session.install("mypy", ".[metrics]")
session.run("mypy", "src/")


@session(python=VERSIONS)
def tests(session: Session) -> None:
"""Run the test suite."""
args = session.posargs or ["--cov"]
session.run("poetry", "install", "--with", "extras", external=True)
session.install(
"pytest",
"pytest-cov",
"pytest-mock",
".[metrics]",
)
session.run("pytest", *args, env={"PYTHONHASHSEED": "0"})

Expand All @@ -61,9 +63,6 @@ def tests(session: Session) -> None:
def benchmark(session: Session) -> None:
"""Run the benchmark suite."""
args = session.posargs
session.run("poetry", "install", "--with", "extras", external=True)
session.install(
"click",
)
session.install("click", ".")
session.run("python", "--version")
session.run("python", "benchmark.py", *args)
Loading

0 comments on commit f9609eb

Please sign in to comment.