Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom executable / custom language #52

Closed
akdor1154 opened this issue Apr 7, 2022 · 4 comments
Closed

Custom executable / custom language #52

akdor1154 opened this issue Apr 7, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@akdor1154
Copy link

akdor1154 commented Apr 7, 2022

Hey,
Thanks for this project, seems to nearly fill exactly what I was looking for.

I am getting stuck on one thing - I'm writing shell code cells, but I'm wanting to use a custom executable/shell for these. For this example let's say I want to use /usr/bin/fish, but full disclosure, what I really want is to get codebraid to run its stuff in a container, by passing the executable podman run -it docker.io/ubuntu:21.10.

When passing executable= to the shell session block as per docs, I get an "executable not found" error:

```{.bash .cb-nb session=dock executable="podman run --name mine -v .:/demo -it ubuntu:21.10"}
set -e
cd /demo/demo
pwd
```
``` {.error .sysConfigError}
SYS CONFIG ERROR in "post.md" near line 88:
Could not find executable "podman run --name mine -v .:/demo -it ubuntu:21.10"
```

When passing executable= to the shell session block as a list because I'm guessing it might get send to subprocess.run, that block doesn't run and future blocks use bash directly.

```{.bash .cb-nb session=dock executable=["podman", "run", "--name", "mine", "-v" ".:/demo", "-it", "ubuntu:21.10"]}
set -e
cd /demo/demo
pwd
ls -l # does not run
```

```{.bash .cb-nb session=dock}
curl -sL https://nixos.org/nix/install | bash -s -- --no-daemon
pwd
ls -l # executes outside container
```

Is there some permutation like the above that's meant to work with shell blocks?

If not, is there a way I can set up a new language by writing the config file in my project, without needing to fork codebraid locally?

Simple answer to both might be "no", no worries if so :)

Thanks!

@gpoore
Copy link
Owner

gpoore commented Apr 7, 2022

Currently, executable literally means executable path only, without any arguments. I believe arguments did work before the current version, which largely reimplemented the code execution system but still has a few missing features. I need to either add some additional processing of executable so that arguments work (probably something like shlex.split()), or add a new option for arguments so that you can do something like args=....

@akdor1154
Copy link
Author

sorta related if you end up looking at this - I tried to wrap my executor in a local script, but it looks like this doesn't work either (through no fault of your own)

```{.bash .cb-nb executor="./local.sh"}
echo hi
```
``` {.error .sysConfigError}
SYS CONFIG ERROR in "post.md" near line 88:
Could not find executable "local.sh"
```

I think this is because of the (surprising to me) behvaiour of Path.as_posix() -

import pathlib
p = pathlib.Path("./local.sh")
print(p.as_posix())
# "local.sh"

:(

gpoore added a commit that referenced this issue May 26, 2022
…stom executables relative to the working directory (#52), added first-chunk setting args
@gpoore
Copy link
Owner

gpoore commented May 26, 2022

The new dev version on GitHub adds a new setting executable_opts. So now you should be able to do something like this (not sure if you need the /usr/bin/fish for your setup):

```{.bash .cb-nb session=dock executable=podman executable_opts="run --name mine -v .:/demo -it ubuntu:21.10 /usr/bin/fish"}
set -e
cd /demo/demo
pwd
```

I've also changed the handling of executable, so things like executable="./local.sh" should work now.

Finally, I've added a new settings args for specifying command-line arguments that are passed to your code. Code execution now defaults to {executable} {executable_opts} {source} {args}, where {source} is a temp file containing the code from the code block.

Let me know if these new settings have any significant limitations for the sort of thing you are trying to do.

I'm working on a few unrelated features, and as soon as those are finished there will be a new release and a new version on PyPI, probably within a few days.

@gpoore gpoore added the enhancement New feature or request label May 26, 2022
@gpoore gpoore closed this as completed Jul 8, 2022
@akdor1154
Copy link
Author

Woohoo, that looks pretty general to any situation! Ill have a play with the new release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants