Skip to content

Commit

Permalink
build: clean up build.py a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Aug 7, 2024
1 parent 49549bf commit c7af6a5
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import shutil
import sys
from pathlib import Path

# setuptools *must* come before Cython, otherwise Cython's distutils hacking
Expand All @@ -15,34 +16,24 @@
BUILD_DIR = Path("cython_build")


extensions = [
Extension("koerce.builders", ["koerce/builders.py"]),
Extension("koerce.patterns", ["koerce/patterns.py"]),
]

cythonized_modules = cythonize(
[
Extension(
"koerce.builders",
["koerce/builders.py"],
),
Extension(
"koerce.patterns",
["koerce/patterns.py"],
),
],
extensions,
build_dir=BUILD_DIR,
# generate anannotated .html output files.
annotate=True,
# nthreads=multiprocessing.cpu_count() * 2,
nthreads=min(os.cpu_count(), len(extensions)),
compiler_directives={
"language_level": "3",
"binding": False,
"boundscheck": False,
"nonecheck": False,
"always_allow_keywords": False,
# "wraparound": False,
# "profile": True,
# "annotation_typing": False
},
# always rebuild, even if files untouched
force=True,
# emit_linenums=True
)

dist = Distribution({"ext_modules": cythonized_modules})
Expand All @@ -53,10 +44,10 @@
# remove all binaries *.so, *.dll, *.lib, *.pyd, *.dylib
for ext in ["so", "dll", "lib", "pyd", "dylib"]:
for f in SOURCE_DIR.glob(f"*.{ext}"):
print(f"Removing previously built binary {f}") # noqa: T201
f.unlink()
print(f"removed {f!r}", file=sys.stderr) # noqa: T201

for output in cmd.get_outputs():
relative_extension = os.path.relpath(output, cmd.build_lib)
print(f"Copying {output} to {relative_extension}") # noqa: T201
print(f"{output} -> {relative_extension}", file=sys.stderr) # noqa: T201
shutil.copyfile(output, relative_extension)

0 comments on commit c7af6a5

Please sign in to comment.