-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of infrastructure for Python wrapper
- Loading branch information
Showing
15 changed files
with
220 additions
and
34 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from __future__ import annotations | ||
|
||
REMAGE_CPP_EXE_PATH = "@REMAGE_CPP_EXE_PATH@" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ requires = ["hatchling", "hatch-vcs"] | |
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "pyremage" | ||
name = "remage" | ||
authors = [ | ||
{ name = "Luigi Pertoldi", email = "[email protected]" }, | ||
] | ||
|
@@ -45,6 +45,9 @@ dev = [ | |
"pytest-cov >=3", | ||
] | ||
|
||
[project.scripts] | ||
remage = "remage.cli:remage_cli" | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/legend-exp/remage" | ||
"Bug Tracker" = "https://github.com/legend-exp/remage/issues" | ||
|
@@ -53,8 +56,10 @@ Changelog = "https://github.com/legend-exp/remage/releases" | |
|
||
[tool.hatch] | ||
version.source = "vcs" | ||
build.hooks.vcs.version-file = "python/_version.py" | ||
metadata.path = "python/" | ||
build.hooks.vcs.version-file = "python/remage/_version.py" | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["python/remage"] | ||
|
||
[tool.hatch.envs.default] | ||
features = ["test"] | ||
|
@@ -106,8 +111,6 @@ ignore = [ | |
"ISC001", # Conflicts with formatter | ||
] | ||
isort.required-imports = ["from __future__ import annotations"] | ||
# Uncomment if using a _compat.typing backport | ||
# typing-modules = ["pyremage._compat.typing"] | ||
|
||
[tool.ruff.lint.per-file-ignores] | ||
"tests/**" = ["T20"] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# get the output name of the remage-cli target (set in src/CMakeLists.txt) | ||
get_target_property(REMAGE_CPP_OUTPUT_NAME remage-cli-cpp OUTPUT_NAME) | ||
|
||
# construct the full path to the built executable | ||
set(REMAGE_CPP_EXE_PATH "${CMAKE_BINARY_DIR}/${REMAGE_CPP_OUTPUT_NAME}") | ||
|
||
# configure cpp_utils.py.in with the dynamically derived path | ||
configure_file("${PROJECT_SOURCE_DIR}/cmake/cpp_utils.py.in" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/remage/cpp_utils.py" @ONLY) | ||
|
||
# create the virtual environment with python-venv | ||
# also install the uv package manager | ||
set(VENV_DIR "${CMAKE_BINARY_DIR}/python_venv") | ||
|
||
add_custom_command( | ||
OUTPUT "${VENV_DIR}/bin/activate" | ||
COMMAND "${PYTHON_EXECUTABLE}" -m venv "${VENV_DIR}" | ||
COMMAND "${VENV_DIR}/bin/python" -m pip install --upgrade pip | ||
COMMAND "${VENV_DIR}/bin/python" -m pip install uv) | ||
|
||
add_custom_target( | ||
python-virtualenv | ||
DEPENDS "${VENV_DIR}/bin/activate" | ||
COMMENT "Configuring Python virtual environment in ${VENV_DIR}") | ||
|
||
# install the remage wrapper package into the virtual environment with uv | ||
add_custom_command( | ||
OUTPUT "${VENV_DIR}/bin/remage" | ||
COMMAND "${VENV_DIR}/bin/python" -m uv pip install "${CMAKE_SOURCE_DIR}" | ||
DEPENDS python-virtualenv) | ||
|
||
add_custom_target( | ||
remage-cli ALL | ||
DEPENDS "${VENV_DIR}/bin/remage" | ||
COMMENT "Installing remage Python wrapper into the virtual environment") | ||
|
||
# store the path to the remage executable, needed later in tests | ||
set_target_properties(remage-cli PROPERTIES PYEXE_PATH "${VENV_DIR}/bin/remage") | ||
|
||
# install section | ||
|
||
# construct the full path to the installed executable | ||
set(REMAGE_CPP_EXE_PATH | ||
"${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/${REMAGE_CPP_OUTPUT_NAME}") | ||
|
||
configure_file("${PROJECT_SOURCE_DIR}/cmake/cpp_utils.py.in" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/remage/cpp_utils.py" @ONLY) | ||
|
||
# install the package into the install prefix with the existing uv installation | ||
add_custom_command( | ||
OUTPUT "${CMAKE_INSTALL_PREFIX}/bin/remage" | ||
COMMAND "${VENV_DIR}/bin/python" -m uv pip install --prefix "${CMAKE_INSTALL_PREFIX}" | ||
"${CMAKE_SOURCE_DIR}") | ||
|
||
add_custom_target( | ||
install-remage-cli | ||
DEPENDS "${CMAKE_INSTALL_PREFIX}/bin/remage" | ||
COMMENT "Installing remage Python wrapper") | ||
|
||
# hack the install process to also install the remage wrapper | ||
install( | ||
CODE "execute_process(COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target install-remage-cli)" | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from __future__ import annotations |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
import argparse | ||
import subprocess | ||
import sys | ||
|
||
from .cpp_utils import REMAGE_CPP_EXE_PATH | ||
|
||
# NOTE: when uv/pip installs the package and creates the executable for the cli, | ||
# it hardcodes the path to the current python executable (e.g. the one of the | ||
# virtualenv) in the script's shebang | ||
|
||
|
||
def remage_cli(): | ||
parser = argparse.ArgumentParser( | ||
prog="remage", description="remage's command-line interface" | ||
) | ||
|
||
# global options | ||
parser.add_argument( | ||
"--version", action="store_true", help="""Print remage version and exit""" | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
cmdline = [REMAGE_CPP_EXE_PATH] | ||
if args.version: | ||
cmdline += ["--version"] | ||
|
||
result = subprocess.run(cmdline, check=False) | ||
|
||
sys.exit(result.returncode) |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
get_target_property(REMAGE_PYEXE remage-cli PYEXE_PATH) | ||
|
||
add_test(NAME python/cli COMMAND "${REMAGE_PYEXE}" --help) |
Oops, something went wrong.