stash icon indicating copy to clipboard operation
stash copied to clipboard

enchantment: Register entry points

Open o-murphy opened this issue 5 months ago • 9 comments

After #524 and https://github.com/ywangd/stash/issues/531 I propose to add 2 features

  • Propose user to create/update stash Pythonista action shortcut on get-stash complete
  • Update bin/pip.py to handle insallable packages entry points in `Documents/bin'

it can be solved with .egg-info\entry_points.txt, it looks like

[console_scripts]
entry-name = package_name.__main__:main

o-murphy avatar Aug 05 '25 17:08 o-murphy

The idea is wrap entries in .sh or .py files automatically by stash.pip and place it in Documents/bin/entry-name.sh, like PC interpreter versions do

o-murphy avatar Aug 05 '25 18:08 o-murphy

Propose user to create/update stash Pythonista action shortcut on get-stash complete

We offer this via the easy_config command. Opening that tool automatically would be a good idea, but I think we generally want the user to first force-quit and restart StaSh before we run StaSh in any capacity in order to deal with any cache-related weirdness. Just adding the shortcut would work, of course, too. But duplicating functionality already elsewhere present is always suboptimal, as it could lead to two similar actions with different behavior down the line.

Update bin/pip.py to handle insallable packages entry points in `Documents/bin'

it can be solved with .egg-info\entry_points.txt, it looks like [console_scripts] entry-name = package_name.main:main

We already do this, I think. I recall adding this feature a couple of years ago, although the entrypoints are stored in ~Documents/stash_extensions/bin/ (or some similar path). The reason we are not directly adding them to Dcouments/bin is that we don't exclusively manage that directory. Some users may have their own scripts (either custom commands or completely unrelated to StaSh) in that directory and it would suck if we accidentally overwrote something important, wouldn't it ;)

Ah, found it. This should have been implemented by #226 and #326.

bennr01 avatar Aug 05 '25 19:08 bennr01

Propose user to create/update stash Pythonista action shortcut on get-stash complete

We offer this via the easy_config command. Opening that tool automatically would be a good idea, but I think we generally want the user to first force-quit and restart StaSh before we run StaSh in any capacity in order to deal with any cache-related weirdness. Just adding the shortcut would work, of course, too. But duplicating functionality already elsewhere present is always suboptimal, as it could lead to two similar actions with different behavior down the line.

Update bin/pip.py to handle insallable packages entry points in `Documents/bin'

it can be solved with .egg-info\entry_points.txt, it looks like [console_scripts] entry-name = package_name.main:main

We already do this, I think. I recall adding this feature a couple of years ago, although the entrypoints are stored in ~Documents/stash_extensions/bin/ (or some similar path). The reason we are not directly adding them to Dcouments/bin is that we don't exclusively manage that directory. Some users may have their own scripts (either custom commands or completely unrelated to StaSh) in that directory and it would suck if we accidentally overwrote something important, wouldn't it ;)

Ah, found it. This should have been implemented by #226 and #326.

  • I was sure ``easy configadds an action toeasy configitself, not tostash`
  • Hm, but #524 uses common pip, seem like #226 and #326 would not work
  • We can place installed entry-points to some other dir like site-packages/bin or even ~/bin

o-murphy avatar Aug 05 '25 20:08 o-murphy

I will explore #226 and #326

o-murphy avatar Aug 05 '25 20:08 o-murphy

@bennr01 Aha, in easy_config it is not done, In addition, in #524 PR, I have already added support for __main__.py so easy_config should also be updated. I’ve already partially written this, so I think I’ll add the action creation as a separate command and import it into easy_config

@ui.in_background
def add_editor_action():
    """
    adds an editor action to the 'wrench' menu in the editor which
    launches launch_stash.py
    """
    mv = cfg_view  # [global] the main view
    mv.ai.start()
    try:
        lsp = "/launch_stash.py"  # TODO: auto-detect
        paa.add_action(
            lsp,
            "monitor",
            "000000",
            "StaSh",
        )
        paa.save_defaults()
    finally:
        mv.ai.stop()

o-murphy avatar Aug 05 '25 20:08 o-murphy

#326 already replaced by common pip and works fine

I will explore #226 and try to add this possibility to #524

o-murphy avatar Aug 05 '25 20:08 o-murphy

I was sure ``easy configadds an action toeasy configitself, not tostash`

It should add an action to launch StaSh as an action in the pythonista editor menu. Is that not what you are asking, or am I misunderstanding something?

Hm, but pythonista>=3.4/py>=3.10: Refactoring, removing deprecated requirements, updating for #524 uses common pip, seem like https://github.com/ywangd/stash/pull/226 and https://github.com/ywangd/stash/pull/326 would not work

I have yet to checkout that PR, it's quite big and I haven't had time yet, sorry. Yes, both PRs I've linked would only work with StaSh pip. I am not sure if we could even support the regular pip like the StaSh pip.

bennr01 avatar Aug 05 '25 20:08 bennr01

Okay I also found that #526 with common pip already register entry points in site-packages/bin so the only think we should do is allow to use it

o-murphy avatar Aug 05 '25 20:08 o-murphy

Propose user to create/update stash Pythonista action shortcut on get-stash complete

  • added bin/pinstash.py, updated bin/easy_config

Update bin/pip.py to handle insallable packages entry points in `Documents/bin'

  • site-packages/bin console scripts support added to #524, that approach is more native for python environment tree

o-murphy avatar Aug 06 '25 11:08 o-murphy