Skip to content

Commit

Permalink
chore: migrate to hatch and update to latest Austin
Browse files Browse the repository at this point in the history
We migrate the build backend to hatch and add support for the
latest version of the Austin binary.
  • Loading branch information
P403n1x87 committed Feb 18, 2024
1 parent a581dbd commit 2d7077a
Show file tree
Hide file tree
Showing 18 changed files with 379 additions and 1,244 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Checks

on:
push:
branches:
- main
pull_request:

jobs:
typing:
runs-on: "ubuntu-latest"

name: Type checking
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v4
with:
python-version: "3.10"

- run: |
pip install hatch
hatch -e checks run typing
linting:
runs-on: "ubuntu-latest"

name: Linting
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v4
with:
python-version: "3.10"

- run: |
pip install hatch
hatch -e checks run linting
20 changes: 11 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
name: Release

on:
release:
types: [published]

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
architecture: x64
- uses: actions/checkout@v2

- uses: actions/setup-python@v4
with:
python-version: '3.10'

- run: |
pip install poetry poetry-dynamic-versioning
poetry build
poetry publish --username=__token__ --password=${{ secrets.PYPI_TOKEN }}
- run: |
pip install hatch hatch-vcs
hatch build
hatch publish --user=__token__ --auth=${{ secrets.PYPI_TOKEN }}
132 changes: 77 additions & 55 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,98 @@
name: Tests
on: push

on:
push:
branches:
- main
pull_request:

concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
tests:
runs-on: ${{ matrix.os }}
tests-linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest] # windows-latest
name: Tests on ${{ matrix.os }}
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

name: Tests with Python ${{ matrix.python-version }} on Linux
steps:
- uses: actions/checkout@v2
with:
path: main
- uses: actions/checkout@v3

- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: '3.x'
architecture: x64
python-version: ${{ matrix.python-version }}-dev

