iterm-components icon indicating copy to clipboard operation
iterm-components copied to clipboard

Create environment for AutoLaunch components

Open daneah opened this issue 5 years ago β€’ 9 comments

It would open a lot of doors to enable long-running components to use third-party packages.

Long-running components need to be placed in the AutoLaunch folder. The docs mention that scripts can have their own full environment via pyenv if done correctly, but I wasn't able to create a directory structure that seemed to work.

daneah avatar Apr 07 '19 14:04 daneah

Even if you put a script in ~/Library/Application Support/iTerm2/Scripts/AutoLaunch/ you still have to manually enable it by checking scripts > AutoLaunch > script.py in iTerm. After that, it should automatically launch when you restart iTerm.

harrygallagher4 avatar Jun 12 '19 04:06 harrygallagher4

@harrygallagher4 Yep, that works like a charm. This issue is about being able to have an environment around a script that enables you to use packages installed from e.g. PyPI.

daneah avatar Jun 12 '19 12:06 daneah

Whoops, didn't read the issue thoroughly enough πŸ˜…

harrygallagher4 avatar Jun 12 '19 19:06 harrygallagher4

@daneah according to the tutorial you can do that with the Full Environment option.

This creates a virtual environment where you can use other packages.

I've tried that yesterday. The structure looks like this.

> pwd
/Users/danieltrautmann/Library/Application Support/iTerm2/Scripts/AutoLaunch

> tree -L 3
.
└── status_bar
    β”œβ”€β”€ iterm2env
    β”‚Β Β  β”œβ”€β”€ iterm2env-metadata.json
    β”‚Β Β  β”œβ”€β”€ pyenv
    β”‚Β Β  β”œβ”€β”€ shims
    β”‚Β Β  └── versions
    β”œβ”€β”€ setup.cfg
    └── status_bar
        └── status_bar.py

Since I'm working on something similar you did, I'd be happy to help. However I'm not a Python expert.

0xd3e avatar Nov 18 '19 12:11 0xd3e

@danieltrautmann Thanks for the additional info. I keep meaning to look (and respond to you!) but haven't been able to find the time just yet. I don't have a particular component in mind to test this out with yet, either, but maybe soon πŸ˜„ if you do in the meantime and want to propose any additions, I'd welcome them πŸ’–

daneah avatar Nov 21 '19 20:11 daneah

I'll try to create a component that shows due tasks of a Todoist account.

0xd3e avatar Nov 21 '19 20:11 0xd3e

It seems that iTerm2 only installs the virtualenv when you create a new script via the GUI. So it is hard to provide scripts.

iTerm2 creates a file called setup.cfg and I thought this is used to setup the environment, but when you copy the directory containing the scripts to the iTerm2 Scripts directory. It doesn't create the environment automatically and I wasn't able to find a way to do it manually.

This is what the setup.cfg looks like:

# WARNING: This file was generated automatically by iTerm2. Do not edit it manually.
[metadata]
name=foo
version=1.0

[options]
scripts=foo/foo.py
install_requires=todoist-python; iterm2
python_requires = =3.8

[iterm2]
environment = >=62

Not sure if it is possible to use an environment which is not managed by iTerm2.

0xd3e avatar Nov 24 '19 18:11 0xd3e

@danieltrautmann Thanks so much for taking the time to investigate. That's pretty interesting. This might be enough for me to explore further, soon. setup.cfg is a common way to provide installation details, and install_requires is what's probably important here. The syntax seems fine, so might just be a matter of triggering iTerm2 to act on it.

daneah avatar Nov 25 '19 22:11 daneah

Yes, the trigger is the part I couldn't find. Another option that came to my mind is to provide iterm-components as a pip package and let the user create a new script with iterm-components as dependency.

But then we would also need some kind of script to initialize iterm-components. In the end this is not an ideal solution.

0xd3e avatar Nov 26 '19 06:11 0xd3e