Skip to content
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

Add Cython to CI #2942

Merged
merged 20 commits into from
Feb 12, 2024
Merged

Add Cython to CI #2942

merged 20 commits into from
Feb 12, 2024

Conversation

jakkdl
Copy link
Member

@jakkdl jakkdl commented Jan 31, 2024

after some wrangling I've got Cython going in the CI. Though so much of CI is ~magic I probably have something configured badly.

  • Commented out all non-cython stuff for sake of testing, obviously will return those before merging.
  • Reverted the change of Cython Workaround #2911 for the sake of reproducing the failure
  • Cython==0.29.23, python 3.8 & 3.10 fails because of reverting Cython Workaround #2911
  • The other five failing tests are because old Cython versions does not work with 3.11/3.12

I vote for testing cython<3 and cython>=3 on latest python, but if @njsmith or @Zac-HD or somebody else has any reasons to test older versions, or on non-ubuntu, or on other python versions (and pypy?). Could even go so far as to add it to ci.sh and test it on everything, which I think would add something like 4-7 seconds.

test_cython.pyx could of course also be much more extensive, though grepping for Cython I'm only getting a hit for the one comment in src/trio/_core_run.py so doesn't seem like there's a lot of code that has been specially adapted for Cython. Maybe catch some exceptions? pytest does not seem to be a thing for cython, so running the full test suite or whatever I think is out of the question.

@jakkdl jakkdl requested review from Zac-HD and A5rocks January 31, 2024 15:21
@jakkdl jakkdl linked an issue Jan 31, 2024 that may be closed by this pull request
2 tasks
@jakkdl
Copy link
Member Author

jakkdl commented Jan 31, 2024

pypy+cython seems to sort of be a thing: https://docs.cython.org/en/latest/src/userguide/pypy.html
but I'm getting a fancy error locally, so if that's something we want to support we probably want it in the matrix (after fixing the error):

python -c 'import test_cython'
hello...
 world !
  + Exception Group Traceback (most recent call last):
  |   File "<string>", line 1, in <module>
  |   File "test_cython.pyx", line 20, in init test_cython
  |     main()
  |   File "test_cython.pyx", line 18, in test_cython.main
  |     trio.run(trio_main)
  |   File "/home/h/Git/trio/cython_ci/.tox/pypy3-cython/lib/pypy3.10/site-packages/trio/_core/_run.py", line 2274, in run
  |     raise runner.main_task_outcome.error
  |   File "test_cython.pyx", line 12, in trio_main
  |     async with trio.open_nursery() as nursery:
  |   File "/home/h/Git/trio/cython_ci/.tox/pypy3-cython/lib/pypy3.10/site-packages/trio/_core/_run.py", line 958, in __aexit__
  |     raise combined_error_from_nursery
  | exceptiongroup.ExceptionGroup: Exceptions from Trio nursery (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "test_cython.pyx", line 13, in test_cython.trio_main
    |     nursery.start_soon(foo)
    | AttributeError: 'NoneType' object has no attribute 'start_soon'
    +------------------------------------

@A5rocks A5rocks mentioned this pull request Feb 5, 2024
17 tasks
python -m pip install --upgrade pip setuptools
python -m pip install "cython${{ matrix.cython}}"
- name: install trio
# use -e?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think editable installs isn't the normal case and those are weird:tm:

So I think it's better to test non-editable installs of trio

Copy link
Member Author

Choose a reason for hiding this comment

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

I was randomly using Black's CI as a reference: https://github.com/search?q=repo%3Apsf%2Fblack+%22python+-m+pip+install+-e%22&type=code
I have no clue why they're doing -e tho

Copy link
Contributor

Choose a reason for hiding this comment

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

meh we'll find out if we need it

tests/cython/test_cython.pyx Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Show resolved Hide resolved
Copy link

codecov bot commented Feb 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (bd19635) 99.64% compared to head (7860181) 99.64%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2942   +/-   ##
=======================================
  Coverage   99.64%   99.64%           
=======================================
  Files         117      117           
  Lines       17564    17564           
  Branches     3166     3166           
=======================================
  Hits        17502    17502           
  Misses         43       43           
  Partials       19       19           
Files Coverage Δ
src/trio/_core/_run.py 99.66% <ø> (ø)

Copy link
Contributor

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

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

If we ever find some way to run the whole test suite under Cython that might be worth switching over (too much effort if it doesn't already exist though), but for now this works.

Copy link
Member

@CoolCat467 CoolCat467 left a comment

Choose a reason for hiding this comment

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

Looks good to me

@jakkdl
Copy link
Member Author

jakkdl commented Feb 12, 2024

Looking around more for cython+pytest I found https://shwina.github.io/cython-testing/ and after messing around with that for a bit I made some progress and managed to run sync test functions, so "just" need to inject our async magic somewhere in there as well and I might close in on running the full test suite.

I also somehow triggered the error from #2908 due to running against an old trio version in my messing around, despite cython being >3, so I wanna track that down and potentially report it upstream.

But we can merge this for now, and then I'll open another PR if/when I make progress on running the full test suite.

@jakkdl jakkdl merged commit b65afe1 into master Feb 12, 2024
60 checks passed
@jakkdl jakkdl deleted the cython_ci branch February 12, 2024 20:45
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 has defeated our Cython workaround
3 participants