Skip to content

Commit

Permalink
Convert to astral based tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
delfick committed Oct 12, 2024
1 parent 34493bb commit 406bd38
Show file tree
Hide file tree
Showing 28 changed files with 695 additions and 349 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@ jobs:
- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install deps
shell: bash
env:
VENVSTARTER_ONLY_MAKE_VENV: "1"
run: |
python ./tools/venv
- name: Install venv
run: ./tools/uv sync --extra tools --locked

- name: Run tests
shell: bash
run: ./test.sh -v
run: ./tools/ci tests -v
20 changes: 8 additions & 12 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@ jobs:
with:
python-version: "3.12"

- name: Install deps
shell: bash
env:
VENVSTARTER_ONLY_MAKE_VENV: "1"
run: python ./tools/venv
- name: Install venv
run: ./tools/uv sync --extra tools --locked

- name: Ensure linter is happy
run: ./lint
run: ./tools/ci lint

format:
runs-on: ubuntu-latest
Expand All @@ -42,15 +39,14 @@ jobs:
with:
python-version: "3.12"

- name: Install deps
shell: bash
env:
VENVSTARTER_ONLY_MAKE_VENV: "1"
run: python ./tools/venv
- name: Install venv
run: ./tools/uv sync --extra tools --locked

- name: Ensure code is formatted
run: |
./format
./tools/ci format
git status --porcelain
# Complain if there were changes
if [[ ! -z "$(git status --porcelain)" ]]; then
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:

name: Release Packages

permissions:
contents: write

jobs:
build:
name: Create the package
Expand All @@ -16,7 +19,7 @@ jobs:
python-version: "3.12"

- id: build
run: pip install hatch==1.6.3 && hatch build
run: uv build

- id: version
run: |
Expand All @@ -27,12 +30,11 @@ jobs:
echo "versiondash=$versiondash" >> $GITHUB_OUTPUT
- id: create-release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
name: alt_pytest_asyncio ${{ steps.version.outputs.version }}
body: "https://github.com/delfick/python-alt_pytest_asyncio#release-${{ steps.version.outputs.versiondash }}"
tag_name: "release-${{ steps.version.outputs.version }}"
token: ${{ secrets.GITHUB_TOKEN }}
fail_on_unmatched_files: true
draft: false
prerelease: false
Expand Down
3 changes: 1 addition & 2 deletions alt_pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def pytest_pyfunc_call(self, pyfuncitem):
partial(converted_async_test, self.ctx, self.test_tasks, o, timeout)
)
else:

original = pyfuncitem.obj

@wraps(original)
Expand Down Expand Up @@ -158,7 +157,7 @@ async def runner():
exc_type = type(exc)
tb = exc.__traceback__
info = ExceptionInfo((exc_type, exc, tb), "")
print(info.getrepr(style="short"))
print(info.getrepr(style="short")) # noqa: T201
sys.exit(1)
finally:
cancel_all_tasks(loop, ignore_errors_from_tasks=[task])
Expand Down
77 changes: 77 additions & 0 deletions dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

# https://stackoverflow.com/questions/2683279/how-to-detect-if-a-script-is-being-sourced
sourced=0
if [ -n "$ZSH_VERSION" ]; then
case $ZSH_EVAL_CONTEXT in *:file) sourced=1;; esac
elif [ -n "$KSH_VERSION" ]; then
# shellcheck disable=SC2296
[ "$(cd -- "$(dirname -- "$0")" && pwd -P)/$(basename -- "$0")" != "$(cd -- "$(dirname -- "${.sh.file}")" && pwd -P)/$(basename -- "${.sh.file}")" ] && sourced=1
elif [ -n "$BASH_VERSION" ]; then
(return 0 2>/dev/null) && sourced=1
else
# All other shells: examine $0 for known shell binary filenames.
# Detects `sh` and `dash`; add additional shell filenames as needed.
case ${0##*/} in sh|-sh|dash|-dash)
if [ -z "$PROJECT_ROOT" ]; then
echo "POSIX environments need PROJECT_ROOT in the environment for 'source run.sh activate' to work"
echo "This must be set to the root of this repository"
return 1
fi
;;
esac
fi

# Bash does not make it easy to find where this file is
# Here I'm making it so it doesn't matter what directory you are in
# when you execute this script. And it doesn't matter whether you're
# executing a symlink to this script
# Note the `-h` in the while loop asks if this path is a symlink
pushd . >'/dev/null'
DIRECTORY_BEFORE="$(pwd)"
SCRIPT_PATH="${BASH_SOURCE[0]:-$0}"

find_here() {
while [ -h "$SCRIPT_PATH" ]; do
cd "$(dirname -- "$SCRIPT_PATH")" || return 1
SCRIPT_PATH="$(readlink -f -- "$SCRIPT_PATH")"
done
cd "$(dirname -- "$SCRIPT_PATH")" >'/dev/null' || return 1
}

if ! find_here; then
if [ "$sourced" = "1" ]; then
return 1
else
exit 1
fi
fi

PROJECT_ROOT=$(pwd)
export PROJECT_ROOT

if ! ./tools/uv sync --locked -q; then
if [ "$sourced" = "1" ]; then
return 1
else
exit 1
fi
fi

if [ -f ./tools/requirements.local.txt ]; then
if ! ./tools/uv pip install -q -r ./tools/requirements.local.txt; then
if [ "$sourced" = "1" ]; then
return 1
else
exit 1
fi
fi
fi

if [ "$sourced" = "1" ]; then
# shellcheck source=/dev/null
source .venv/bin/activate
cd "$DIRECTORY_BEFORE" || return 1
else
exec uv run ./tools/run.py "$@"
fi
23 changes: 12 additions & 11 deletions find
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/bash

set -e

# Helper for searching code base without searching through external code

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

(
cd $DIR
exec ack "$@" \
--ignore-directory .tox \
--ignore-directory .mypy_cache \
--ignore-directory dist \
--ignore-directory build \
--ignore-directory tools \
)
cd "$(git rev-parse --show-toplevel)"

exec ack "$@" \
--ignore-directory .tox \
--ignore-directory .mypy_cache \
--ignore-directory .dmypy.json \
--ignore-directory dist \
--ignore-directory build \
--ignore-directory "*.egg-info" \
--ignore-directory tools
2 changes: 1 addition & 1 deletion format
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e

cd "$(git rev-parse --show-toplevel)"

./tools/venv format "$@"
exec ./dev format "$@"
Empty file.
1 change: 1 addition & 0 deletions helpers/alt_pytest_asyncio_test_driver/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "0.1"
28 changes: 28 additions & 0 deletions helpers/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "alt-pytest-asyncio-test-driver"
dynamic = ["version"]
license = { text = "MIT" }
authors = [
{ name = "Stephen Moore", email = "stephen@delfick.com" },
]
dependencies = [
"nest-asyncio==1.6.0",
"noseOfYeti[black]==2.4.9",
"pytest==8.2.1",
"pytest-order==1.2.1"
]

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.version]
path = "alt_pytest_asyncio_test_driver/version.py"

[tool.hatch.build.targets.wheel]
include = [
"/alt_pytest_asyncio_test_driver",
]
2 changes: 1 addition & 1 deletion lint
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e

cd "$(git rev-parse --show-toplevel)"

exec ./tools/venv lint "$@"
exec ./dev lint "$@"
17 changes: 0 additions & 17 deletions pylama.ini

This file was deleted.

65 changes: 39 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,58 @@ dependencies = [
"pytest >= 8.0.0",
]

[project.optional-dependencies]
tests = [
"nest-asyncio==1.6.0",
"noseOfYeti[black]==2.4.9",
"pytest==8.2.1",
"pytest-order==1.2.1"
]

[project.entry-points.pytest11]
alt_pytest_asyncio = "alt_pytest_asyncio"

[project.urls]
Homepage = "https://github.com/delfick/alt-pytest-asyncio"

[tool.uv]
dev-dependencies = [
"tools",
"alt_pytest_asyncio_test_driver",
]

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.version]
path = "alt_pytest_asyncio/version.py"

[tool.hatch.build.targets.wheel]
include = [
"/alt_pytest_asyncio",
]

[tool.hatch.build.targets.sdist]
include = [
"/alt_pytest_asyncio",
]

[tool.black]
line-length = 100
include = '\.py$'
exclude = '''
/(
\.git
| \.tox
| dist
| tools/\.python
)/
'''
[tool.uv.sources]
tools = { workspace = true }
alt_pytest_asyncio_test_driver = { workspace = true }

[tool.uv.workspace]
members = ["tools", "helpers"]

[tool.ruff]
target-version = "py311"
line-length = 99
extend-exclude = [
".DS_Store",
"tools/.bootstrap-venv",
"tests",
"__pycache__",
]

[tool.isort]
profile = "black"
skip_glob = [
".git/*",
".tox/*",
"dist/*",
"tools/.*",
[tool.ruff.lint]
select = [
"B008", # mutable objects as function argument defaults
"B015", # flake8-bugbear (useless-comparison)
"I", # isort
"T20", # flake8-print
"UP", # pyupgrade
"RUF",
"F",
]
Loading

0 comments on commit 406bd38

Please sign in to comment.