From 87aa70784bdea2ea816dacfc02a26f061eda93f4 Mon Sep 17 00:00:00 2001 From: qk-santi <94850169+qk-santi@users.noreply.github.com> Date: Wed, 12 Nov 2025 13:02:27 +0100 Subject: [PATCH 1/2] feat: pipx install --- pyproject.toml | 6 ++++ src/staking_sdk_py/cli.py | 71 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 src/staking_sdk_py/cli.py diff --git a/pyproject.toml b/pyproject.toml index e899b68..46712f8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,6 +34,9 @@ dependencies = [ [project.urls] +[project.scripts] +monad-staking-cli = "staking_sdk_py.cli:main" + [tool.hatch.version] path = "src/staking_sdk_py/__about__.py" @@ -57,3 +60,6 @@ exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"] [tool.hatch.build.targets.wheel] packages = ["src/staking_sdk_py"] + +[tool.hatch.build.targets.wheel.shared-data] +"staking-cli" = "share/staking-cli" diff --git a/src/staking_sdk_py/cli.py b/src/staking_sdk_py/cli.py new file mode 100644 index 0000000..d2230fb --- /dev/null +++ b/src/staking_sdk_py/cli.py @@ -0,0 +1,71 @@ +"""CLI entry point for staking-sdk-cli.""" +import sys +import os +from pathlib import Path + +def find_cli_directory(): + """Find the staking-cli directory in various possible locations.""" + # Try 1: Relative to this file (development) + package_dir = Path(__file__).parent.parent.parent + cli_dir = package_dir / 'staking-cli' + if cli_dir.exists(): + return cli_dir + + # Try 2: In the installed package location + try: + import staking_sdk_py + package_location = Path(staking_sdk_py.__file__).parent.parent + cli_dir = package_location / 'staking-cli' + if cli_dir.exists(): + return cli_dir + except Exception: + pass + + # Try 3: In share/staking-cli (if installed via shared-data) + # pipx installs packages in ~/.local/pipx/venvs//share// + try: + import site + import sysconfig + # Try to find share directory in various locations + for path in site.getsitepackages() + [sysconfig.get_path('data')]: + share_dir = Path(path).parent / 'share' / 'staking-cli' + if share_dir.exists(): + return share_dir + # Also try relative to package + import staking_sdk_py + package_location = Path(staking_sdk_py.__file__).parent.parent + share_dir = package_location.parent / 'share' / 'staking-cli' + if share_dir.exists(): + return share_dir + except Exception: + pass + + # Try 4: Current directory (for development) + cwd_cli = Path.cwd() / 'staking-cli' + if cwd_cli.exists(): + return cwd_cli + + raise ImportError( + f"Could not find staking-cli directory. " + f"Tried: {package_dir / 'staking-cli'}, " + f"installed package location, and current directory." + ) + +cli_dir = find_cli_directory() +sys.path.insert(0, str(cli_dir)) +# Change to the CLI directory so relative imports work +original_cwd = os.getcwd() +try: + os.chdir(cli_dir) + from main import StakingCLI +finally: + os.chdir(original_cwd) + + +def main(): + """Entry point for the staking-cli console script.""" + StakingCLI().main() + + +if __name__ == "__main__": + main() From e796cd3a616952304c60a70b028062515fdc5540 Mon Sep 17 00:00:00 2001 From: qk-santi <94850169+qk-santi@users.noreply.github.com> Date: Wed, 12 Nov 2025 13:57:41 +0100 Subject: [PATCH 2/2] fix: pipx run --- src/staking_sdk_py/cli.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/staking_sdk_py/cli.py b/src/staking_sdk_py/cli.py index d2230fb..93e9277 100644 --- a/src/staking_sdk_py/cli.py +++ b/src/staking_sdk_py/cli.py @@ -23,20 +23,35 @@ def find_cli_directory(): # Try 3: In share/staking-cli (if installed via shared-data) # pipx installs packages in ~/.local/pipx/venvs//share// + # pipx run uses ~/.local/pipx/.cache//share// try: - import site import sysconfig - # Try to find share directory in various locations - for path in site.getsitepackages() + [sysconfig.get_path('data')]: + # Get the data path (where share/ directory is located) + data_path = Path(sysconfig.get_path('data')) + share_dir = data_path / 'share' / 'staking-cli' + if share_dir.exists(): + return share_dir + + # Also try relative to site-packages (for some installation methods) + import site + for path in site.getsitepackages(): + # Try parent of site-packages (lib/pythonX.Y) then up to share + share_dir = Path(path).parent.parent / 'share' / 'staking-cli' + if share_dir.exists(): + return share_dir + # Also try at the same level as site-packages share_dir = Path(path).parent / 'share' / 'staking-cli' if share_dir.exists(): return share_dir - # Also try relative to package + + # Try relative to package location import staking_sdk_py package_location = Path(staking_sdk_py.__file__).parent.parent - share_dir = package_location.parent / 'share' / 'staking-cli' - if share_dir.exists(): - return share_dir + # Try various parent levels + for parent in [package_location.parent, package_location.parent.parent]: + share_dir = parent / 'share' / 'staking-cli' + if share_dir.exists(): + return share_dir except Exception: pass