diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 92c86595..cdb11d69 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -54,51 +54,51 @@ jobs: - spec: cp38-manylinux_aarch64 foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp39-manylinux_aarch64 foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp310-manylinux_aarch64 foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp311-manylinux_aarch64 foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp312-manylinux_aarch64 foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp38-manylinux_ppc64le foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp39-manylinux_ppc64le foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp310-manylinux_ppc64le foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp311-manylinux_ppc64le foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp312-manylinux_ppc64le foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp38-manylinux_s390x foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp39-manylinux_s390x foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp310-manylinux_s390x foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp311-manylinux_s390x foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' - spec: cp312-manylinux_s390x foreign_arch: true - test_args: '{project}/c' + test_args: '{project}/src/c' steps: - name: clone repo @@ -261,9 +261,9 @@ jobs: CIBW_BUILD: ${{ matrix.spec }} CIBW_PRERELEASE_PYTHONS: 'True' CIBW_TEST_REQUIRES: pytest setuptools - CIBW_TEST_COMMAND: 'python -m pytest {project}/c' + CIBW_TEST_COMMAND: 'python -m pytest {project}/src/c' # FIXME: /testing takes ~45min on Windows and has some failures... - # CIBW_TEST_COMMAND='python -m pytest {project}/c {project}/testing' + # CIBW_TEST_COMMAND='python -m pytest {project}/src/c {project}/testing' run: | python -m pip install --upgrade pip pip install "${{ matrix.cibw_version || 'cibuildwheel'}}" diff --git a/MANIFEST.in b/MANIFEST.in index b8ca2e08..a7616ffe 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ -recursive-include cffi *.py *.h -recursive-include c *.c *.h *.asm *.py win64.obj ffi.lib +recursive-include src/cffi *.py *.h +recursive-include src/c *.c *.h *.asm *.py win64.obj ffi.lib recursive-include testing *.py *.c *.h recursive-include doc *.py *.rst Makefile *.bat recursive-include demo py.cleanup *.py embedding_test.c manual.c diff --git a/setup.py b/setup.py index e9391764..8a2c5579 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ import setuptools -sources = ['c/_cffi_backend.c'] +sources = ['src/c/_cffi_backend.c'] libraries = ['ffi'] include_dirs = ['/usr/include/ffi', '/usr/include/libffi'] # may be changed by pkg-config @@ -125,10 +125,10 @@ def use_homebrew_for_libffi(): if sys.platform == "win32" and uses_msvc(): if platform.machine() == "ARM64": - include_dirs.append(os.path.join("c/libffi_arm64/include")) - library_dirs.append(os.path.join("c/libffi_arm64")) + include_dirs.append(os.path.join("src/c/libffi_arm64/include")) + library_dirs.append(os.path.join("src/c/libffi_arm64")) else: - COMPILE_LIBFFI = 'c/libffi_x86_x64' # from the CPython distribution + COMPILE_LIBFFI = 'src/c/libffi_x86_x64' # from the CPython distribution assert os.path.isdir(COMPILE_LIBFFI), "directory not found!" include_dirs[:] = [COMPILE_LIBFFI] libraries[:] = [] @@ -198,6 +198,7 @@ def has_ext_modules(self): version='1.16.0rc1', python_requires='>=3.8', packages=['cffi'] if cpython else [], + package_dir={"": "src"}, package_data={'cffi': ['_cffi_include.h', 'parse_c_type.h', '_embedding.h', '_cffi_errors.h']} if cpython else {}, diff --git a/c/_cffi_backend.c b/src/c/_cffi_backend.c similarity index 100% rename from c/_cffi_backend.c rename to src/c/_cffi_backend.c diff --git a/c/call_python.c b/src/c/call_python.c similarity index 100% rename from c/call_python.c rename to src/c/call_python.c diff --git a/c/cdlopen.c b/src/c/cdlopen.c similarity index 100% rename from c/cdlopen.c rename to src/c/cdlopen.c diff --git a/c/cffi1_module.c b/src/c/cffi1_module.c similarity index 100% rename from c/cffi1_module.c rename to src/c/cffi1_module.c diff --git a/c/cglob.c b/src/c/cglob.c similarity index 100% rename from c/cglob.c rename to src/c/cglob.c diff --git a/c/commontypes.c b/src/c/commontypes.c similarity index 100% rename from c/commontypes.c rename to src/c/commontypes.c diff --git a/c/ffi_obj.c b/src/c/ffi_obj.c similarity index 100% rename from c/ffi_obj.c rename to src/c/ffi_obj.c diff --git a/c/file_emulator.h b/src/c/file_emulator.h similarity index 100% rename from c/file_emulator.h rename to src/c/file_emulator.h diff --git a/c/lib_obj.c b/src/c/lib_obj.c similarity index 100% rename from c/lib_obj.c rename to src/c/lib_obj.c diff --git a/c/libffi_arm64/README b/src/c/libffi_arm64/README similarity index 100% rename from c/libffi_arm64/README rename to src/c/libffi_arm64/README diff --git a/c/libffi_arm64/build_libffi.bat b/src/c/libffi_arm64/build_libffi.bat similarity index 100% rename from c/libffi_arm64/build_libffi.bat rename to src/c/libffi_arm64/build_libffi.bat diff --git a/c/libffi_arm64/ffi.lib b/src/c/libffi_arm64/ffi.lib similarity index 100% rename from c/libffi_arm64/ffi.lib rename to src/c/libffi_arm64/ffi.lib diff --git a/c/libffi_arm64/include/ffi.h b/src/c/libffi_arm64/include/ffi.h similarity index 100% rename from c/libffi_arm64/include/ffi.h rename to src/c/libffi_arm64/include/ffi.h diff --git a/c/libffi_arm64/include/fficonfig.h b/src/c/libffi_arm64/include/fficonfig.h similarity index 100% rename from c/libffi_arm64/include/fficonfig.h rename to src/c/libffi_arm64/include/fficonfig.h diff --git a/c/libffi_arm64/include/ffitarget.h b/src/c/libffi_arm64/include/ffitarget.h similarity index 100% rename from c/libffi_arm64/include/ffitarget.h rename to src/c/libffi_arm64/include/ffitarget.h diff --git a/c/libffi_x86_x64/LICENSE b/src/c/libffi_x86_x64/LICENSE similarity index 100% rename from c/libffi_x86_x64/LICENSE rename to src/c/libffi_x86_x64/LICENSE diff --git a/c/libffi_x86_x64/README b/src/c/libffi_x86_x64/README similarity index 100% rename from c/libffi_x86_x64/README rename to src/c/libffi_x86_x64/README diff --git a/c/libffi_x86_x64/README.ctypes b/src/c/libffi_x86_x64/README.ctypes similarity index 100% rename from c/libffi_x86_x64/README.ctypes rename to src/c/libffi_x86_x64/README.ctypes diff --git a/c/libffi_x86_x64/ffi.c b/src/c/libffi_x86_x64/ffi.c similarity index 100% rename from c/libffi_x86_x64/ffi.c rename to src/c/libffi_x86_x64/ffi.c diff --git a/c/libffi_x86_x64/ffi.h b/src/c/libffi_x86_x64/ffi.h similarity index 100% rename from c/libffi_x86_x64/ffi.h rename to src/c/libffi_x86_x64/ffi.h diff --git a/c/libffi_x86_x64/ffi_common.h b/src/c/libffi_x86_x64/ffi_common.h similarity index 100% rename from c/libffi_x86_x64/ffi_common.h rename to src/c/libffi_x86_x64/ffi_common.h diff --git a/c/libffi_x86_x64/fficonfig.h b/src/c/libffi_x86_x64/fficonfig.h similarity index 100% rename from c/libffi_x86_x64/fficonfig.h rename to src/c/libffi_x86_x64/fficonfig.h diff --git a/c/libffi_x86_x64/ffitarget.h b/src/c/libffi_x86_x64/ffitarget.h similarity index 100% rename from c/libffi_x86_x64/ffitarget.h rename to src/c/libffi_x86_x64/ffitarget.h diff --git a/c/libffi_x86_x64/prep_cif.c b/src/c/libffi_x86_x64/prep_cif.c similarity index 100% rename from c/libffi_x86_x64/prep_cif.c rename to src/c/libffi_x86_x64/prep_cif.c diff --git a/c/libffi_x86_x64/types.c b/src/c/libffi_x86_x64/types.c similarity index 100% rename from c/libffi_x86_x64/types.c rename to src/c/libffi_x86_x64/types.c diff --git a/c/libffi_x86_x64/win32.c b/src/c/libffi_x86_x64/win32.c similarity index 100% rename from c/libffi_x86_x64/win32.c rename to src/c/libffi_x86_x64/win32.c diff --git a/c/libffi_x86_x64/win64.asm b/src/c/libffi_x86_x64/win64.asm similarity index 100% rename from c/libffi_x86_x64/win64.asm rename to src/c/libffi_x86_x64/win64.asm diff --git a/c/libffi_x86_x64/win64.obj b/src/c/libffi_x86_x64/win64.obj similarity index 100% rename from c/libffi_x86_x64/win64.obj rename to src/c/libffi_x86_x64/win64.obj diff --git a/c/malloc_closure.h b/src/c/malloc_closure.h similarity index 100% rename from c/malloc_closure.h rename to src/c/malloc_closure.h diff --git a/c/minibuffer.h b/src/c/minibuffer.h similarity index 100% rename from c/minibuffer.h rename to src/c/minibuffer.h diff --git a/c/misc_thread_common.h b/src/c/misc_thread_common.h similarity index 100% rename from c/misc_thread_common.h rename to src/c/misc_thread_common.h diff --git a/c/misc_thread_posix.h b/src/c/misc_thread_posix.h similarity index 100% rename from c/misc_thread_posix.h rename to src/c/misc_thread_posix.h diff --git a/c/misc_win32.h b/src/c/misc_win32.h similarity index 100% rename from c/misc_win32.h rename to src/c/misc_win32.h diff --git a/c/parse_c_type.c b/src/c/parse_c_type.c similarity index 100% rename from c/parse_c_type.c rename to src/c/parse_c_type.c diff --git a/c/realize_c_type.c b/src/c/realize_c_type.c similarity index 100% rename from c/realize_c_type.c rename to src/c/realize_c_type.c diff --git a/c/test_c.py b/src/c/test_c.py similarity index 100% rename from c/test_c.py rename to src/c/test_c.py diff --git a/c/wchar_helper.h b/src/c/wchar_helper.h similarity index 100% rename from c/wchar_helper.h rename to src/c/wchar_helper.h diff --git a/c/wchar_helper_3.h b/src/c/wchar_helper_3.h similarity index 100% rename from c/wchar_helper_3.h rename to src/c/wchar_helper_3.h diff --git a/cffi/__init__.py b/src/cffi/__init__.py similarity index 100% rename from cffi/__init__.py rename to src/cffi/__init__.py diff --git a/cffi/_cffi_errors.h b/src/cffi/_cffi_errors.h similarity index 100% rename from cffi/_cffi_errors.h rename to src/cffi/_cffi_errors.h diff --git a/cffi/_cffi_include.h b/src/cffi/_cffi_include.h similarity index 100% rename from cffi/_cffi_include.h rename to src/cffi/_cffi_include.h diff --git a/cffi/_embedding.h b/src/cffi/_embedding.h similarity index 100% rename from cffi/_embedding.h rename to src/cffi/_embedding.h diff --git a/cffi/_imp_emulation.py b/src/cffi/_imp_emulation.py similarity index 100% rename from cffi/_imp_emulation.py rename to src/cffi/_imp_emulation.py diff --git a/cffi/_shimmed_dist_utils/__init__.py b/src/cffi/_shimmed_dist_utils.py similarity index 100% rename from cffi/_shimmed_dist_utils/__init__.py rename to src/cffi/_shimmed_dist_utils.py diff --git a/cffi/api.py b/src/cffi/api.py similarity index 100% rename from cffi/api.py rename to src/cffi/api.py diff --git a/cffi/backend_ctypes.py b/src/cffi/backend_ctypes.py similarity index 100% rename from cffi/backend_ctypes.py rename to src/cffi/backend_ctypes.py diff --git a/cffi/cffi_opcode.py b/src/cffi/cffi_opcode.py similarity index 100% rename from cffi/cffi_opcode.py rename to src/cffi/cffi_opcode.py diff --git a/cffi/commontypes.py b/src/cffi/commontypes.py similarity index 100% rename from cffi/commontypes.py rename to src/cffi/commontypes.py diff --git a/cffi/cparser.py b/src/cffi/cparser.py similarity index 100% rename from cffi/cparser.py rename to src/cffi/cparser.py diff --git a/cffi/error.py b/src/cffi/error.py similarity index 100% rename from cffi/error.py rename to src/cffi/error.py diff --git a/cffi/ffiplatform.py b/src/cffi/ffiplatform.py similarity index 100% rename from cffi/ffiplatform.py rename to src/cffi/ffiplatform.py diff --git a/cffi/lock.py b/src/cffi/lock.py similarity index 100% rename from cffi/lock.py rename to src/cffi/lock.py diff --git a/cffi/model.py b/src/cffi/model.py similarity index 100% rename from cffi/model.py rename to src/cffi/model.py diff --git a/cffi/parse_c_type.h b/src/cffi/parse_c_type.h similarity index 100% rename from cffi/parse_c_type.h rename to src/cffi/parse_c_type.h diff --git a/cffi/pkgconfig.py b/src/cffi/pkgconfig.py similarity index 100% rename from cffi/pkgconfig.py rename to src/cffi/pkgconfig.py diff --git a/cffi/recompiler.py b/src/cffi/recompiler.py similarity index 100% rename from cffi/recompiler.py rename to src/cffi/recompiler.py diff --git a/cffi/setuptools_ext.py b/src/cffi/setuptools_ext.py similarity index 100% rename from cffi/setuptools_ext.py rename to src/cffi/setuptools_ext.py diff --git a/cffi/vengine_cpy.py b/src/cffi/vengine_cpy.py similarity index 100% rename from cffi/vengine_cpy.py rename to src/cffi/vengine_cpy.py diff --git a/cffi/vengine_gen.py b/src/cffi/vengine_gen.py similarity index 100% rename from cffi/vengine_gen.py rename to src/cffi/vengine_gen.py diff --git a/cffi/verifier.py b/src/cffi/verifier.py similarity index 100% rename from cffi/verifier.py rename to src/cffi/verifier.py diff --git a/testing/cffi0/test_version.py b/testing/cffi0/test_version.py index e975d24d..41cca932 100644 --- a/testing/cffi0/test_version.py +++ b/testing/cffi0/test_version.py @@ -1,6 +1,7 @@ import os, sys import pytest import cffi, _cffi_backend +from pathlib import Path def setup_module(mod): if '_cffi_backend' in sys.builtin_module_names: @@ -25,8 +26,8 @@ def test_version(): assert v == _cffi_backend.__version__ def test_doc_version(): - parent = os.path.dirname(os.path.dirname(cffi.__file__)) - p = os.path.join(parent, 'doc', 'source', 'conf.py') + cffi_root = Path(os.path.dirname(__file__)).parent.parent + p = cffi_root / 'doc/source/conf.py' content = open(p).read() # v = cffi.__version__ @@ -34,24 +35,24 @@ def test_doc_version(): assert ("release = '%s'\n" % v) in content def test_setup_version(): - parent = os.path.dirname(os.path.dirname(cffi.__file__)) - p = os.path.join(parent, 'setup.py') + cffi_root = Path(os.path.dirname(__file__)).parent.parent + p = cffi_root / 'setup.py' content = open(p).read() # v = cffi.__version__.replace('+', '') assert ("version='%s'" % v) in content def test_c_version(): - parent = os.path.dirname(os.path.dirname(cffi.__file__)) + cffi_root = Path(os.path.dirname(__file__)).parent.parent v = cffi.__version__ - p = os.path.join(parent, 'c', 'test_c.py') + p = cffi_root / 'src/c/test_c.py' content = open(p).read() #v = BACKEND_VERSIONS.get(v, v) assert (('assert __version__ == "%s"' % v) in content) def test_embedding_h(): - parent = os.path.dirname(os.path.dirname(cffi.__file__)) + cffi_root = Path(os.path.dirname(__file__)).parent.parent v = cffi.__version__ - p = os.path.join(parent, 'cffi', '_embedding.h') + p = cffi_root / 'src/cffi/_embedding.h' content = open(p).read() assert ('cffi version: %s"' % (v,)) in content diff --git a/testing/cffi1/test_parse_c_type.py b/testing/cffi1/test_parse_c_type.py index fa1f36c8..d203ba83 100644 --- a/testing/cffi1/test_parse_c_type.py +++ b/testing/cffi1/test_parse_c_type.py @@ -2,6 +2,7 @@ import pytest import cffi from cffi import cffi_opcode +from pathlib import Path if '__pypy__' in sys.builtin_module_names: try: @@ -11,7 +12,7 @@ # older pytest pytest.skip("not available on pypy") -cffi_dir = os.path.dirname(cffi_opcode.__file__) +cffi_dir = str(Path(os.path.dirname(__file__)).parent.parent / "src/cffi") r_macro = re.compile(r"#define \w+[(][^\n]*|#include [^\n]*") r_define = re.compile(r"(#define \w+) [^\n]*")