Skip to content

Commit

Permalink
restore veririfer.sourcefilename, make test_parse_c_tpye tests work w…
Browse files Browse the repository at this point in the history
…ith xdist, touch up documentation
  • Loading branch information
mattip committed Oct 13, 2024
1 parent ed30b46 commit 1b89cef
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,10 @@ jobs:
CIBW_MUSLLINUX_AARCH64_IMAGE: ${{ matrix.musllinux_img || 'musllinux_1_1' }}
CIBW_PRERELEASE_PYTHONS: 'True'
CIBW_FREE_THREADED_SUPPORT: 'True'
CIBW_TEST_REQUIRES: pytest setuptools # 3.12+ no longer includes distutils, just always ensure setuptools is present
CIBW_TEST_COMMAND: PYTHONUNBUFFERED=1 python -m pytest ${{ matrix.test_args || '{project}' }} # default to test all
# 3.12+ no longer includes distutils, just always ensure setuptools is present
CIBW_TEST_REQUIRES: pytest setuptools pytest-xdist filelock
# default to test all
CIBW_TEST_COMMAND: PYTHONUNBUFFERED=1 python -m pytest ${{ matrix.test_args || '{project}' }} -n 4
run: |
set -eux
Expand Down Expand Up @@ -417,8 +419,8 @@ jobs:
env:
CIBW_BUILD: ${{ matrix.spec }}
CIBW_PRERELEASE_PYTHONS: 'True'
CIBW_TEST_REQUIRES: pytest setuptools
CIBW_TEST_COMMAND: pip install pip --upgrade; cd {project}; PYTHONUNBUFFERED=1 pytest
CIBW_TEST_REQUIRES: pytest setuptools pytest-xdist filelock
CIBW_TEST_COMMAND: pip install pip --upgrade; cd {project}; PYTHONUNBUFFERED=1 pytest -n 4
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.deployment_target || '10.9' }}
SDKROOT: ${{ matrix.sdkroot || 'macosx' }}
run: |
Expand Down Expand Up @@ -508,10 +510,9 @@ jobs:
env:
CIBW_BUILD: ${{ matrix.spec }}
CIBW_PRERELEASE_PYTHONS: 'True'
CIBW_TEST_REQUIRES: pytest setuptools
CIBW_TEST_REQUIRES: pytest setuptools pytest-xdist filelock
CIBW_TEST_COMMAND: 'python -m pytest {package}/src/c'
# FIXME: /testing takes ~45min on Windows and has some failures...
# CIBW_TEST_COMMAND='python -m pytest {package}/src/c {project}/testing'
CIBW_TEST_COMMAND='python -m pytest {package}/src/c {project}/testing -n 4'
run: |
set -eux
Expand Down
6 changes: 3 additions & 3 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ Requirements:
* pycparser >= 2.06: https://github.com/eliben/pycparser (automatically
tracked by ``pip install cffi``).

* `pytest`_ is needed to run the tests of CFFI itself.
* `pytest`_ and `filelock` are needed to run the tests of CFFI itself.

.. _`pytest`: http://pypi.python.org/pypi/pytest
.. _`filelock`: http://pypi.python.org/pypi/filelock

Download and Installation:

Expand All @@ -54,8 +55,7 @@ Download and Installation:
``git clone https://github.com/python-cffi/cffi``

* running the tests: ``pytest c/ testing/`` (if you didn't
install cffi yet, you need first ``python setup_base.py build_ext -f
-i``)
install cffi yet, you need first ``python -m pip install -e .``)

.. _`GitHub`: https://github.com/python-cffi/cffi

Expand Down
2 changes: 2 additions & 0 deletions src/cffi/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,14 @@ def _compile_module(self):
tmpdir = os.path.dirname(self.sourcefilename)
olddir = os.getcwd()
os.chdir(tmpdir)
self.sourcefilename_orig = self.sourcefilename
try:
self.sourcefilename = os.path.relpath(self.sourcefilename)
output_rel_filename = ffiplatform.compile(tmpdir, self.get_extension())
outputfilename = os.path.join(tmpdir, output_rel_filename)
finally:
os.chdir(olddir)
self.sourcefilename = self.sourcefilename_orig
try:
same = ffiplatform.samefile(outputfilename, self.modulefilename)
except OSError:
Expand Down
2 changes: 1 addition & 1 deletion testing/cffi0/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2595,7 +2595,7 @@ def test_no_regen():
from cffi.verifier import Verifier, _caller_dir_pycache
import os
ffi = FFI()
modulename = "_cffi_test_no_regen"
modulename = "_cffi_test_no_regen_%d" % random.randint(0, 1000000000)
ffi.cdef("double sin(double x);")
lib = ffi.verify('#include <math.h>', libraries=lib_m, modulename=modulename)
assert lib.sin(1.23) == math.sin(1.23)
Expand Down
24 changes: 16 additions & 8 deletions testing/cffi1/test_parse_c_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
import cffi
from cffi import cffi_opcode
from filelock import FileLock
from pathlib import Path

if '__pypy__' in sys.builtin_module_names:
Expand All @@ -26,14 +27,21 @@
ffi = cffi.FFI()
ffi.cdef(header)

with open(os.path.join(cffi_dir, '..', 'c', 'parse_c_type.c')) as _body:
body = _body.read()
lib = ffi.verify(
body + """
static const char *get_common_type(const char *search, size_t search_len) {
return NULL;
}
""", include_dirs=[cffi_dir])

def build_lib():
sourcename = os.path.join(cffi_dir, '..', 'c', 'parse_c_type.c')
with FileLock(sourcename + ".lock"):
with open(sourcename) as _body:
body = _body.read()
lib = ffi.verify(
body + """
static const char *get_common_type(const char *search, size_t search_len) {
return NULL;
}
""", include_dirs=[cffi_dir])
return lib

lib = build_lib()

class ParseError(Exception):
pass
Expand Down

0 comments on commit 1b89cef

Please sign in to comment.