kootenpv / cliche

Build a simple command-line interface from your functions :computer:
MIT License
107 stars 9 forks source link

Installing bin exec in a specific dir #8

Closed GTrunSec closed 2 years ago

GTrunSec commented 2 years ago

I think we should add a flexible path flag for different purposes.

Example:

cliche install --dir <path> <CommandName>
kootenpv commented 2 years ago

Added it! Thanks for the suggestion.

Also be aware since recently it became possible to add a line to setup.py to allow installing and uninstalling packages and including a command based on cliche

setup.py:

setup(
    name="my_module",
    entry_points={"console_scripts": ["my_command = cliche:runner"]},
    ....
)

where my_command will be the executable name

GTrunSec commented 2 years ago

Thanks for your modify. May you add a flag for executable dir instead of wrapping the command exec in Cliche's PythonPackage dir?

As a nix user, if we have dynamic flags for module_dir and bin_dir, that are helpful to create a sandbox environment for each command in different module_dirs.

tree .        
.
├── bin
│   └── cliche-custom
└── cl.py

Nix error output:

cliche install --module_dir ./cliche cliche_custom           
Traceback (most recent call last):
  File "/nix/store/0x2hbkva1hjjfk7n69p3zgci5dxqsxnp-python3.9-cliche-57dd14ddcbebefac91275d4c380be134b7167786/bin/.cliche-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/0x2hbkva1hjjfk7n69p3zgci5dxqsxnp-python3.9-cliche-57dd14ddcbebefac91275d4c380be134b7167786/lib/python3.9/site-packages/cliche/__init__.py", line 432, in main
    fn_registry[cmd][0](*starargs, **kwargs)
  File "/nix/store/0x2hbkva1hjjfk7n69p3zgci5dxqsxnp-python3.9-cliche-57dd14ddcbebefac91275d4c380be134b7167786/lib/python3.9/site-packages/cliche/install.py", line 20, in install
    with open(bin_name, "w") as f:
OSError: [Errno 30] Read-only file system: '/nix/store/0x2hbkva1hjjfk7n69p3zgci5dxqsxnp-python3.9-cliche-57dd14ddcbebefac91275d4c380be134b7167786/bin/cliche_custom'
kootenpv commented 2 years ago

Thanks for your modify. May you add a flag for executable dir instead of wrapping the command exec in Cliche's PythonPackage dir?

As a nix user, if we have dynamic flags for module_dir and bin_dir, that are helpful to create a sandbox environment for each command in different module_dirs.

  • expected cliche install --module_dir ./cliche --bin_dir ./cliche/bin cliche_custom
tree .        
.
├── bin
│   └── cliche-custom
└── cl.py

Nix error output:

cliche install --module_dir ./cliche cliche_custom           
Traceback (most recent call last):
  File "/nix/store/0x2hbkva1hjjfk7n69p3zgci5dxqsxnp-python3.9-cliche-57dd14ddcbebefac91275d4c380be134b7167786/bin/.cliche-wrapped", line 9, in <module>
    sys.exit(main())
  File "/nix/store/0x2hbkva1hjjfk7n69p3zgci5dxqsxnp-python3.9-cliche-57dd14ddcbebefac91275d4c380be134b7167786/lib/python3.9/site-packages/cliche/__init__.py", line 432, in main
    fn_registry[cmd][0](*starargs, **kwargs)
  File "/nix/store/0x2hbkva1hjjfk7n69p3zgci5dxqsxnp-python3.9-cliche-57dd14ddcbebefac91275d4c380be134b7167786/lib/python3.9/site-packages/cliche/install.py", line 20, in install
    with open(bin_name, "w") as f:
OSError: [Errno 30] Read-only file system: '/nix/store/0x2hbkva1hjjfk7n69p3zgci5dxqsxnp-python3.9-cliche-57dd14ddcbebefac91275d4c380be134b7167786/bin/cliche_custom'

I do wonder though how console_entry are installed then using pip? I'd like to ensure that it will work out of the box like that (i.e. I prefer to avoid having to cliche install in the first place)