Skip to content

Commit

Permalink
Add --platform-info flag to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbarrett committed Mar 11, 2024
1 parent 61ad0b6 commit 69a040b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
28 changes: 26 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,34 @@ def tests(session):

# print info
session.run(
"python", "-m", "coverage", "run", "-m", "find_libpython", "--candidate-names"
"python",
"-m",
"coverage",
"run",
"-m",
"find_libpython",
"-v",
"--platform-info",
)
session.run(
"python", "-m", "coverage", "run", "-m", "find_libpython", "--candidate-paths"
"python",
"-m",
"coverage",
"run",
"-m",
"find_libpython",
"-v",
"--candidate-names",
)
session.run(
"python",
"-m",
"coverage",
"run",
"-m",
"find_libpython",
"-v",
"--candidate-paths",
)
session.run("python", "-m", "coverage", "run", "-m", "find_libpython", "-v")

Expand Down
22 changes: 17 additions & 5 deletions src/find_libpython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,6 @@ def _finding_libpython():
path : str
Existing path to a libpython.
"""
_logger.debug("_is_windows = %s", _is_windows)
_logger.debug("_is_apple = %s", _is_apple)
_logger.debug("_is_mingw = %s", _is_mingw)
_logger.debug("_is_msys = %s", _is_cygwin)
_logger.debug("_is_posix = %s", _is_posix)
for path in candidate_paths():
_logger.debug("Candidate: %s", path)
normalized = _normalize_path(path)
Expand Down Expand Up @@ -391,13 +386,23 @@ def _cli_find_libpython(cli_op, verbose):
_print_all(candidate_names())
elif cli_op == "candidate-paths":
_print_all(p for p in candidate_paths() if p and os.path.isabs(p))
elif cli_op == "platform-info":
_log_platform_info()
else:
path = find_libpython()
if path is None:
return 1
print(path, end="")


def _log_platform_info():
_logger.debug("_is_windows = %s", _is_windows)
_logger.debug("_is_apple = %s", _is_apple)
_logger.debug("_is_mingw = %s", _is_mingw)
_logger.debug("_is_msys = %s", _is_cygwin)
_logger.debug("_is_posix = %s", _is_posix)


def main(args=None):
import argparse

Expand Down Expand Up @@ -432,6 +437,13 @@ def main(args=None):
const="candidate-paths",
help="Print list of candidate paths of libpython.",
)
group.add_argument(
"--platform-info",
action="store_const",
dest="cli_op",
const="platform-info",
help="Print information about the platform and exit.",
)

ns = parser.parse_args(args)
parser.exit(_cli_find_libpython(**vars(ns)))

0 comments on commit 69a040b

Please # to comment.