Last active
June 29, 2023 14:18
-
-
Save scivision/f4f20aa824c45a04e30d430d580589f3 to your computer and use it in GitHub Desktop.
importlib.resources for Python >= 3.9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Assumes executable "amender.bin" exists in the Python package and you want to resolve its full path and run it. | |
""" | |
import os | |
import subprocess | |
import importlib.resources as impr | |
def run_package_exe(name: str = "amender.bin"): | |
if os.name == "nt": | |
name += ".exe" | |
if not impr.as_file(impr.files(__package__).joinpath(name)).is_file(): | |
raise ImportError(f"{name} not found, please see README") | |
with impr.as_file(impr.files(__package__).joinpath(name)) as exe: | |
subprocess.check_call([str(exe), myparam1, myparam2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment