Add --script mode to run command for inline metadata scripts#21
Add --script mode to run command for inline metadata scripts#21
Conversation
|
You're iterating quickly on this pull request. To help protect your rate limits, cubic has paused automatic reviews on new pushes for now—when you're ready for another review, comment |
|
@cubic-dev-ai review |
@pirate I have started the AI code review. It will take a few minutes to complete. |
41370ca to
74ae064
Compare
1608e20 to
e9523c0
Compare
f5604fd to
d41aec6
Compare
6c09913 to
4dfcded
Compare
7379279 to
8dfbb1f
Compare
abx_pkg/binprovider_bun.py
Outdated
| def default_abspath_handler( | ||
| self, | ||
| bin_name: BinName | HostBinPath, | ||
| no_cache: bool = False, | ||
| **context, | ||
| ) -> HostBinPath | None: | ||
| result = super().default_abspath_handler(bin_name, **context) | ||
| return TypeAdapter(HostBinPath).validate_python(result) if result else None |
There was a problem hiding this comment.
this is not doing anything just remove it and let it use the base class method
8dfbb1f to
40dcd80
Compare
abx_pkg/binprovider_deno.py
Outdated
| def default_abspath_handler( | ||
| self, | ||
| bin_name: BinName | HostBinPath, | ||
| no_cache: bool = False, | ||
| **context, | ||
| ) -> HostBinPath | None: | ||
| result = super().default_abspath_handler(bin_name, **context) | ||
| return TypeAdapter(HostBinPath).validate_python(result) if result else None |
There was a problem hiding this comment.
this is also not doing anything, just remove it let the base class handle it
40dcd80 to
78aafd7
Compare
abx_pkg/binprovider_playwright.py
Outdated
| try: | ||
| return self.INSTALLER_BINARY(no_cache=no_cache).loaded_abspath | ||
| except Exception: | ||
| return None |
There was a problem hiding this comment.
shouldnt this be in the base method not the override?
78aafd7 to
130e145
Compare
| def default_abspath_handler( | ||
| self, | ||
| bin_name: BinName | HostBinPath, | ||
| no_cache: bool = False, | ||
| **context, | ||
| ) -> HostBinPath | None: | ||
| if str(bin_name) == self.INSTALLER_BIN: | ||
| return self.INSTALLER_BIN_ABSPATH | ||
| try: | ||
| return self.INSTALLER_BINARY(no_cache=no_cache).loaded_abspath | ||
| except Exception: | ||
| return None | ||
| bin_dir = self.bin_dir | ||
| assert bin_dir is not None | ||
| link_path = bin_dir / str(bin_name) |
There was a problem hiding this comment.
cant this just be on the base? then we dont need this same override everywhere.
Checking bin_dir for the bin_name seems like the most common pattern
8aad844 to
8536a0f
Compare
8536a0f to
d899150
Compare
d899150 to
bbe308c
Compare
bbe308c to
d168e0d
Compare
- parse_script_metadata(): comment-syntax-agnostic /// script parser - --script flag on run command with automatic dep resolution - BinProvider.ENV computed property + apply_env() for runtime env vars - ENV overrides on all 14 providers - [tool.abx-pkg] values passed through as env vars verbatim - Removed MANAGED_PROVIDER_ROOTS — providers resolve install_root from ABX_PKG_LIB_DIR via default_factory - abx_pkg_install_root_default reads env vars fresh (not cached) - Playwright/puppeteer: 3-mode npm resolution (global/managed/hermetic) https://claude.ai/code/session_0125eDj24UMFUhMUN8x2zmHB
d168e0d to
48996d7
Compare
Summary
This PR adds a new
--scriptmode to theabx-pkg runcommand that enables executing scripts with inline/// scriptmetadata blocks. The feature automatically parses script metadata, resolves declared dependencies, and executes the script with a PATH that includes all resolved binaries.Key Changes
New
parse_script_metadata()function: Extracts TOML-formatted metadata from/// scriptblocks in script files. Supports multiple comment styles (#,//,--,;, etc.) and handles multi-line TOML structures with proper indentation preservation.--scriptflag for run command: When enabled, treats the binary name as an interpreter and the first argument as a script file path. Parses the script's metadata, resolves all declared dependencies, and executes the script with an augmented PATH.Metadata-driven dependency resolution: Scripts can declare dependencies as strings or objects with additional options (custom binproviders, min_version). The resolver collects PATH entries from all successfully resolved binaries.
Tool configuration support: Scripts can include
[tool.abx-pkg]sections in metadata to set defaults forpostinstall_scripts,min_release_age, andmin_version. CLI flags take precedence over metadata settings.Comprehensive test coverage: Added 16 unit tests for metadata parsing (various comment styles, edge cases, TOML structures) and 7 integration tests for the full
run --scriptworkflow (argument passing, error handling, exit code propagation, CLI override behavior).Implementation Details
///marker; unclosed blocks returnNoneabx-pkgunchanged--dry-run) resolves dependencies but skips actual script executionhttps://claude.ai/code/session_0125eDj24UMFUhMUN8x2zmHB
Summary by cubic
Adds a new
--scriptmode toabx-pkg runthat parses inline/// scriptTOML, resolves dependencies, builds PATH and ENV from providers, and runs the script with the chosen interpreter. Also centralizes installer discovery and dynamic install-root resolution for shebang-friendly usage and consistent runtime envs.New Features
run --script INTERPRETER SCRIPT_PATH [ARGS...](shebang:#!/usr/bin/env -S abx-pkg run --script node). Implies--install;--dry-runonly resolves./// scriptTOML block.{name, binproviders, min_version}; PATH/ENV assembled from resolved providers.[tool.abx-pkg]values export as env vars verbatim; CLI flags still override.Refactors
BinProvider.ENV+apply_env()with merge rules ("value"overwrite,":value"append,"value:"prepend); implemented across all providers (pip,uv,npm,pnpm,yarn,bun,deno,brew,cargo,gem,goget,nix,apt,docker,chromewebstore,playwright,puppeteer).INSTALLER_BINARY()with env overrides (NPM_BINARY,PNPM_BINARY,YARN_BINARY,UV_BINARY,DENO_BINARY,BUN_BINARY).abx_pkg_install_root_default()which readsABX_PKG_LIB_DIRfresh at runtime; removedMANAGED_PROVIDER_ROOTS.playwright/puppeteer: add global/managed/hermeticnpmresolution; subprocess output formatter now accepts bytes.Written for commit 48996d7. Summary will update on new commits.