Skip to content

Commit 538c021

Browse files
timosachsenbergclaudeCopilot
authored
only use std shared ptr (#201)
* update install instructions * Update TODO for current roadmap * Migrate to Cython 3 only * Remove workflow file changes * Drop Boost smart_ptr and use std::shared_ptr * Remove legacy shared_ptr and include_boost API parameters Now that autowrap uses std::shared_ptr exclusively: - Remove shared_ptr parameter from CodeGenerator.__init__ and generate_code() - Remove include_boost parameter from generate_code(), parse_and_generate_code(), and Main.create_wrapper_code() - Simplify fixed_include_dirs() and get_include_dirs() to take no arguments - Remove include_shared_ptr attribute from CodeGenerator 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Replace boost::shared_ptr with std::shared_ptr (#209) * Initial plan * Replace boost/shared_ptr.hpp with memory header in test files Co-authored-by: timosachsenberg <5803621+timosachsenberg@users.noreply.github.com> * Replace boost::shared_ptr with std::shared_ptr Co-authored-by: timosachsenberg <5803621+timosachsenberg@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: timosachsenberg <5803621+timosachsenberg@users.noreply.github.com> * fix include --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
1 parent f2b09c7 commit 538c021

File tree

1,989 files changed

+176
-261495
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,989 files changed

+176
-261495
lines changed

MIGRATION_PLAN.MD

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
## Migration Plan: Cython 3+ Only
2+
3+
This document outlines how to drop legacy Cython 0.x / “Cython 2-style”
4+
compatibility and make `autowrap` cleanly target Cython 3+.
5+
6+
### 1. Tighten Cython Version Requirements
7+
8+
- Update `pyproject.toml` to require Cython 3+ (for example
9+
`Cython>=3.0` instead of `Cython>=0.19`).
10+
- Optionally add a runtime guard that checks
11+
`Cython.Compiler.Version.version` and raises a clear error if it is
12+
`< 3`.
13+
14+
### 2. Simplify `PXDParser` for Cython 3 Only
15+
16+
Key points:
17+
18+
- `autowrap/PXDParser.py:406–418`:
19+
conversion of `node.templates` from `[(string, bool)]` to `[string]`
20+
is still used and matches current Cython 3 behavior, so it remains.
21+
- `autowrap/PXDParser.py:627–632`:
22+
legacy `options.create_context()` (Cython 0.x) use has been removed in
23+
favor of `Context.from_options(options)` (Cython 3).
24+
25+
Planned/implemented changes:
26+
27+
- Assume the Cython 3 AST / options API:
28+
- Keep the `template_parameters` conversion as an internal
29+
normalization step for template arguments.
30+
- Unconditionally use `Context.from_options(options)` (or the
31+
canonical Cython 3 way to construct a `Context`).
32+
- Keep or simplify `options.language_level`:
33+
- Currently set to `sys.version_info.major`; optionally hard-code to
34+
`3` if we want explicit Python 3 semantics everywhere.
35+
36+
### 3. Simplify `run_cython` (CLI) to Cython 3 Only
37+
38+
Current compatibility code in `autowrap/Main.py:176–188`:
39+
40+
- Tries `from Cython.Compiler.Options import directive_defaults`,
41+
falls back to `Cython.Compiler.Options.get_directive_defaults()` for
42+
Cython 0.25.
43+
- Commented as “for backwards-compat to Cython 0.X”.
44+
45+
Planned changes:
46+
47+
- Assume Cython 3+:
48+
- Drop the `try/except ImportError` and always import
49+
`directive_defaults` from `Cython.Compiler.Options`.
50+
- Remove the fallback call to `get_directive_defaults()`.
51+
- Revisit directives (behavior, not compatibility):
52+
- Decide whether `binding=False` should be kept or whether Cython 3
53+
defaults are sufficient.
54+
- Keep `boundscheck=False`, `wraparound=False`, and the chosen
55+
`language_level` setting.
56+
57+
### 4. Clean Up Tests Assuming Cython < 3
58+
59+
Current version-specific logic:
60+
61+
- `tests/test_code_generator.py:test_enums`:
62+
- Imports `cython_version` from `Cython.Compiler.Version`.
63+
- Returns early if `int(cython_version[0]) < 3`.
64+
65+
Planned changes:
66+
67+
- Remove the version check and the `cython_version` import so that
68+
`test_enums` always runs (since Cython 3+ is now the minimum).
69+
- If any other tests gate behavior on “Cython < 3”, remove those
70+
branches as well.
71+
72+
### 5. Address `language_level=2` Test Files
73+
74+
Many test `.pxd` / `.pyx` files currently include:
75+
76+
- `# cython: language_level=2` (e.g. `tests/test_files/minimal.pxd`,
77+
`A.pxd`, `B.pxd`, `C.pxd`, `D.pxd`, `Cycle0/1/2.pxd`,
78+
`libcpp_test.pxd`, `templated.pxd`, `base*.pxd`,
79+
`int_container_class.pxd`, `gil_testing.pxd`, etc.).
80+
- Some `.pyx` files rely on Python 2 syntax (e.g.
81+
`print "dealloc called"` in `tests/test_files/itertest.pyx`).
82+
83+
Options:
84+
85+
- **Option A (fully modernize)**:
86+
- Remove `language_level=2` pragmas and rely on the global
87+
`language_level` from `directive_defaults` (Python 3 semantics).
88+
- Update any Python 2-only syntax in test files to Python 3 syntax
89+
(e.g. use `print("…")`).
90+
- Confirm that the C AST expected by `PXDParser` is unchanged for
91+
these declarations.
92+
- **Option B (keep as historical fixtures)**:
93+
- Leave `language_level=2` pragmas if they still compile under
94+
Cython 3 and if Python 2 semantics in tests are acceptable.
95+
- This keeps autowrap itself Cython 3-only while tolerating older
96+
directives in test fixtures.
97+
98+
If the goal is “fully Cython 3 / Python 3 semantics everywhere”,
99+
Option A should be implemented.
100+
101+
### 6. Refresh Docs and Examples for Cython 3
102+
103+
Not strictly required for compatibility, but desirable for clarity:
104+
105+
- `example/setup.py` and `tests/test_full_library.py` use
106+
`from Cython.Distutils import build_ext`; this still works under
107+
Cython 3, but more modern examples might use `cythonize`.
108+
- `docs/README.md` and `README.md` may include Python 2-style code
109+
snippets or wording that implicitly references “Cython 0.X”.
110+
111+
Planned changes:
112+
113+
- Update documentation to state that autowrap targets Cython 3+.
114+
- Modernize any Python 2-style examples (e.g. `print` statements) to
115+
Python 3 syntax where appropriate.
116+
- Optionally update example build instructions to show idiomatic
117+
Cython 3 usage.
118+
119+
### 7. Verification After Changes
120+
121+
After applying the above steps:
122+
123+
- Run the full test suite under Cython 3.x:
124+
- `pytest -v` from the project root.
125+
- Ensure all tests run (no early returns based on Cython version).
126+
- Optionally add a small test or import-time assertion that:
127+
- Checks `int(Cython.Compiler.Version.version[0]) >= 3`, and
128+
- Fails fast if someone accidentally runs under an older Cython.
129+
130+
This will ensure that autowrap’s parser, code generator, and CLI are
131+
all consistently using Cython 3 APIs and Python 3 semantics.

_codeql_detected_source_root

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.

autowrap/CodeGenerator.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,14 @@ def augment_arg_names(method):
9393
]
9494

9595

96-
def fixed_include_dirs(include_boost: bool) -> List[AnyStr]:
96+
def fixed_include_dirs() -> List[AnyStr]:
9797
from importlib.resources import files
9898

9999
autowrap_files = files("autowrap")
100-
boost = str(autowrap_files.joinpath("data_files/boost"))
101100
data = str(autowrap_files.joinpath("data_files"))
102101
autowrap_internal = str(autowrap_files.joinpath("data_files/autowrap"))
103102

104-
if not include_boost:
105-
return [autowrap_internal]
106-
else:
107-
return [boost, data, autowrap_internal]
103+
return [data, autowrap_internal]
108104

109105

110106
class CodeGenerator(object):
@@ -121,7 +117,6 @@ class CodeGenerator(object):
121117
pxd_dir: Optional[AnyStr]
122118
manual_code: Dict[str, Code]
123119
extra_cimports: Collection[str]
124-
include_shared_ptr: str
125120
include_refholder: bool
126121
include_numpy: bool
127122
add_relative: bool
@@ -164,7 +159,6 @@ def __init__(
164159
extra_cimports=None,
165160
all_decl=None,
166161
add_relative=False,
167-
shared_ptr="boost",
168162
):
169163
self.pxd_dir = None
170164
if all_decl is None:
@@ -174,7 +168,6 @@ def __init__(
174168

175169
self.manual_code: Dict[str, Code] = manual_code
176170
self.extra_cimports: Collection[str] = extra_cimports
177-
self.include_shared_ptr: str = shared_ptr
178171
self.include_refholder: bool = True
179172
self.include_numpy: bool = False
180173
self.add_relative: bool = add_relative
@@ -251,11 +244,11 @@ def __init__(
251244
self.wrapped_classes_cnt: int = 0
252245
self.wrapped_methods_cnt: int = 0
253246

254-
def get_include_dirs(self, include_boost: bool) -> List[AnyStr]:
247+
def get_include_dirs(self) -> List[AnyStr]:
255248
if self.pxd_dir is not None:
256-
return fixed_include_dirs(include_boost) + [self.pxd_dir]
249+
return fixed_include_dirs() + [self.pxd_dir]
257250
else:
258-
return fixed_include_dirs(include_boost)
251+
return fixed_include_dirs()
259252

260253
def setup_cimport_paths(self) -> None:
261254
"""
@@ -2039,18 +2032,11 @@ def create_default_cimports(self):
20392032
|from AutowrapConstPtrHolder cimport AutowrapConstPtrHolder
20402033
"""
20412034
)
2042-
if self.include_shared_ptr == "boost":
2043-
code.add(
2044-
"""
2045-
|from smart_ptr cimport shared_ptr
2046-
"""
2047-
)
2048-
elif self.include_shared_ptr == "std":
2049-
code.add(
2050-
"""
2035+
code.add(
2036+
"""
20512037
|from libcpp.memory cimport shared_ptr
20522038
"""
2053-
)
2039+
)
20542040
if self.include_numpy:
20552041
code.add(
20562042
"""

autowrap/Main.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ def create_wrapper_code(
199199
out,
200200
extra_inc_dirs,
201201
extra_opts,
202-
include_boost=True,
203202
allDecl=[],
204203
):
205204
cimports, manual_code = collect_manual_code(addons)
@@ -211,7 +210,6 @@ def create_wrapper_code(
211210
debug=False,
212211
manual_code=manual_code,
213212
extra_cimports=cimports,
214-
include_boost=include_boost,
215213
all_decl=allDecl,
216214
)
217215

autowrap/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ def generate_code(
7878
debug=False,
7979
manual_code=None,
8080
extra_cimports=None,
81-
include_boost=True,
8281
include_numpy=False,
8382
all_decl=[],
8483
add_relative=False,
85-
shared_ptr="boost",
8684
):
8785
import autowrap.CodeGenerator
8886

@@ -94,11 +92,10 @@ def generate_code(
9492
extra_cimports=extra_cimports,
9593
all_decl=all_decl,
9694
add_relative=add_relative,
97-
shared_ptr=shared_ptr,
9895
)
9996
gen.include_numpy = include_numpy
10097
gen.create_pyx_file(debug)
101-
includes = gen.get_include_dirs(include_boost)
98+
includes = gen.get_include_dirs()
10299
print(
103100
"Autowrap has wrapped %s classes, %s methods and %s enums"
104101
% (gen.wrapped_classes_cnt, gen.wrapped_methods_cnt, gen.wrapped_enums_cnt)
@@ -113,11 +110,10 @@ def parse_and_generate_code(
113110
debug,
114111
manual_code=None,
115112
extra_cimports=None,
116-
include_boost=True,
117113
):
118114
print("Autowrap will start to parse and generate code. " "Will parse %s files" % len(files))
119115
decls, instance_map = parse(files, root)
120116
print("Done parsing the files, will generate the code...")
121117
return generate_code(
122-
decls, instance_map, target, debug, manual_code, extra_cimports, include_boost
118+
decls, instance_map, target, debug, manual_code, extra_cimports
123119
)

autowrap/data_files/autowrap/smart_ptr.pxd

Lines changed: 0 additions & 10 deletions
This file was deleted.

autowrap/data_files/boost/LICENSE

Lines changed: 0 additions & 23 deletions
This file was deleted.

autowrap/data_files/boost/assert.hpp

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)