__main__.py
Go to the documentation of this file.
1 # pylint: disable=missing-function-docstring
2 from __future__ import annotations
3 
4 import argparse
5 import re
6 import sys
7 import sysconfig
8 
9 from ._version import __version__
10 from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
11 
12 # This is the conditional used for os.path being posixpath
13 if "posix" in sys.builtin_module_names:
14  from shlex import quote
15 elif "nt" in sys.builtin_module_names:
16  # See https://github.com/mesonbuild/meson/blob/db22551ed9d2dd7889abea01cc1c7bba02bf1c75/mesonbuild/utils/universal.py#L1092-L1121
17  # and the original documents:
18  # https://docs.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments and
19  # https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
20  UNSAFE = re.compile("[ \t\n\r]")
21 
22  def quote(s: str) -> str:
23  if s and not UNSAFE.search(s):
24  return s
25 
26  # Paths cannot contain a '"' on Windows, so we don't need to worry
27  # about nuanced counting here.
28  return f'"{s}\\"' if s.endswith("\\") else f'"{s}"'
29 else:
30 
31  def quote(s: str) -> str:
32  return s
33 
34 
35 def print_includes() -> None:
36  dirs = [
37  sysconfig.get_path("include"),
38  sysconfig.get_path("platinclude"),
39  get_include(),
40  ]
41 
42  # Make unique but preserve order
43  unique_dirs = []
44  for d in dirs:
45  if d and d not in unique_dirs:
46  unique_dirs.append(d)
47 
48  print(" ".join(quote(f"-I{d}") for d in unique_dirs))
49 
50 
51 def main() -> None:
52  parser = argparse.ArgumentParser()
53  parser.add_argument(
54  "--version",
55  action="version",
56  version=__version__,
57  help="Print the version and exit.",
58  )
59  parser.add_argument(
60  "--includes",
61  action="store_true",
62  help="Include flags for both pybind11 and Python headers.",
63  )
64  parser.add_argument(
65  "--cmakedir",
66  action="store_true",
67  help="Print the CMake module directory, ideal for setting -Dpybind11_ROOT in CMake.",
68  )
69  parser.add_argument(
70  "--pkgconfigdir",
71  action="store_true",
72  help="Print the pkgconfig directory, ideal for setting $PKG_CONFIG_PATH.",
73  )
74  args = parser.parse_args()
75  if not sys.argv[1:]:
76  parser.print_help()
77  if args.includes:
79  if args.cmakedir:
81  if args.pkgconfigdir:
83 
84 
85 if __name__ == "__main__":
86  main()
Eigen::internal::print
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
Definition: NEON/PacketMath.h:3115
pybind11.commands.get_include
str get_include(bool user=False)
Definition: commands.py:8
pybind11.commands.get_cmake_dir
str get_cmake_dir()
Definition: commands.py:18
pybind11.__main__.print_includes
None print_includes()
Definition: __main__.py:35
pybind11.commands.get_pkgconfig_dir
str get_pkgconfig_dir()
Definition: commands.py:30
pybind11.__main__.main
None main()
Definition: __main__.py:51
pybind11.__main__.quote
str quote(str s)
Definition: __main__.py:22


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:01:12