diff --git a/README.md b/README.md index 7557a16..70680bc 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Compile Python command line tool wrappers from Boutiques descriptors. - [x] Documentation generation - [x] Custom execution environments via dependency injection - [x] Runtime input validation -- [ ] Unit test generation +- [ ] Unit & integration test generation ## Boutiques descriptor implementation status: 77% diff --git a/poetry.lock b/poetry.lock index 371488b..e986cb8 100644 --- a/poetry.lock +++ b/poetry.lock @@ -608,28 +608,28 @@ files = [ [[package]] name = "ruff" -version = "0.3.0" +version = "0.3.1" description = "An extremely fast Python linter and code formatter, written in Rust." optional = false python-versions = ">=3.7" files = [ - {file = "ruff-0.3.0-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:7deb528029bacf845bdbb3dbb2927d8ef9b4356a5e731b10eef171e3f0a85944"}, - {file = "ruff-0.3.0-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:e1e0d4381ca88fb2b73ea0766008e703f33f460295de658f5467f6f229658c19"}, - {file = "ruff-0.3.0-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2f7dbba46e2827dfcb0f0cc55fba8e96ba7c8700e0a866eb8cef7d1d66c25dcb"}, - {file = "ruff-0.3.0-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:23dbb808e2f1d68eeadd5f655485e235c102ac6f12ad31505804edced2a5ae77"}, - {file = "ruff-0.3.0-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3ef655c51f41d5fa879f98e40c90072b567c666a7114fa2d9fe004dffba00932"}, - {file = "ruff-0.3.0-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:d0d3d7ef3d4f06433d592e5f7d813314a34601e6c5be8481cccb7fa760aa243e"}, - {file = "ruff-0.3.0-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:b08b356d06a792e49a12074b62222f9d4ea2a11dca9da9f68163b28c71bf1dd4"}, - {file = "ruff-0.3.0-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:9343690f95710f8cf251bee1013bf43030072b9f8d012fbed6ad702ef70d360a"}, - {file = "ruff-0.3.0-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a1f3ed501a42f60f4dedb7805fa8d4534e78b4e196f536bac926f805f0743d49"}, - {file = "ruff-0.3.0-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:cc30a9053ff2f1ffb505a585797c23434d5f6c838bacfe206c0e6cf38c921a1e"}, - {file = "ruff-0.3.0-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:5da894a29ec018a8293d3d17c797e73b374773943e8369cfc50495573d396933"}, - {file = "ruff-0.3.0-py3-none-musllinux_1_2_i686.whl", hash = "sha256:755c22536d7f1889be25f2baf6fedd019d0c51d079e8417d4441159f3bcd30c2"}, - {file = "ruff-0.3.0-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:dd73fe7f4c28d317855da6a7bc4aa29a1500320818dd8f27df95f70a01b8171f"}, - {file = "ruff-0.3.0-py3-none-win32.whl", hash = "sha256:19eacceb4c9406f6c41af806418a26fdb23120dfe53583df76d1401c92b7c14b"}, - {file = "ruff-0.3.0-py3-none-win_amd64.whl", hash = "sha256:128265876c1d703e5f5e5a4543bd8be47c73a9ba223fd3989d4aa87dd06f312f"}, - {file = "ruff-0.3.0-py3-none-win_arm64.whl", hash = "sha256:e3a4a6d46aef0a84b74fcd201a4401ea9a6cd85614f6a9435f2d33dd8cefbf83"}, - {file = "ruff-0.3.0.tar.gz", hash = "sha256:0886184ba2618d815067cf43e005388967b67ab9c80df52b32ec1152ab49f53a"}, + {file = "ruff-0.3.1-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:6b82e3937d0d76554cd5796bc3342a7d40de44494d29ff490022d7a52c501744"}, + {file = "ruff-0.3.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:ae7954c8f692b70e6a206087ae3988acc9295d84c550f8d90b66c62424c16771"}, + {file = "ruff-0.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6b730f56ccf91225da0f06cfe421e83b8cc27b2a79393db9c3df02ed7e2bbc01"}, + {file = "ruff-0.3.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:c78bfa85637668f47bd82aa2ae17de2b34221ac23fea30926f6409f9e37fc927"}, + {file = "ruff-0.3.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d6abaad602d6e6daaec444cbf4d9364df0a783e49604c21499f75bb92237d4af"}, + {file = "ruff-0.3.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:5f0c21b6914c3c9a25a59497cbb1e5b6c2d8d9beecc9b8e03ee986e24eee072e"}, + {file = "ruff-0.3.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:434c3fc72e6311c85cd143c4c448b0e60e025a9ac1781e63ba222579a8c29200"}, + {file = "ruff-0.3.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:78a7025e6312cbba496341da5062e7cdd47d95f45c1b903e635cdeb1ba5ec2b9"}, + {file = "ruff-0.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:52b02bb46f1a79b0c1fa93f6495bc7e77e4ef76e6c28995b4974a20ed09c0833"}, + {file = "ruff-0.3.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:11b5699c42f7d0b771c633d620f2cb22e727fb226273aba775a91784a9ed856c"}, + {file = "ruff-0.3.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:54e5dca3e411772b51194b3102b5f23b36961e8ede463776b289b78180df71a0"}, + {file = "ruff-0.3.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:951efb610c5844e668bbec4f71cf704f8645cf3106e13f283413969527ebfded"}, + {file = "ruff-0.3.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:09c7333b25e983aabcf6e38445252cff0b4745420fc3bda45b8fce791cc7e9ce"}, + {file = "ruff-0.3.1-py3-none-win32.whl", hash = "sha256:d937f9b99ebf346e0606c3faf43c1e297a62ad221d87ef682b5bdebe199e01f6"}, + {file = "ruff-0.3.1-py3-none-win_amd64.whl", hash = "sha256:c0318a512edc9f4e010bbaab588b5294e78c5cdc9b02c3d8ab2d77c7ae1903e3"}, + {file = "ruff-0.3.1-py3-none-win_arm64.whl", hash = "sha256:d3b60e44240f7e903e6dbae3139a65032ea4c6f2ad99b6265534ff1b83c20afa"}, + {file = "ruff-0.3.1.tar.gz", hash = "sha256:d30db97141fc2134299e6e983a6727922c9e03c031ae4883a6d69461de722ae7"}, ] [[package]] @@ -685,4 +685,4 @@ docs = [] [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "85b8ea124a91fbdee3121c732c29fdc60745ad3d0b30f37e2ef5d8599ff0a55e" +content-hash = "1381614a7cf0b72135830c00e202fd3945e27331e39f394b7015b8c107b3883b" diff --git a/pyproject.toml b/pyproject.toml index b54c358..3088593 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,13 +10,14 @@ packages = [{include = "styx", from = "src"}] [tool.poetry.dependencies] python = "^3.11" pydantic = "^2.6.3" +ruff = "^0.3.1" [tool.poetry.group.dev.dependencies] pytest = "^8.0.2" mypy = "^1.7.1" pre-commit = "^3.6.0" pytest-cov = "^4.1.0" -ruff = "^0.3.0" +ruff = "^0.3.1" [tool.poetry.group.docs.dependencies] pdoc = "^14.2.0" diff --git a/src/styx/compiler/core.py b/src/styx/compiler/core.py index a55f11f..24c6ac3 100644 --- a/src/styx/compiler/core.py +++ b/src/styx/compiler/core.py @@ -8,6 +8,7 @@ from styx.compiler.settings import CompilerSettings, DefsMode from styx.compiler.utils import optional_float_to_int from styx.pycodegen.core import LineBuffer, PyArg, PyFunc, PyModule, collapse, expand, indent +from styx.pycodegen.format import format_code from styx.pycodegen.scope import Scope from styx.pycodegen.utils import ( as_py_literal, @@ -519,7 +520,6 @@ def _from_boutiques(tool: bt.Tool, settings: CompilerSettings) -> str: # type: if tool.container_image.root.image is not None: metadata["container_image_tag"] = tool.container_image.root.image - print(tool.container_image) # Static metadata buf_header.extend([ *defs, @@ -575,7 +575,12 @@ def _from_boutiques(tool: bt.Tool, settings: CompilerSettings) -> str: # type: mod.imports.extend(["import typing"]) mod.imports.sort() - return mod.text() + code = mod.text() + code_formatted = format_code(code) + if code_formatted is None: + print("WARNING: Failed to format code") + return code + return code_formatted def compile_descriptor(descriptor: bt.Tool, settings: CompilerSettings) -> str: # type: ignore diff --git a/src/styx/pycodegen/format.py b/src/styx/pycodegen/format.py new file mode 100644 index 0000000..7eb5421 --- /dev/null +++ b/src/styx/pycodegen/format.py @@ -0,0 +1,23 @@ +"""Format code using ruff.""" + +import subprocess +from pathlib import Path + + +def format_code(code: str) -> str | None: + """Format code using ruff.""" + try: + formatted = subprocess.check_output( + [ + "ruff", + "format", + "--config", + Path(__file__).parent / "ruff.toml", + "-", + ], + input=code, + encoding="utf-8", + ) + return formatted + except subprocess.CalledProcessError as _: + return None diff --git a/src/styx/pycodegen/ruff.toml b/src/styx/pycodegen/ruff.toml new file mode 100644 index 0000000..f5b5532 --- /dev/null +++ b/src/styx/pycodegen/ruff.toml @@ -0,0 +1,4 @@ +line-length = 80 + +[lint.pydocstyle] +convention = "google" diff --git a/src/styx/runners/local.py b/src/styx/runners/local.py new file mode 100644 index 0000000..e69de29