Skip to content

Commit

Permalink
move project sources to src/ subdir (#12)
Browse files Browse the repository at this point in the history
* move the distutils shim module back to a plain module

* MANIFEST.in, the source layout, and pytest's default sys.path behavior conspired to mask a busted package, even though we were testing against the built package. `pytest` adds cwd to the path first, and since the `cffi` is in the root (grr), even though we're testing against the installed wheel, pytest loaded the subpackage from the source, masking that it was missing from the actual package (due to flat inclusions in MANIFEST.in). This is a longer-term problem that should be addressed by moving to a standard `src/` layout, and possibly also by bringing `_cffi_backend` in as a subpackage, but there are likely many dragons there with wheels that assume the presence of the top-level package.

* move project sources under src/
  • Loading branch information
nitzmahone committed Sep 26, 2023
1 parent 475c466 commit 932eba2
Show file tree
Hide file tree
Showing 65 changed files with 35 additions and 32 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/ci.yaml
Expand Up @@ -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
Expand Down Expand Up @@ -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'}}"
Expand Down
4 changes: 2 additions & 2 deletions 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
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Expand Up @@ -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
Expand Down Expand Up @@ -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[:] = []
Expand Down Expand Up @@ -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 {},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 9 additions & 8 deletions 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:
Expand All @@ -25,33 +26,33 @@ 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__
assert ("version = '%s'\n" % v[:4]) in content
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
3 changes: 2 additions & 1 deletion testing/cffi1/test_parse_c_type.py
Expand Up @@ -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:
Expand All @@ -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]*")
Expand Down

0 comments on commit 932eba2

Please sign in to comment.