Skip to content

Fix Cython @implementation include_dirs being overwritten - #1923

Merged
mstimberg merged 1 commit into
brian-team:masterfrom
Souravrajvi0:feat/fix-cython-include-dirs-443c
Nov 9, 2026
Merged

mstimberg merged 1 commit into
brian-team:masterfrom
Souravrajvi0:feat/fix-cython-include-dirs-443c

Conversation

@Souravrajvi0

Copy link
Copy Markdown
Contributor

Summary

  • Remove a duplicate assignment in CythonCodeObject.__init__ that overwrote self.include_dirs after merging @implementation(..., include_dirs=...) with prefs['codegen.cpp.include_dirs'].
  • Add test_external_function_cython_include_dirs, mirroring the existing C++ standalone include_dirs test: compile an external header from a temporary directory via Cython cdef extern.

Fixes #1922

Test plan

  • prefs.codegen.target = 'cython' and run test_external_function_cython_include_dirs locally
  • CI (Cython job)

Merge compiler_kwds include_dirs with prefs before building extensions,
and add a regression test using an external header in a temporary directory.

Fixes brian-team#1922

@antonsoo antonsoo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested c77a4af0 against a88d9f15 on Linux, Python 3.13.9, NumPy 2.5.4 and Cython 3.3.0, with each tree's native extensions built separately. The added external-header test passes.

A constructed 64-neuron Cython LIF network using @implementation(..., include_dirs=[...]) cannot compile its current function on the base because the header is not found. Here it produces all 101 expected spikes and an exact match to an independent discrete voltage recurrence. Both runtime and string-expression targets were Cython.

Changing header directories within one process still reuses the first binary: a second configuration produces 101 spikes instead of 156. This is the separate cache bug covered by #1925, not introduced here. A private composition of both PRs, plus the include-list copy described in my #1925 review, gives the expected 101/156/101 spikes and exact traces when switching A -> B -> A. Scope is these Linux header/current configurations; no other-platform or full-model claim.

@mstimberg mstimberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that's a silly bug, thanks for the fix! Apparently it has been around for eight years…

@mstimberg
mstimberg merged commit d80181e into brian-team:master Nov 9, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cython: include_dirs from @implementation / compiler_kwds are overwritten and ignored

3 participants