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

Remove cython gen files, generate in meson build #2831

Merged
merged 2 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-debian-multiarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ env:
INSTALL_CMD: |
apt-get update --fix-missing
apt-get upgrade -y
apt-get install build-essential meson -y
apt-get install build-essential meson cython3 -y
apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev -y
apt-get install libfreetype6-dev libportmidi-dev fontconfig -y
apt-get install python3-dev python3-pip python3-wheel python3-sphinx -y
Expand Down
25 changes: 2 additions & 23 deletions .github/workflows/build-emsdk.yml
Copy link
Member Author

Choose a reason for hiding this comment

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

Why am I doing changes in this file?

Well these changes are not technically needed to make this PR pass this CI, but this is the only file still using the legacy setup.py based install so naturally I had to take a look here. Now, all this PR does here is bumps cython to the stable 3.0.10 release, the older code was building cython from source based on some commit in the cython 3.0.0 development history.

Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,12 @@ jobs:
SDK_ARCHIVE: python3.11-wasm-sdk-Ubuntu-22.04.tar.lz4
SDKROOT: /opt/python-wasm-sdk

# use the most recent cython from github, but pin on a commit for CI
# stability. This is also needed to benefit from caching cython installs
LATEST_CYTHON_COMMIT: 2f3a781dcca092ce95fbfef2736b12b0d1ab50dd # cython 3.0.0

WHEELHOUSE_CYTHON: /tmp/wheelhouse/cython

steps:
- uses: actions/checkout@v4.1.4

- name: Cache Cython
id: cache-cython
uses: actions/cache@v4.0.2
with:
path: ${{ env.WHEELHOUSE_CYTHON }}
key: wasm-ubuntu-cython-${{ env.LATEST_CYTHON_COMMIT }}-path-${{ env.WHEELHOUSE_CYTHON }}

# This builds the cython wheel and stores it in cache too
- name: Download and build cython on cache miss
if: steps.cache-cython.outputs.cache-hit != 'true'
run: |
mkdir -p $WHEELHOUSE_CYTHON
pip wheel --wheel-dir $WHEELHOUSE_CYTHON git+https://github.com/cython/cython.git@$LATEST_CYTHON_COMMIT

- name: Install latest cython and regen
- name: Regen with latest cython (using system python3)
run: |
pip install --no-index --find-links $WHEELHOUSE_CYTHON --pre cython
touch $(find | grep pxd$)
pip3 install cython==3.0.10
python3 setup.py cython_only

- name: Install python-wasm-sdk
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build-on-msys2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
mingw-w64-${{ matrix.env }}-python-pip
mingw-w64-${{ matrix.env }}-python-sphinx
mingw-w64-${{ matrix.env }}-meson-python
mingw-w64-${{ matrix.env }}-cython

# mingw-w64-${{ matrix.env }}-SDL2
# mingw-w64-${{ matrix.env }}-SDL2_image
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ dist
*.so
__pycache__
_headers/*

# cython generated files
src_c/_sdl2/*.c
!/src_c/_sdl2/touch.c
src_c/pypm.c
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(
'pygame_ce',
'c', # Project type. We only need a C compiler
['c', 'cython'], # Project type. We need a C compiler and cython
version: run_command(
[find_program('python3', 'python'), 'buildconfig/get_version.py'],
check: true,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ classifiers = [
hook-dirs = 'pygame.__pyinstaller:get_hook_dirs'

[build-system]
requires = ["meson-python", "ninja"] # add cython here when needed
requires = ["meson-python", "ninja", "cython"]
build-backend = 'mesonpy'

[tool.meson-python.args]
Expand Down
28 changes: 10 additions & 18 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,15 @@ def consume_arg(name):
cflags += '-mfpu=neon'
os.environ['CFLAGS'] = cflags

compile_cython = False
cython_only = False
if consume_arg('cython'):
compile_cython = True
no_compilation = bool({'docs', 'sdist', 'stubcheck'}.intersection(sys.argv))

compile_cython = not no_compilation

# does nothing now, but consume the arg anyways for compatibilty
consume_arg('cython')

cython_only = False
if consume_arg('cython_only'):
compile_cython = True
cython_only = True

if compile_cython:
Expand Down Expand Up @@ -243,22 +245,13 @@ def consume_arg(name):

# update outdated .c files
if os.path.isfile(c_file):
c_timestamp = os.path.getmtime(c_file)
if c_timestamp < deps.timestamp(pyx_file):
dep_timestamp, dep = deps.timestamp(pyx_file), pyx_file
priority = 0
else:
dep_timestamp, dep = deps.newest_dependency(pyx_file)
priority = 2 - (dep in deps.immediate_dependencies(pyx_file))
if dep_timestamp > c_timestamp:
outdated = True
else:
outdated = False
outdated = False
priority = 0
else:
outdated = True
priority = 0
if outdated:
print(f'Compiling {pyx_file} because it changed.')
print(f'Compiling {pyx_file} because the generated C file is missing.')
queue.append((priority, {'pyx_file': pyx_file, 'c_file': c_file, 'fingerprint': None, 'quiet': False,
'options': c_options, 'full_module_name': ext.name,
'embedded_metadata': pyx_meta.get(ext.name)}))
Expand All @@ -275,7 +268,6 @@ def consume_arg(name):
if cython_only:
sys.exit(0)

no_compilation = 'docs' in sys.argv
AUTO_CONFIG = not os.path.isfile('Setup') and not no_compilation
if consume_arg('-auto'):
AUTO_CONFIG = True
Expand Down
Loading
Loading