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..93e9277 --- /dev/null +++ b/src/staking_sdk_py/cli.py @@ -0,0 +1,86 @@ +"""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// + # pipx run uses ~/.local/pipx/.cache//share// + try: + import sysconfig + # 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 + + # Try relative to package location + import staking_sdk_py + package_location = Path(staking_sdk_py.__file__).parent.parent + # 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 + + # 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()