-
-
Notifications
You must be signed in to change notification settings - Fork 50
feat: cythonise all sources #176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
P403n1x87
wants to merge
16
commits into
MatthieuDartiailh:main
Choose a base branch
from
P403n1x87:cythonize
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
217b80c
Cythonise all sources
P403n1x87 0536524
work around Cython bug
P403n1x87 5fe8344
add wheel builds
P403n1x87 7347a23
Merge branch 'main' into cythonize
MatthieuDartiailh c85d324
test both cythonised and pure-Python
P403n1x87 c2191a3
add benchmarks
P403n1x87 d02b85c
fix linting
P403n1x87 603784c
Merge branch 'main' into cythonize
P403n1x87 e81eb29
Merge branch 'main' into cythonize
P403n1x87 c979e50
perf: declare cdef extension types for hot classes via .pxd files
P403n1x87 2fc7441
add explicit arg.deleter raising AttributeError for cdef class compat
P403n1x87 c8c2132
address review comments
P403n1x87 a9eda77
fix typing
P403n1x87 3076a77
salvage immutability
P403n1x87 4fbc698
use isinstance check
P403n1x87 127d6eb
Merge branch 'main' into cythonize
MatthieuDartiailh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,3 +21,5 @@ coverage.xml | |
| .pytest_cache | ||
| .cache | ||
| .venv | ||
| *.c | ||
| *.so | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import os | ||
|
|
||
| from setuptools import setup # isort: skip | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import Cython.Distutils | ||
| from Cython.Build import cythonize # noqa: I100 | ||
|
|
||
| ROOT = Path(__file__).parent / "src" | ||
|
|
||
|
|
||
| # Get all the py files under the src folder | ||
| def get_py_files(path): | ||
| return [ | ||
| p.relative_to(ROOT) for p in Path(path).rglob("*.py") if p.name != "__init__.py" | ||
| ] | ||
|
|
||
|
|
||
| def pretend_cython(): | ||
| return [ | ||
| Cython.Distutils.Extension( | ||
| str(p.with_suffix("")).replace(os.sep, "."), | ||
| sources=[str(Path("src") / p)], | ||
| language="c", | ||
| ) | ||
| for p in get_py_files(ROOT) | ||
| ] | ||
|
|
||
|
|
||
| _pure_python = os.getenv("BYTECODE_PURE_PYTHON") | ||
| print(f"bytecode: building {'pure-Python' if _pure_python else 'Cython'} version") | ||
|
|
||
| # Include .pxd declaration files only in Cython builds so they are available | ||
| # to downstream Cython users who want to cimport from bytecode. | ||
| _package_data = {} if _pure_python else {"bytecode": ["*.pxd"]} | ||
|
|
||
| setup( | ||
| name="bytecode", | ||
| setup_requires=["setuptools_scm[toml]>=4", "cython"] + ([] if _pure_python else ["cmake>=3.24.2,<3.28"]), | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is cmake required ? |
||
| package_data=_package_data, | ||
| ext_modules=[] if _pure_python else cythonize( | ||
| pretend_cython(), | ||
| force=True, | ||
| compiler_directives={ | ||
| "language_level": "3", | ||
| "annotation_typing": False, | ||
| }, | ||
| ), | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from bytecode.instr cimport BaseInstr | ||
|
|
||
| cdef class ConcreteInstr(BaseInstr): | ||
| cdef public object _extended_args | ||
| cdef public int _size |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| cdef class InstrLocation: | ||
| # Must be `object` (not `int`) because these fields are Optional[int] and can be None. | ||
| cdef readonly object lineno | ||
| cdef readonly object end_lineno | ||
| cdef readonly object col_offset | ||
| cdef readonly object end_col_offset | ||
|
|
||
| cdef class BaseInstr: | ||
| cdef public str _name | ||
| cdef public object _location | ||
| cdef public int _opcode | ||
| cdef public object _arg | ||
|
|
||
| cdef class Instr(BaseInstr): | ||
| pass |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not dealt with that in a long time but since you specify files manually we may need to add .pyi now.