Skip to content

Commit

Permalink
Merge pull request #78 from databio/dev
Browse files Browse the repository at this point in the history
Release 0.7.2
  • Loading branch information
nsheff authored Jun 24, 2021
2 parents 1f033e8 + 49fa766 commit 96c2d71
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 16 deletions.
2 changes: 1 addition & 1 deletion bulker/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.1"
__version__ = "0.7.2"
30 changes: 18 additions & 12 deletions bulker/bulker.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ def bulker_load(manifest, cratevars, bcfg, exe_jinja2_template,
manifest_name,
cratevars['tag'])
if not os.path.isabs(crate_path):
crate_path = os.path.join(os.path.dirname(bcfg._file_path), crate_path)
crate_path = os.path.join(os.path.dirname(bcfg["__internal"].file_path), crate_path)

_LOGGER.debug("Crate path: {}".format(crate_path))
_LOGGER.debug("cratevars: {}".format(cratevars))
Expand Down Expand Up @@ -483,7 +483,7 @@ def bulker_load(manifest, cratevars, bcfg, exe_jinja2_template,
imp_cratevars['crate'],
imp_cratevars['tag'])
if not os.path.isabs(imp_crate_path):
imp_crate_path = os.path.join(os.path.dirname(bcfg._file_path), imp_crate_path)
imp_crate_path = os.path.join(os.path.dirname(bcfg["__internal"].file_path), imp_crate_path)
if not os.path.exists(imp_crate_path):
_LOGGER.error("Nonexistent crate: '{}' from '{}'. Reloading...".format(imp, imp_crate_path))
reload_import = True
Expand Down Expand Up @@ -533,7 +533,7 @@ def host_tool_specific_args(bcfg, pkg, hosttool_arg_key):
if os.path.isabs(pkg["singularity_image_folder"]):
sif = pkg["singularity_image_folder"]
else:
sif = os.path.join(os.path.dirname(bcfg._file_path),
sif = os.path.join(os.path.dirname(bcfg["__internal"].file_path),
pkg["singularity_image_folder"])

pkg["singularity_fullpath"] = os.path.join(
Expand Down Expand Up @@ -756,10 +756,10 @@ def bulker_activate(bulker_config, cratelist, echo=False, strict=False, prompt=T
if os.path.basename(shellpath) == "bash":
if strict:
rcfile = mkabs(bulker_config.bulker.rcfile_strict,
os.path.dirname(bulker_config._file_path))
os.path.dirname(bulker_config["__internal"].file_path))
else:
rcfile = mkabs(bulker_config.bulker.rcfile,
os.path.dirname(bulker_config._file_path))
os.path.dirname(bulker_config["__internal"].file_path))

shell_list.append("--rcfile")
shell_list.append(rcfile)
Expand All @@ -770,11 +770,11 @@ def bulker_activate(bulker_config, cratelist, echo=False, strict=False, prompt=T
if strict:
rcfolder = mkabs(os.path.join(
os.path.dirname(bulker_config.bulker.rcfile_strict),
"zsh_start_strict"), os.path.dirname(bulker_config._file_path))
"zsh_start_strict"), os.path.dirname(bulker_config["__internal"].file_path))
else:
rcfolder = mkabs(os.path.join(
os.path.dirname(bulker_config.bulker.rcfile_strict),
"zsh_start"), os.path.dirname(bulker_config._file_path))
"zsh_start"), os.path.dirname(bulker_config["__internal"].file_path))

new_env["ZDOTDIR"] = rcfolder
_LOGGER.debug("ZDOTDIR: {}".format(new_env["ZDOTDIR"]))
Expand Down Expand Up @@ -844,6 +844,7 @@ def maybe_quote(item):
global PROC
PROC = psutil.Popen(merged_command, shell=True, preexec_fn=os.setsid)
PROC.communicate()
sys.exit(PROC.returncode)
#command[0:0] = ["export", "PATH=\"{}\"".format(newpath)]
#subprocess.call(merged_command)

Expand Down Expand Up @@ -1047,12 +1048,12 @@ def prep_load(bulker_config, crate_registry_paths, manifest=None, build=False):
shell_template_jinja = None

exe_template = mkabs(bulker_config.bulker.executable_template,
os.path.dirname(bulker_config._file_path))
os.path.dirname(bulker_config["__internal"].file_path))
build_template = mkabs(bulker_config.bulker.build_template,
os.path.dirname(bulker_config._file_path))
os.path.dirname(bulker_config["__internal"].file_path))
try:
shell_template = mkabs(bulker_config.bulker.shell_template,
os.path.dirname(bulker_config._file_path))
os.path.dirname(bulker_config["__internal"].file_path))
except AttributeError:
_LOGGER.error("You need to re-initialize your bulker config or add a 'shell_template' attribute.")
sys.exit(1)
Expand Down Expand Up @@ -1289,7 +1290,7 @@ def main():
manifest_name,
cratevars['tag'])
if not os.path.isabs(crate_path):
crate_path = os.path.join(os.path.dirname(bcfg._file_path), crate_path)
crate_path = os.path.join(os.path.dirname(bulker_config["__internal"].file_path), crate_path)
print("Crate path: {}".format(crate_path))


