Skip to content

Commit de09039

Browse files
committed
Fix tooling
1 parent 1a5a2c4 commit de09039

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

src/semiwrap/tool/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def main():
3939
else:
4040
retval = 0
4141

42-
return retval
42+
sys.exit(retval)
4343

4444

4545
if __name__ == "__main__":
46-
sys.exit(main())
46+
main()

src/semiwrap/tool/create_gen.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import os
12
import pathlib
3+
import typing as T
24

35
from ..autowrap.generator_data import MissingReporter
46
from ..cmd.header2dat import make_argparser, generate_wrapper
@@ -22,6 +24,28 @@ def add_subparser(cls, parent_parser, subparsers):
2224
def run(self, args):
2325
project_root = pathlib.Path.cwd()
2426

27+
# Problem: if another hatchling plugin sets PKG_CONFIG_PATH to include a .pc
28+
# file, makeplan() will fail to find it, which prevents a semiwrap program
29+
# from consuming those .pc files.
30+
#
31+
# We search for .pc files in the project root by default and add anything found
32+
# to the PKG_CONFIG_PATH to allow that to work. Probably won't hurt anything?
33+
34+
pcpaths: T.Set[str] = set()
35+
for pcfile in project_root.glob("**/*.pc"):
36+
pcpaths.add(str(pcfile.parent))
37+
38+
if pcpaths:
39+
# Add to PKG_CONFIG_PATH so that it can be resolved by other hatchling
40+
# plugins if desired
41+
pkg_config_path = os.environ.get("PKG_CONFIG_PATH")
42+
if pkg_config_path is not None:
43+
os.environ["PKG_CONFIG_PATH"] = os.pathsep.join(
44+
(pkg_config_path, *pcpaths)
45+
)
46+
else:
47+
os.environ["PKG_CONFIG_PATH"] = os.pathsep.join(pcpaths)
48+
2549
plan = makeplan(project_root, missing_yaml_ok=True)
2650

2751
for item in plan:

src/semiwrap/tool/create_imports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def add_subparser(cls, parent_parser, subparsers):
127127
def run(self, args):
128128
project = PyProject().project
129129

130-
if not project.update_init:
130+
if project.update_init is None:
131131
print("[tool.semiwrap].update_init not set", file=sys.stderr)
132132
return 1
133133

src/semiwrap/tool/scan_headers.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def add_subparser(cls, parent_parser, subparsers):
1818
parents=[parent_parser],
1919
)
2020
parser.add_argument("--all", default=False, action="store_true")
21+
parser.add_argument("--as-ignore", default=False, action="store_true", help="Emit scan_headers_ignore instead")
2122
return parser
2223

2324
def _make_search_paths(self, pyproject: PyProject) -> T.Dict[str, T.List[Path]]:
@@ -117,18 +118,26 @@ def _should_ignore(f):
117118

118119
files.sort()
119120

121+
if args.as_ignore:
122+
comment = " #"
123+
else:
124+
comment = "#"
125+
120126
lastdir = None
121127
for f in files:
122128
thisdir = f.parent
123129
if lastdir is None:
124130
if thisdir:
125-
print("#", thisdir)
131+
print(comment, thisdir)
126132
elif lastdir != thisdir:
127133
print()
128134
if thisdir:
129-
print("#", thisdir)
135+
print(comment, thisdir)
130136
lastdir = thisdir
131137

132138
base = f.stem
133-
print(f'{base} = "{f.as_posix()}"')
139+
if args.as_ignore:
140+
print(f' "{f.as_posix()}",')
141+
else:
142+
print(f'{base} = "{f.as_posix()}"')
134143
print()

0 commit comments

Comments
 (0)