Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
86 changes: 86 additions & 0 deletions src/staking_sdk_py/cli.py
Original file line number Diff line number Diff line change
@@ -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/<package>/share/<package>/
# pipx run uses ~/.local/pipx/.cache/<hash>/share/<package>/
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()