- name: Checkout Austin development branch
uses: actions/checkout@master
with:
repository: P403n1x87/austin
ref: devel
path: austin
- name: Install dependencies
run: |
pip install hatch
- name: Compile Austin on Linux
- name: Run tests
timeout-minutes: 10
run: |
hatch run tests.py${{ matrix.python-version }}:tests -svv
- name: Publish coverage metrics
run: |
cd $GITHUB_WORKSPACE/austin
gcc -Wall -O3 -Os -s -pthread src/*.c -o src/austin
if: startsWith(matrix.os, 'ubuntu')
cd $GITHUB_WORKSPACE/main
hatch run coverage:cov
hatch run coverage:codecov
if: matrix.python-version == '3.10'
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}

# - name: Compile Austin on Windows
# run: |
# cd $env:GITHUB_WORKSPACE/austin
# gcc.exe -O3 -o src/austin.exe src/*.c -lpsapi -Wall -Os -s
# if: startsWith(matrix.os, 'windows')
tests-macos:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

- name: Compile Austin on macOS
run: |
cd $GITHUB_WORKSPACE/austin
gcc -Wall -O3 -Os src/*.c -o src/austin
if: startsWith(matrix.os, 'macos')
name: Tests with Python ${{ matrix.python-version }} on MacOS
steps:
- uses: actions/checkout@v3

- run: pip install nox==2020.5.24
- run: pip install poetry==1.0.5
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}-dev

- name: Run nox on Linux
- name: Remove signature from the Python binary
run: |
cd $GITHUB_WORKSPACE/main
export PATH="$GITHUB_WORKSPACE/austin/src:$PATH"
nox
if: "startsWith(matrix.os, 'ubuntu')"
codesign --remove-signature /Library/Frameworks/Python.framework/Versions/${{ matrix.python-version }}/bin/python3 || true
codesign --remove-signature /Library/Frameworks/Python.framework/Versions/${{ matrix.python-version }}/Resources/Python.app/Contents/MacOS/Python || true
- name: Run nox on macOS
- name: Install dependencies
run: |
cd $GITHUB_WORKSPACE/main
export PATH="$GITHUB_WORKSPACE/austin/src:$PATH"
sudo nox
if: startsWith(matrix.os, 'macos')
pip install hatch
# - name: Run nox on Windows
# run: |
# cd $env:GITHUB_WORKSPACE/main
# $env:PATH="$env:GITHUB_WORKSPACE/austin/src;$env:PATH"
# nox
# if: "startsWith(matrix.os, 'windows')"
- name: Run tests
timeout-minutes: 10
run: |
sudo hatch run tests.py${{ matrix.python-version }}:tests -svv
- name: Publish coverage metrics
tests-win:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

name: Tests with Python ${{ matrix.python-version }} on Windows
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}-dev

- name: Install dependencies
run: |
cd $GITHUB_WORKSPACE/main
nox -rs coverage
if: startsWith(matrix.os, 'ubuntu')
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
pip install hatch
- name: Run tests
timeout-minutes: 10
run: |
hatch run tests.py${{ matrix.python-version }}:tests -svv
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

49 changes: 34 additions & 15 deletions austin_web/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,30 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import asyncio
from enum import Enum
import json
import sys
from typing import Any, List, Optional, Type
import weakref
from enum import Enum
from typing import Any
from typing import List
from typing import Optional
from typing import Type

from aiohttp import web
from aiohttp.test_utils import unused_port
from austin import AustinError, AustinTerminated
from austin import AustinError
from austin import AustinTerminated
from austin.aio import AsyncAustin
from austin.cli import AustinArgumentParser, AustinCommandLineError
from austin_web.data import DataPool, WebFrame
from austin_web.html import load_compile, load_site
from austin.cli import AustinArgumentParser
from austin.cli import AustinCommandLineError
from halo import Halo
from pyfiglet import Figlet

from austin_web.data import DataPool
from austin_web.data import WebFrame
from austin_web.html import load_compile
from austin_web.html import load_site


if sys.platform == "win32":
asyncio.set_event_loop(asyncio.ProactorEventLoop())
Expand Down Expand Up @@ -127,13 +135,21 @@ def on_sample_received(self, text: str) -> None:
if self._mode == AustinWebMode.SERVE:
if not self._pools:
return
frame = WebFrame.parse(text)
try:
frame = WebFrame.parse(text)
except Exception:
# TODO: log exception
return
for data_pool in self._pools:
data_pool.add(frame)
else:
if not self._pool:
raise AustinWebError("Data pool is unexpectedly missing")
self._pool.add(WebFrame.parse(text))
try:
self._pool.add(WebFrame.parse(text))
except Exception:
# TODO: log exception
return

def on_terminate(self, stats: str) -> None:
"""Austin terminate callback."""
Expand Down Expand Up @@ -226,7 +242,9 @@ async def start_server(self) -> None:
f"⏲️ Sampling process with PID {self.get_process().pid} "
f"({self.get_command_line()})"
)
print(f"🏃 Austin Web is running on http://{host}:{port}. Press Ctrl+C to stop.")
print(
f"🏃 Austin Web is running on http://{host}:{port}. Press Ctrl+C to stop."
)

async def stop_server(self) -> None:
"""Stop the web server asynchronously."""
Expand All @@ -241,7 +259,7 @@ async def start(self, args: List[str]) -> None:
pass
except AustinError as e:
asyncio.get_event_loop().stop()
raise e
print(f"austin-web: {e}")

def run(self) -> None:
"""Run Austin Web."""
Expand All @@ -253,7 +271,8 @@ def run(self) -> None:

try:
austin_task = loop.create_task(
self.start(AustinWebArgumentParser.to_list(self._args))
self.start(AustinWebArgumentParser.to_list(self._args)),
name="austin-web",
)
loop.run_forever()
if not austin_task.done():
Expand All @@ -262,6 +281,9 @@ def run(self) -> None:
loop.run_until_complete(austin_task)
except asyncio.CancelledError:
pass
exc = austin_task.exception()
if exc:
raise exc
except AustinError as e:
(message,) = e.args
if message[0] == "(":
Expand All @@ -276,10 +298,7 @@ def shutdown(self) -> None:
"""Shutdown Austin Web."""
asyncio.get_event_loop().run_until_complete(self.stop_server())

try:
all_tasks = asyncio.all_tasks # Python 3.7+
except AttributeError:
all_tasks = asyncio.Task.all_tasks # Python 3.6
all_tasks = asyncio.all_tasks

try:
for task in all_tasks():
Expand Down
Loading

0 comments on commit 2d7077a

Please sign in to comment.