-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support vendoring with command (#5)
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
- Loading branch information
Showing
6 changed files
with
113 additions
and
1 deletion.
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
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,34 @@ | ||
from __future__ import annotations | ||
|
||
import argparse | ||
from pathlib import Path | ||
|
||
from ._version import version as __version__ | ||
from .vendor import vendorize | ||
|
||
__all__ = ["main"] | ||
|
||
|
||
def __dir__() -> list[str]: | ||
return __all__ | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Entry point. | ||
""" | ||
parser = argparse.ArgumentParser(description="CMake F2Py module helper") | ||
parser.add_argument( | ||
"--version", action="version", version=f"%(prog)s {__version__}" | ||
) | ||
subparser = parser.add_subparsers(required=True) | ||
vendor_parser = subparser.add_parser("vendor", help="Vendor CMake helpers") | ||
vendor_parser.add_argument( | ||
"target", type=Path, help="Directory to vendor the CMake helpers" | ||
) | ||
args = parser.parse_args() | ||
vendorize(args.target) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,30 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
if sys.version_info < (3, 9): | ||
from importlib_resources import files | ||
else: | ||
from importlib.resources import files | ||
|
||
__all__ = ["vendorize"] | ||
|
||
|
||
def __dir__() -> list[str]: | ||
return __all__ | ||
|
||
|
||
def vendorize(target: Path) -> None: | ||
""" | ||
Vendorize files into a directory. Directory must exist. | ||
""" | ||
if not target.is_dir(): | ||
msg = f"Target directory {target} does not exist" | ||
raise AssertionError(msg) | ||
|
||
cmake_dir = files("f2py_cmake") / "cmake" | ||
|
||
use = cmake_dir / "UseF2Py.cmake" | ||
use_target = target / "UseF2Py.cmake" | ||
use_target.write_text(use.read_text(encoding="utf-8"), encoding="utf-8") |
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,21 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from f2py_cmake.__main__ import main | ||
|
||
DIR = Path(__file__).parent.resolve() | ||
USE_F2PY = DIR.parent.joinpath("src/f2py_cmake/cmake/UseF2Py.cmake").read_text() | ||
|
||
|
||
def test_copy_files(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None: | ||
path = tmp_path / "copy_all" | ||
path.mkdir() | ||
|
||
monkeypatch.setattr(sys, "argv", [sys.executable, "vendor", str(path)]) | ||
main() | ||
|
||
assert path.joinpath("UseF2Py.cmake").read_text() == USE_F2PY |