Skip to content

Commit 3687b81

Browse files
committed
[Fix] build: released as extra-http
1 parent c9bab20 commit 3687b81

File tree

3 files changed

+46
-12
lines changed

3 files changed

+46
-12
lines changed

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ SHELL:= bash
22
.SHELLFLAGS:= -eu -o pipefail -c
33
MAKEFLAGS+= --warn-undefined-variables
44
MAKEFLAGS+= --no-builtin-rules
5-
PROJECT:=retro
5+
PROJECT:=extra
6+
PYPY_PROJECT=extra-http
67
VERSION:=$(shell grep version setup.py | cut -d '"' -f2)
78

89
PYTHON=python
@@ -15,12 +16,13 @@ MODULES_PY:=$(filter-out %/__main__,$(filter-out %/__init__,$(SOURCES_PY:$(PATH_
1516
PATH_LOCAL_PY=$(firstword $(shell python -c "import sys,pathlib;sys.stdout.write(' '.join([_ for _ in sys.path if _.startswith(str(pathlib.Path.home()))] ))"))
1617
PATH_LOCAL_BIN=$(HOME)/.local/bin
1718

18-
REQUIRE_PY=flake8 bandit mypy
19+
REQUIRE_PY=flake8 bandit mypy twine
1920
PREP_ALL=$(REQUIRE_PY:%=build/require-py-%.task)
2021
# Commands
21-
BANDIT=python -m bandit
22-
FLAKE8=python -m flake8
23-
MYPY=python -m mypy
22+
BANDIT=$(PYTHON) -m bandit
23+
FLAKE8=$(PYTHON) -m flake8
24+
MYPY=$(PYTHON) -m mypy
25+
TWINE=$(PYTHON) -m twine
2426
MYPYC=mypyc
2527

2628
cmd-check=if ! $$(which $1 &> /dev/null ); then echo "ERR Could not find command $1"; exit 1; fi; $1
@@ -111,11 +113,12 @@ format:
111113
@ruff $(SOURCES_PY)
112114

113115
.PHONY: release
114-
release:
116+
release: $(PREP_ALL)
115117
@git commit -a -m "[Release] $(PROJECT): $(VERSION)"
116118
git tag $(VERSION)
117119
git push --all
118-
$(PYTHON) setup.py clean sdist register upload
120+
$(PYTHON) setup.py clean sdist bdist_wheel
121+
$(TWINE) upload dist/$(PYPI_PROJECT)-$(VERSION)*
119122

120123
.PHONY: install
121124
install:

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ course, [FastAPI](https://fastapi.tiangolo.com/).
5555
Here is `helloworld.py`:
5656

5757
``` python
58+
#!/usr/bin/env uv run --with extra-http
5859
from extra import Service, HTTPRequest, HTTPResponse, on, run
5960

6061
class HelloWorld(Service):

setup.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
from setuptools import setup, find_packages
2-
from mypyc.build import mypycify
32
import os
3+
import sys
4+
5+
VERSION = "1.0.1"
6+
# Try to import mypyc, make it optional
7+
try:
8+
from mypyc.build import mypycify
9+
10+
MYPYC_AVAILABLE = True
11+
except ImportError:
12+
MYPYC_AVAILABLE = False
413

514

615
def readme():
@@ -17,9 +26,30 @@ def list_ext_modules(base_path="src/py/extra"):
1726
return python_files
1827

1928

29+
# Determine if we should use mypyc compilation
30+
USE_MYPYC = MYPYC_AVAILABLE and "--use-mypyc" in sys.argv and "sdist" not in sys.argv
31+
32+
# Remove our custom flag from sys.argv to avoid confusing setuptools
33+
if "--use-mypyc" in sys.argv:
34+
sys.argv.remove("--use-mypyc")
35+
36+
# Prepare ext_modules
37+
ext_modules = []
38+
if USE_MYPYC:
39+
print("=" * 60)
40+
print("MyPyC compilation is enabled.")
41+
print("This may take a few minutes to compile all Python files...")
42+
print("=" * 60)
43+
ext_modules = mypycify(list_ext_modules())
44+
elif MYPYC_AVAILABLE and "sdist" not in sys.argv:
45+
print(
46+
"Note: Use --use-mypyc flag to enable MyPyC compilation for better performance."
47+
)
48+
49+
2050
setup(
21-
name="extra",
22-
version="1.0.0",
51+
name="extra-http",
52+
version=VERSION,
2353
author="Sébastien Pierre",
2454
author_email="sebastien.pierre@gmail.com",
2555
description="A toolkit to write HTTP/1.1 web services and applications, with first class support for streaming",
@@ -66,6 +96,6 @@ def list_ext_modules(base_path="src/py/extra"):
6696
},
6797
include_package_data=True,
6898
zip_safe=False,
69-
# NOTE: mypyc compilation is experimental
70-
ext_modules=mypycify(list_ext_modules()),
99+
# NOTE: mypyc compilation is optional and experimental
100+
ext_modules=ext_modules,
71101
)

0 commit comments

Comments
 (0)