Skip to content

Commit

Permalink
chores(wip): build and publish cython
Browse files Browse the repository at this point in the history
  • Loading branch information
raceychan committed Feb 18, 2025
1 parent a81c8ff commit bdd8964
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 170 deletions.
8 changes: 5 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ git-push:
@git push origin master
@git push origin "v$(VERSION)"

hatch-build:
@echo "Building version $(VERSION)..."
@pixi run -e publish hatch build
#hatch-build:
# @echo "Building version $(VERSION)..."
# @pixi run -e publish hatch build
setup-build:
pixi run -e publish python setup.py build_ext --inplace

pypi-release:
pixi run -e publish publish
Expand Down
144 changes: 0 additions & 144 deletions pcss.md

This file was deleted.

7 changes: 1 addition & 6 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ graphviz = ["python-graphviz>=0.20.3,<0.21"]
# ======== Build =========

[build-system]
build-backend = "hatchling.build"
requires = ["hatchling"]
requires = ["setuptools", "cython"]
build-backend = "setuptools.build_meta"

[tool.hatch.version]
path = "ididi/__init__.py"

[tool.hatch.build.targets.wheel.hooks.cython]
dependencies = ["hatch-cython"]

[tool.setuptools]
py-modules = ["ididi"]
Expand Down Expand Up @@ -86,7 +81,6 @@ test = { features = ["test"], solve-group = "default" }
[tool.pixi.dependencies]
python = "3.9.0.*"
typing_extensions = ">=4.12.2,<5"
cython = "==3.0.12"

[tool.pixi.feature.dev.dependencies]
jupyter = ">=1.1.1,<2"
Expand All @@ -102,6 +96,8 @@ pyinstrument = ">=5.0.0,<6"
[tool.pixi.feature.publish.dependencies]
hatch = ">=1.13.0,<2"
twine = ">=6.1"
cython = "==3.0.12"
setuptools = ">=75.8.0,<76"

[tool.pixi.feature.publish.tasks]
# Build into a wheel using hatch
Expand Down
22 changes: 22 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from Cython.Build import cythonize
from setuptools import Extension, setup

# from ididi import VERSION

exts = [
Extension("ididi.graph", ["ididi/*.pyx"]),
Extension("ididi._node", ["ididi/_node.pyd"]),
Extension("ididi._ds", ["ididi/_ds.pyd"]),
]

extensions = cythonize(
exts,
compiler_directives={"language_level": 3, "profile": False},
)


setup(
name="ididi",
version="1.5.0",
ext_modules=extensions,
)
25 changes: 17 additions & 8 deletions tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_create_root():
start = perf_counter()

for _ in range(n):
root_service = create_root_service()
_ = create_root_service()
end = perf_counter()

menual = round((end - start), 6)
Expand All @@ -229,6 +229,8 @@ def test_create_root():
for c in classes.values():
dg.node(c, reuse=False)

dg.analyze_nodes()

start = perf_counter()
for _ in range(n):
dg.resolve(RootService)
Expand All @@ -237,17 +239,20 @@ def test_create_root():

print(f"ididi resolve took {res}")

print(
f"current implementation(without reuse) is {round(res / menual, 6)} times slower"
)
cost = round(res / menual, 6)

if cost > 1:
print(f"current implementation(reuse dependencies) is {cost} times slower")
else:
print(f"current implementation(reuse dependencies) is {1 / cost} times faster")


@pytest.mark.benchmark
def test_create_root_reuse():
n = 1000
start = perf_counter()
for _ in range(n):
root_service = create_root_service_reuse()
_ = create_root_service_reuse()
end = perf_counter()
menual = round(end - start, 6)

Expand All @@ -266,6 +271,7 @@ def test_create_root_reuse():
dg.remove_dependent(RootService)
dg.node(RootService, reuse=False)
assert dg.nodes[RootService].config.reuse is False
dg.analyze_nodes()

start = perf_counter()
for _ in range(n):
Expand All @@ -274,6 +280,9 @@ def test_create_root_reuse():
res = round(end - start, 6)
print(f"ididi resolve {res}")

print(
f"current implementation(reuse dependencies) is {round(res / menual, 6)} times slower"
)
cost = round(res / menual, 6)

if cost > 1:
print(f"current implementation(reuse dependencies) is {cost} times slower")
else:
print(f"current implementation(reuse dependencies) is {1 / cost} times faster")
2 changes: 1 addition & 1 deletion tests/versions/test_v1_4_5.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ def dependency(a: int) -> Ignore[int]:
def main(a: int, b: int, c: Annotated[int, use(dependency)]) -> Ignore[float]:
return a + b + c

dg.resolve(main, a=1, b=2)
assert dg.resolve(main, a=1, b=2) == 4

0 comments on commit bdd8964

Please sign in to comment.