Skip to content
Open

TEST #293

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
16 changes: 8 additions & 8 deletions .github/actions/dynamatrix/matrix_yaml_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import os
import pathlib
import sys
import typing as t
import yaml

from collections.abc import MutableMapping, Sequence

import yaml

skipped_entries = []

def _filter_omit_entries(value):
if isinstance(value, MutableMapping):
if (omit_value := value.pop('omit', ...)) is not ...:
if omit_value is True or str(omit_value).lower().strip() == 'true':
print(f'omitting {value} from matrix')
skipped_entries.append(value)
return ...
omit_value = value.pop('omit', ...)
if omit_value is not ... and (
omit_value is True or str(omit_value).lower().strip() == 'true'):
print(f'omitting {value} from matrix')
skipped_entries.append(value)
return ...

return {k: v for k, v in ((k, _filter_omit_entries(v)) for k, v in value.items()) if v is not ...}

Expand Down
6 changes: 3 additions & 3 deletions demo/_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _ensure_initialised_color():

def _check_ERR(code, fname):
if code != lib.ERR:
return None
return
elif fname is None:
raise error("curses function returned ERR")
else:
Expand Down Expand Up @@ -799,7 +799,7 @@ def setupterm(term=None, fd=-1):
fd = sys.stdout.fileno()

if _initialised_setupterm:
return None
return

if term is None:
term = ffi.NULL
Expand All @@ -814,7 +814,7 @@ def setupterm(term=None, fd=-1):
raise error("setupterm: unknown error")

globals()["_initialised_setupterm"] = True
return None
return


def intrflush(ch):
Expand Down
1 change: 1 addition & 0 deletions demo/_curses_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

if sys.platform == 'win32':
#This module does not exist in windows
raise ImportError('No module named _curses')
Expand Down
1 change: 1 addition & 0 deletions demo/api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import cffi
from cffi import FFI


class PythonFFI(FFI):

def __init__(self, backend=None):
Expand Down
1 change: 1 addition & 0 deletions demo/bsdopendirtype.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from _bsdopendirtype import ffi, lib


Expand Down
1 change: 1 addition & 0 deletions demo/extern_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from _extern_python_cffi import ffi, lib


@ffi.def_extern()
def f(n):
return n * n
Expand Down
1 change: 1 addition & 0 deletions demo/extern_python_varargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

from _extern_python_cffi import ffi, lib


@ffi.def_extern()
def f(n, va):
if n == 3:
Expand Down
1 change: 1 addition & 0 deletions demo/fastcsv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csv

import cffi

# IN-PROGRESS. See the demo at the end of the file
Expand Down
1 change: 1 addition & 0 deletions demo/gmp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

#
# This is only a demo based on the GMP library.
# There is a rather more complete (but perhaps outdated) version available at:
Expand Down
3 changes: 0 additions & 3 deletions demo/pwuid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import sys, os

# run pwuid_build first, then make sure the shared object is on sys.path
from _pwuid_cffi import ffi, lib


print(ffi.string(lib.getpwuid(0).pw_name))
1 change: 1 addition & 0 deletions demo/pwuid_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cffi import FFI

