Skip to content

Commit 932eba2

Browse files
authored
move project sources to src/ subdir (#12)
* 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/
1 parent 475c466 commit 932eba2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+35
-32
lines changed

.github/workflows/ci.yaml

+17-17
Original file line numberDiff line numberDiff line change
@@ -54,51 +54,51 @@ jobs:
5454

5555
- spec: cp38-manylinux_aarch64
5656
foreign_arch: true
57-
test_args: '{project}/c'
57+
test_args: '{project}/src/c'
5858
- spec: cp39-manylinux_aarch64
5959
foreign_arch: true
60-
test_args: '{project}/c'
60+
test_args: '{project}/src/c'
6161
- spec: cp310-manylinux_aarch64
6262
foreign_arch: true
63-
test_args: '{project}/c'
63+
test_args: '{project}/src/c'
6464
- spec: cp311-manylinux_aarch64
6565
foreign_arch: true
66-
test_args: '{project}/c'
66+
test_args: '{project}/src/c'
6767
- spec: cp312-manylinux_aarch64
6868
foreign_arch: true
69-
test_args: '{project}/c'
69+
test_args: '{project}/src/c'
7070

7171
- spec: cp38-manylinux_ppc64le
7272
foreign_arch: true
73-
test_args: '{project}/c'
73+
test_args: '{project}/src/c'
7474
- spec: cp39-manylinux_ppc64le
7575
foreign_arch: true
76-
test_args: '{project}/c'
76+
test_args: '{project}/src/c'
7777
- spec: cp310-manylinux_ppc64le
7878
foreign_arch: true
79-
test_args: '{project}/c'
79+
test_args: '{project}/src/c'
8080
- spec: cp311-manylinux_ppc64le
8181
foreign_arch: true
82-
test_args: '{project}/c'
82+
test_args: '{project}/src/c'
8383
- spec: cp312-manylinux_ppc64le
8484
foreign_arch: true
85-
test_args: '{project}/c'
85+
test_args: '{project}/src/c'
8686

8787
- spec: cp38-manylinux_s390x
8888
foreign_arch: true
89-
test_args: '{project}/c'
89+
test_args: '{project}/src/c'
9090
- spec: cp39-manylinux_s390x
9191
foreign_arch: true
92-
test_args: '{project}/c'
92+
test_args: '{project}/src/c'
9393
- spec: cp310-manylinux_s390x
9494
foreign_arch: true
95-
test_args: '{project}/c'
95+
test_args: '{project}/src/c'
9696
- spec: cp311-manylinux_s390x
9797
foreign_arch: true
98-
test_args: '{project}/c'
98+
test_args: '{project}/src/c'
9999
- spec: cp312-manylinux_s390x
100100
foreign_arch: true
101-
test_args: '{project}/c'
101+
test_args: '{project}/src/c'
102102

103103
steps:
104104
- name: clone repo
@@ -261,9 +261,9 @@ jobs:
261261
CIBW_BUILD: ${{ matrix.spec }}
262262
CIBW_PRERELEASE_PYTHONS: 'True'
263263
CIBW_TEST_REQUIRES: pytest setuptools
264-
CIBW_TEST_COMMAND: 'python -m pytest {project}/c'
264+
CIBW_TEST_COMMAND: 'python -m pytest {project}/src/c'
265265
# FIXME: /testing takes ~45min on Windows and has some failures...
266-
# CIBW_TEST_COMMAND='python -m pytest {project}/c {project}/testing'
266+
# CIBW_TEST_COMMAND='python -m pytest {project}/src/c {project}/testing'
267267
run: |
268268
python -m pip install --upgrade pip
269269
pip install "${{ matrix.cibw_version || 'cibuildwheel'}}"

MANIFEST.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
recursive-include cffi *.py *.h
2-
recursive-include c *.c *.h *.asm *.py win64.obj ffi.lib
1+
recursive-include src/cffi *.py *.h
2+
recursive-include src/c *.c *.h *.asm *.py win64.obj ffi.lib
33
recursive-include testing *.py *.c *.h
44
recursive-include doc *.py *.rst Makefile *.bat
55
recursive-include demo py.cleanup *.py embedding_test.c manual.c

setup.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import setuptools
88

99

10-
sources = ['c/_cffi_backend.c']
10+
sources = ['src/c/_cffi_backend.c']
1111
libraries = ['ffi']
1212
include_dirs = ['/usr/include/ffi',
1313
'/usr/include/libffi'] # may be changed by pkg-config
@@ -125,10 +125,10 @@ def use_homebrew_for_libffi():
125125

126126
if sys.platform == "win32" and uses_msvc():
127127
if platform.machine() == "ARM64":
128-
include_dirs.append(os.path.join("c/libffi_arm64/include"))
129-
library_dirs.append(os.path.join("c/libffi_arm64"))
128+
include_dirs.append(os.path.join("src/c/libffi_arm64/include"))
129+
library_dirs.append(os.path.join("src/c/libffi_arm64"))
130130
else:
131-
COMPILE_LIBFFI = 'c/libffi_x86_x64' # from the CPython distribution
131+
COMPILE_LIBFFI = 'src/c/libffi_x86_x64' # from the CPython distribution
132132
assert os.path.isdir(COMPILE_LIBFFI), "directory not found!"
133133
include_dirs[:] = [COMPILE_LIBFFI]
134134
libraries[:] = []
@@ -198,6 +198,7 @@ def has_ext_modules(self):
198198
version='1.16.0rc1',
199199
python_requires='>=3.8',
200200
packages=['cffi'] if cpython else [],
201+
package_dir={"": "src"},
201202
package_data={'cffi': ['_cffi_include.h', 'parse_c_type.h',
202203
'_embedding.h', '_cffi_errors.h']}
203204
if cpython else {},
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

c/cglob.c renamed to src/c/cglob.c

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.

testing/cffi0/test_version.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os, sys
22
import pytest
33
import cffi, _cffi_backend
4+
from pathlib import Path
45

56
def setup_module(mod):
67
if '_cffi_backend' in sys.builtin_module_names:
@@ -25,33 +26,33 @@ def test_version():
2526
assert v == _cffi_backend.__version__
2627

2728
def test_doc_version():
28-
parent = os.path.dirname(os.path.dirname(cffi.__file__))
29-
p = os.path.join(parent, 'doc', 'source', 'conf.py')
29+
cffi_root = Path(os.path.dirname(__file__)).parent.parent
30+
p = cffi_root / 'doc/source/conf.py'
3031
content = open(p).read()
3132
#
3233
v = cffi.__version__
3334
assert ("version = '%s'\n" % v[:4]) in content
3435
assert ("release = '%s'\n" % v) in content
3536

3637
def test_setup_version():
37-
parent = os.path.dirname(os.path.dirname(cffi.__file__))
38-
p = os.path.join(parent, 'setup.py')
38+
cffi_root = Path(os.path.dirname(__file__)).parent.parent
39+
p = cffi_root / 'setup.py'
3940
content = open(p).read()
4041
#
4142
v = cffi.__version__.replace('+', '')
4243
assert ("version='%s'" % v) in content
4344

4445
def test_c_version():
45-
parent = os.path.dirname(os.path.dirname(cffi.__file__))
46+
cffi_root = Path(os.path.dirname(__file__)).parent.parent
4647
v = cffi.__version__
47-
p = os.path.join(parent, 'c', 'test_c.py')
48+
p = cffi_root / 'src/c/test_c.py'
4849
content = open(p).read()
4950
#v = BACKEND_VERSIONS.get(v, v)
5051
assert (('assert __version__ == "%s"' % v) in content)
5152

5253
def test_embedding_h():
53-
parent = os.path.dirname(os.path.dirname(cffi.__file__))
54+
cffi_root = Path(os.path.dirname(__file__)).parent.parent
5455
v = cffi.__version__
55-
p = os.path.join(parent, 'cffi', '_embedding.h')
56+
p = cffi_root / 'src/cffi/_embedding.h'
5657
content = open(p).read()
5758
assert ('cffi version: %s"' % (v,)) in content

testing/cffi1/test_parse_c_type.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33
import cffi
44
from cffi import cffi_opcode
5+
from pathlib import Path
56

67
if '__pypy__' in sys.builtin_module_names:
78
try:
@@ -11,7 +12,7 @@
1112
# older pytest
1213
pytest.skip("not available on pypy")
1314

14-
cffi_dir = os.path.dirname(cffi_opcode.__file__)
15+
cffi_dir = str(Path(os.path.dirname(__file__)).parent.parent / "src/cffi")
1516

1617
r_macro = re.compile(r"#define \w+[(][^\n]*|#include [^\n]*")
1718
r_define = re.compile(r"(#define \w+) [^\n]*")

0 commit comments

Comments
 (0)