From 462c270962c59a97b617bbd88d0b2b4d02ee4ba9 Mon Sep 17 00:00:00 2001 From: geisserml Date: Wed, 17 Jan 2024 19:24:23 +0100 Subject: [PATCH 1/2] minor style improvements In dependencies.py: - In a comment, rename "imported modules" to "linked modules" - Check against "macro" only in one loop, not in both In __main__.py: avoid an odd use of any() where regular `or` does the trick. --- ctypesgen/__main__.py | 2 +- ctypesgen/processor/dependencies.py | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ctypesgen/__main__.py b/ctypesgen/__main__.py index 5a7c3b26..40a556e4 100644 --- a/ctypesgen/__main__.py +++ b/ctypesgen/__main__.py @@ -325,7 +325,7 @@ def __call__(self, parser, namespace, values, option_string=None): args = parser.parse_args(given_argv) - if not any([args.headers, args.system_headers]): + if not (args.headers or args.system_headers): raise argparse.ArgumentError("Either --headers or --system-headers required.") if args.cpp: diff --git a/ctypesgen/processor/dependencies.py b/ctypesgen/processor/dependencies.py index d0410ebf..6388c985 100755 --- a/ctypesgen/processor/dependencies.py +++ b/ctypesgen/processor/dependencies.py @@ -18,7 +18,7 @@ def find_dependencies(data, opts): typedef_names = {} ident_names = {} - # Start the lookup tables with names from imported modules + # Start the lookup tables with names from linked modules for name in opts.linked_symbols: typedef_names[name] = None @@ -155,12 +155,11 @@ def add_to_lookup_table(desc, kind): # Macros are handled differently from everything else because macros can # call other macros that are referenced after them in the input file, but # no other type of description can look ahead like that. - + + macros = [] for kind, desc in data.output_order: add_to_lookup_table(desc, kind) - if kind != "macro": - find_dependencies_for(desc, kind) + find_dependencies_for(desc, kind) if kind != "macro" else macros.append(desc) - for kind, desc in data.output_order: - if kind == "macro": - find_dependencies_for(desc, kind) + for desc in macros: + find_dependencies_for(desc, "macro") From 101a7d05511ae20a70d4071083f8db7a85aad410 Mon Sep 17 00:00:00 2001 From: geisserml Date: Wed, 17 Jan 2024 22:59:02 +0100 Subject: [PATCH 2/2] Start using assignment expressions (:= aka walrus operator) --- .github/workflows/test.yml | 2 -- ctypesgen/__main__.py | 12 ++++++------ pyproject.toml | 3 +-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 60a4a950..94c60bef 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,8 +22,6 @@ jobs: matrix: include: # Linux - - os: ubuntu-latest - python: 3.7 - os: ubuntu-latest python: 3.8 - os: ubuntu-latest diff --git a/ctypesgen/__main__.py b/ctypesgen/__main__.py index 40a556e4..2fe1a308 100644 --- a/ctypesgen/__main__.py +++ b/ctypesgen/__main__.py @@ -332,12 +332,12 @@ def __call__(self, parser, namespace, values, option_string=None): # split while preserving quotes args.cpp = shlex.split(args.cpp) else: - if shutil.which("gcc"): - args.cpp = ["gcc", "-E"] - elif shutil.which("cpp"): - args.cpp = ["cpp"] - elif shutil.which("clang"): - args.cpp = ["clang", "-E"] + if exe := shutil.which("gcc"): + args.cpp = [exe, "-E"] + elif exe := shutil.which("cpp"): + args.cpp = [exe] + elif exe := shutil.which("clang"): + args.cpp = [exe, "-E"] else: raise RuntimeError("C pre-processor auto-detection failed: neither gcc nor clang available.") diff --git a/pyproject.toml b/pyproject.toml index a6ff67a4..1679b64d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ license = { text = "BSD-2-Clause" } classifiers = [ "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", @@ -23,7 +22,7 @@ classifiers = [ "Environment :: Console", ] dynamic = ["readme", "version"] -requires-python = ">=3.7" +requires-python = ">=3.8" [project.urls] Homepage = "https://github.com/ctypesgen/ctypesgen"