ffi = FFI()
ffi.cdef(""" // some declarations from the man page
struct passwd {
Expand Down
1 change: 1 addition & 0 deletions demo/readdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
raise Exception("Linux-only demo")

from _readdir import ffi

lib = ffi.dlopen(None)


Expand Down
1 change: 1 addition & 0 deletions demo/readdir2_setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from distutils.core import setup

import readdir2_build

setup(
Expand Down
1 change: 1 addition & 0 deletions demo/readdir_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys

from cffi import FFI

if not sys.platform.startswith('linux'):
Expand Down
2 changes: 1 addition & 1 deletion demo/readdir_ctypes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# A Linux-only demo
#
# For comparison purposes, this is a ctypes version of readdir.py.
import sys
import ctypes
import sys

if not sys.platform.startswith('linux'):
raise Exception("Linux-only demo")
Expand Down
1 change: 1 addition & 0 deletions demo/recopendirtype.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

from _recopendirtype import ffi, lib


Expand Down
3 changes: 2 additions & 1 deletion demo/recopendirtype_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from cffi import FFI
import bsdopendirtype_build

from cffi import FFI

ffi = FFI()

# ========== This is a demo of ffi.include() ==========
Expand Down
1 change: 1 addition & 0 deletions demo/setup_manual.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from distutils.core import setup
from distutils.extension import Extension

setup(name='manual',
ext_modules=[Extension(name='manual',
sources=['manual.c'])])
2 changes: 1 addition & 1 deletion demo/winclipboard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__author__ = "Israel Fruchter <israel.fruchter@gmail.com>"

import sys, os
import sys

if not sys.platform == 'win32':
raise Exception("Windows-only demo")
Expand Down
3 changes: 0 additions & 3 deletions demo/xclient.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import sys, os

# run xclient_build first, then make sure the shared object is on sys.path
from _xclient_cffi import ffi, lib


# ffi "knows" about the declared variables and functions from the
# cdef parts of the module xclient_build created,
# lib "knows" how to call the functions from the set_source parts
Expand Down
1 change: 1 addition & 0 deletions demo/xclient_build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cffi import FFI

ffi = FFI()
ffi.cdef("""

Expand Down
2 changes: 0 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand Down
12 changes: 7 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import sys, sysconfig, os, platform
import subprocess
import errno
import os
import platform
import subprocess
import sys
import sysconfig

# the setuptools distutils shim should make distutils available, but this will definitely do
# it, since setuptools is now required at build-time
import setuptools

import setuptools # noqa: F401

sources = ['src/c/_cffi_backend.c']
libraries = ['ffi']
Expand Down Expand Up @@ -168,7 +170,7 @@ def use_homebrew_for_libffi():


if __name__ == '__main__':
from setuptools import setup, Distribution, Extension
from setuptools import Distribution, Extension, setup

class CFFIDistribution(Distribution):
def has_ext_modules(self):
Expand Down
15 changes: 10 additions & 5 deletions setup_base.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import sys, os


from setup import include_dirs, sources, libraries, define_macros
from setup import library_dirs, extra_compile_args, extra_link_args
import sys

from setup import (
define_macros,
extra_compile_args,
extra_link_args,
include_dirs,
libraries,
library_dirs,
sources,
)

if __name__ == '__main__':
from distutils.core import setup
Expand Down
32 changes: 15 additions & 17 deletions src/c/test_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import contextlib
import os
import sys
import traceback
import unittest.mock

import pytest
import sys
import typing as t

is_musl = False
if sys.platform == 'linux':
Expand All @@ -22,11 +20,13 @@


def _setup_path():
import os, sys
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
_setup_path()
from _cffi_backend import *
from _cffi_backend import _get_types, _get_common_types
from _cffi_backend import _get_common_types, _get_types

try:
from _cffi_backend import _testfunc
except ImportError:
Expand Down Expand Up @@ -67,6 +67,7 @@ def _capture_unraisable_hook(ur_args):
# ____________________________________________________________

import sys

assert __version__ == "2.2.0.dev0", ("This test_c.py file is for testing a version"
" of cffi that differs from the one that we"
" get from 'import _cffi_backend'")
Expand Down Expand Up @@ -3244,8 +3245,8 @@ class mylist(list):
del o
import gc; gc.collect()
assert wr() is not None
assert from_handle(x) == list((2, 3, 4))
assert from_handle(cast(BCharP, x)) == list((2, 3, 4))
assert from_handle(x) == [2, 3, 4]
assert from_handle(cast(BCharP, x)) == [2, 3, 4]
del x
for i in range(3):
if wr() is not None:
Expand All @@ -3254,8 +3255,8 @@ class mylist(list):
pytest.raises(RuntimeError, from_handle, cast(BCharP, 0))

def test_new_handle_cycle():
import gc
import _weakref
import gc
BVoidP = new_pointer_type(new_void_type())
class A:
pass
Expand Down Expand Up @@ -4167,7 +4168,6 @@ def test_cdata_dir():
check_dir(pp[0][0], ['a1', 'a2'])

def test_char_pointer_conversion():
import warnings
BCharP = new_pointer_type(new_primitive_type("char"))
BIntP = new_pointer_type(new_primitive_type("int"))
BVoidP = new_pointer_type(new_void_type())
Expand All @@ -4176,10 +4176,10 @@ def test_char_pointer_conversion():
z2 = cast(BIntP, 0)
z3 = cast(BVoidP, 0)
z4 = cast(BUCharP, 0)
with pytest.raises(TypeError) as e1:
with pytest.raises(TypeError):
newp(new_pointer_type(BIntP), z1)
newp(new_pointer_type(BVoidP), z1) # fine
with pytest.raises(TypeError) as e2:
with pytest.raises(TypeError):
newp(new_pointer_type(BCharP), z2)
newp(new_pointer_type(BVoidP), z2) # fine
newp(new_pointer_type(BCharP), z3) # fine
Expand Down Expand Up @@ -4311,12 +4311,10 @@ def test_explicit_release_badtype():
def test_explicit_release_badtype_contextmgr():
BIntP = new_pointer_type(new_primitive_type("int"))
p = cast(BIntP, 12345)
with pytest.raises(ValueError):
with p:
pass
with pytest.raises(ValueError):
with p:
pass
with pytest.raises(ValueError), p:
pass
with pytest.raises(ValueError), p:
pass

def test_explicit_release_gc():
BIntP = new_pointer_type(new_primitive_type("int"))
Expand Down
13 changes: 9 additions & 4 deletions src/cffi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
__all__ = ['FFI', 'VerificationError', 'VerificationMissing', 'CDefError',
'FFIError']
__all__ = ['FFI', 'CDefError','FFIError', 'PkgConfigError',
'VerificationError', 'VerificationMissing']

from .api import FFI
from .error import CDefError, FFIError, VerificationError, VerificationMissing
from .error import PkgConfigError
from .error import (
CDefError,
FFIError,
PkgConfigError,
VerificationError,
VerificationMissing,
)

__version__ = "2.2.0.dev0"
__version_info__ = (2, 2, 0, 'dev0')
Expand Down
9 changes: 3 additions & 6 deletions src/cffi/_imp_emulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
# Note that this is used only for tests or for the old ffi.verify().
# This is copied from the source code of Python 3.11.

from _imp import (acquire_lock, release_lock,
is_builtin, is_frozen)

from importlib._bootstrap import _load

from importlib import machinery
import os
import sys
import tokenize
from _imp import is_builtin, is_frozen
from importlib import machinery
from importlib._bootstrap import _load

SEARCH_ERROR = 0
PY_SOURCE = 1
Expand Down
2 changes: 1 addition & 1 deletion src/cffi/_shimmed_dist_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from distutils.command.build_ext import build_ext
from distutils.core import Distribution, Extension
from distutils.dir_util import mkpath
from distutils.errors import DistutilsSetupError, CompileError, LinkError
from distutils.errors import CompileError, DistutilsSetupError, LinkError
from distutils.log import set_threshold, set_verbosity

if sys.platform == 'win32':
Expand Down
Loading
Loading