Expand Down Expand Up @@ -1359,13 +1360,18 @@ def main():
manifest, cratevars, exe_template_jinja, shell_template_jinja, build_template_jinja = prep_load(
bulker_config, args.crate_registry_paths, args.manifest, args.build)

bulker_load(manifest, cratevars, bulker_config,
try:
bulker_load(manifest, cratevars, bulker_config,
exe_jinja2_template=exe_template_jinja,
shell_jinja2_template=shell_template_jinja,
crate_path=args.path,
build=build_template_jinja,
force=args.force,
recurse=args.recurse)
except Exception as e:
print(f'Bulker load failed: {e}')
sys.exit(1)


if args.command == "reload":
bulker_config.make_writable()
Expand Down
1 change: 0 additions & 1 deletion bulker/templates/start.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
source "${BULKERSHELLRC}"
echo $BULKERPROMPT
if [ -z ${BULKERPROMPT+x} ]; then echo "No prompt change"; else PS1="${BULKERPROMPT}"; fi
export PATH="${BULKERPATH}:${PATH}"
7 changes: 6 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Changelog

## [0.7.2] -- 2021-06-24
- Update to yacman 0.8.0, fixing references to internal config attributes.
- Add documentation and clarity for the `shell_prompt` option
- Fixed bug with relative crate root folders.

## [0.7.1] -- 2021-03-03
-- Fixed bug in bulker reload.
- Fixed bug in bulker reload.

## [0.7.0] -- 2021-03-02
- EXPERIMENTAL: Added `bulker cwl2man` to create a bulker manifest from a CWL file.
Expand Down
71 changes: 71 additions & 0 deletions docs/custom_prompts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Customizing bulker prompts

By default, when you activate a crate, bulker will change your prompt. You can customize it by specifying the `shell_prompt` attribute in your bulker config. *Make sure you enclose the value in single quotes*; if you use double-quotes the parser will re-escape your prompt escape sequences and break stuff. Here are some examples:

In these examples we'll activate the crate like this:

```console
bulker activate databio/lab
```

The variables that could be displayed are these:

- namespace: `databio`
- crate name: `lab`
- username: `nsheff`
- host: `zither`
- working directory: `code`

# Default prompt

The default bulker prompt shows you the name of the crate you've activated, colored in yellow. Bulker uses `\b` to indicate the name of the bulker namespace and crate. The default prompt is the equivalent of putting this in your config:

```yaml
shell_prompt: '\[\033[01;93m\]\b|\[\033[00m\]\[\033[01;34m\]\w\[\033[00m\]\$ '
```
![](img/prompts/default.png)
## Include username and hostname
In addition the bulker-provided `\b`, there are lots of other shell-provided variables you can use, like `\u` for username and `\h` for hostname, and `\W` for working directory path. You can look up lists of these by searching for *customizing bash PS1 prompt*. Here's a simple sample using *username* and *hostname*:

```yaml
shell_prompt: '[\u@\h(\b) \W] $ '
```

![](img/prompts/prompt1.png)

## Change colors

You can al;so use any terminal colors compatible with your terminal.


```yaml
shell_prompt: '\u@\h|\e[94m\b\[\e[00m\]:\e[90m\W\e[39m $ '
```

![](img/prompts/prompt2.png)


## Emoji

Yes, you can even put emoji in your prompt, if that's your thing:

```yaml
shell_prompt: '⚓ \e[94m\b\[\e[00m\]:\e[90m\W\e[39m $ '
```

![](img/prompts/prompt3.png)


## Date/time

This example uses a custom date/time format along with 256-color codes:

```yaml
shell_prompt: '\D{%y/%m/%d %H:%M}⚓ \e[38;5;141m\b\[\e[00m\]:\e[38;5;29m\W\e[39m $ '
```

![](img/prompts/prompt4.png)
Binary file added docs/img/prompts/default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/prompts/prompt1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/prompts/prompt2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/prompts/prompt3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/prompts/prompt4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ nav:
- Start an exploratory shell: shell.md
- Use bulker in a multi-user environment: multi_user_environment.md
- Host- and tool-specific settings: settings.md
- Custom prompts: custom_prompts.md
- Use a bulker registry: registry.md
- Use images with entrypoints: entrypoint.md
- Disable user or network map: advanced_templates.md
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-all.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
yacman>=0.6.6
yacman>=0.8.1
pyyaml>=5.1
logmuse>=0.2.0
jinja2
Expand Down

0 comments on commit 96c2d71

Please sign in to comment.