Skip to main content

A Powerline segment for showing the venv prompt.

Project description

powerline-venvprompt

powerline-venvprompt is a Powerline status segment that displays the prompt set by the venv --prompt option.

For example, if a virtual environment was created with the command python3 -m venv venv --prompt "my_prompt", the prompt will be "my_prompt" instead of "venv" or the name of the folder containing venv.

Installation

  1. Make sure Powerline is installed and functioning and that you have a custom configuration (most likely in ~/.config/powerline).

  2. Install the package.

python3 -m pip install --user powerline-venvprompt
  1. Add to your theme.

Typically, the config.json file that controls your Powerline setup is in ~/.config/powerline. The theme itself will be in ~/.config/powerline/themes/shell. Add the following lines to your theme JSON file (note the segment specification uses an underscore, not a hyphen):

{
    "function": "powerline_venvprompt.segments.prompt",
    "priority": 10
},

Set the priority however you like.

powerline-venvprompt takes the place of the powerline.segments.common.env.virtualenv segment, so if that one is already in your config file you should remove it. If there is no prompt set in the venv, it will display the same thing that powerline.segments.common.env.virtualenv would have shown.

Options

The options for powerline-venvprompt are inherited from the default powerline.segments.common.env.virtualenv segment in version 2.8.3.

  • ignore_venv

If true, the venv virtual environment will be ignored (including the --prompt option). Default value is false.

  • ignore_conda

If true, the conda virtual environment will be ignored. Default value is false.

  • ignored_names

A list of names that will be ignored. If a virtual environment has one of these names (and no explicit prompt defined), the prompt will be the name of the folder containing venv.

Here is an example configuration with the default values:

{
    "function": "powerline_venvprompt.segments.prompt",
    "priority": 10,
    "args": {
        "ignore_venv": false,
        "ignore_conda": false,
        "ignored_names": ["venv", ".venv"]
    }
},

Troubleshooting

If you activate a virtual environment and the prompt isn't displayed, here are some potential solutions.

Restart Powerline

Use the command powerline-daemon -r to restart Powerline after any change to your configuration.

Check for errors

Use the command powerline-lint to display configuration errors.

You may see a number of unrelated issues (my installation has over a dozen errors in the stock colorschemes/vim/__main__.json file). Ignore those.

You will see the following message. You can ignore this. powerline-venvprompt uses the same virtualenv color scheme that the default powerline.segments.common.env.virtualenv uses.

found highlight group prompt not defined in the following colorschemes: default, solarized
(If not specified otherwise in documentation, highlight group for function segments
is the same as the function name.)
  in "~/.config/powerline/themes/shell/steve.json", line 17, column 49:
     ...  "powerline_venvprompt.segments.prompt",

If you see the message "failed to import module powerline_venvprompt.segments" that might mean Powerline is not searching the folder containing your powerline_venvprompt folder. If this is the case, add the folder to your config.json file. Use the command python3 -m pip show powerline-venvprompt | grep Location to determine the required path.

$ pip show powerline-venvprompt | grep Location
Location: /Users/steve/Library/Python/3.11/lib/python/site-packages

Add this to your config.json file:

"paths": [
    "/Users/steve/Library/Python/3.11/lib/python/site-packages"
],

If all else fails, use GitHub Issues to report your problem and I'll do my best to help.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

powerline-venvprompt-1.0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

powerline_venvprompt-1.0.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file powerline-venvprompt-1.0.1.tar.gz.

File metadata

  • Download URL: powerline-venvprompt-1.0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for powerline-venvprompt-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cd5e8ce71929a8485f0c648a4915c958ab73f7e7d9a84ba371a9c4601d8fa838
MD5 1b0c6fe20b203ee6aef2e5af70b658bc
BLAKE2b-256 90fd1e3609e835d11b93257dfd1612b4bf3c42f86ce9586992981c1c81a573cd

See more details on using hashes here.

File details

Details for the file powerline_venvprompt-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for powerline_venvprompt-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 553305b9dbd894fab29aa91e655fe66ca14c25773b9593eb9787dab960552851
MD5 af5c2f6c6257fa4c3b5f67cc9c024f7c
BLAKE2b-256 4655cd1637e1ffd9e382148a1096dbdb56ef3ef0aa8c8907b0fa09b5470711f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page