From 8725d13f944a9bc0517c741b57a1648ae500d7fd Mon Sep 17 00:00:00 2001 From: Jacob Faibussowitsch Date: Mon, 5 May 2025 14:31:35 -0400 Subject: [PATCH 1/2] add bootstrap example --- README.md | 53 +++++++++++++++++++++++++++++ share/aedifix/example_configure.py | 54 ++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100755 share/aedifix/example_configure.py diff --git a/README.md b/README.md index c2ce724..140753a 100644 --- a/README.md +++ b/README.md @@ -1 +1,54 @@ # aedifix + +# Bootstrapping aedifix in your build + +Assuming your main package is called `MyMainPacakge` and lives in `my_main_package.py`, +you may use the following snippet to create a `configure` script that automatically +bootstraps `aedifix` on first call. + +```python +#!/usr/bin/env python3 +from __future__ import annotations + +import sys + +def ensure_aedifix() -> None: + from importlib.metadata import PackageNotFoundError, version + + from packaging.version import Version + + VERSION = Version("1.2.0") + + try: + mod_version = Version(version("aedifix")) + + if mod_version == VERSION: + return + + if mod_version.is_devrelease: + # If its a "dev release" that means it's editable installed, + # meaning someone is working on aedifix. We don't care that the + # versions don't match in this case. + return + + raise RuntimeError + except (PackageNotFoundError, RuntimeError): + from subprocess import check_call + + package = f"git+https://github.com/nv-legate/aedifix@{VERSION}" + check_call([sys.executable, "-m", "pip", "install", package]) + + +ensure_aedifix() + +from aedifix.main import basic_configure + +from my_main_package import MyMainPackage + +def main() -> int: + return basic_configure(tuple(sys.argv[1:]), MyMainPackage) + + +if __name__ == "__main__": + sys.exit(main()) +``` diff --git a/share/aedifix/example_configure.py b/share/aedifix/example_configure.py new file mode 100755 index 0000000..68657bb --- /dev/null +++ b/share/aedifix/example_configure.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import sys + + +def ensure_aedifix() -> None: + r"""Ensure aedifix is bootstrapped.""" + from importlib.metadata import PackageNotFoundError, version + + from packaging.version import Version + + VERSION = Version("1.2.0") + + try: + mod_version = Version(version("aedifix")) + + if mod_version == VERSION: + return + + if mod_version.is_devrelease: + # If its a "dev release" that means it's editable installed, + # meaning someone is working on aedifix. We don't care that the + # versions don't match in this case. + return + + raise RuntimeError # noqa: TRY301 + except (PackageNotFoundError, RuntimeError): + from subprocess import check_call + + package = f"git+https://github.com/nv-legate/aedifix@{VERSION}" + check_call([sys.executable, "-m", "pip", "install", package]) + + +ensure_aedifix() + +from my_main_package import MyMainPackage # noqa: E402 + +from aedifix.main import basic_configure # noqa: E402 + + +def main() -> int: + r"""Run configure. + + Returns + ------- + int + An integer error code, or 0 on success. + """ + return basic_configure(tuple(sys.argv[1:]), MyMainPackage) + + +if __name__ == "__main__": + sys.exit(main()) From 4268797841100443fdcf97f25ff8013860953471 Mon Sep 17 00:00:00 2001 From: Jacob Faibussowitsch Date: Mon, 5 May 2025 14:32:25 -0400 Subject: [PATCH 2/2] fixup! add bootstrap example --- README.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 140753a..fa3688a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,9 @@ from __future__ import annotations import sys + def ensure_aedifix() -> None: + r"""Ensure aedifix is bootstrapped.""" from importlib.metadata import PackageNotFoundError, version from packaging.version import Version @@ -25,30 +27,39 @@ def ensure_aedifix() -> None: if mod_version == VERSION: return - if mod_version.is_devrelease: + if mod_version.is_devrelease: # If its a "dev release" that means it's editable installed, # meaning someone is working on aedifix. We don't care that the # versions don't match in this case. return - raise RuntimeError + raise RuntimeError # noqa: TRY301 except (PackageNotFoundError, RuntimeError): - from subprocess import check_call + from subprocess import check_call - package = f"git+https://github.com/nv-legate/aedifix@{VERSION}" - check_call([sys.executable, "-m", "pip", "install", package]) + package = f"git+https://github.com/nv-legate/aedifix@{VERSION}" + check_call([sys.executable, "-m", "pip", "install", package]) ensure_aedifix() -from aedifix.main import basic_configure +from my_main_package import MyMainPackage # noqa: E402 + +from aedifix.main import basic_configure # noqa: E402 -from my_main_package import MyMainPackage def main() -> int: + r"""Run configure. + + Returns + ------- + int + An integer error code, or 0 on success. + """ return basic_configure(tuple(sys.argv[1:]), MyMainPackage) if __name__ == "__main__": sys.exit(main()) + ```