iterm-components
iterm-components copied to clipboard
Create environment for AutoLaunch components
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.
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 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.
Whoops, didn't read the issue thoroughly enough π
@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.
@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 π
I'll try to create a component that shows due tasks of a Todoist account.
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.
@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.
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.