1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-12-12 14:17:45 +00:00

feat(python): detect pixi and ipynb files (#6228)

This commit is contained in:
Baku Kim 2024-09-26 17:53:18 +09:00 committed by GitHub
parent ee563f93d3
commit 36134d896b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 50 additions and 20 deletions

View File

@ -1419,7 +1419,8 @@
"VIRTUAL_ENV" "VIRTUAL_ENV"
], ],
"detect_extensions": [ "detect_extensions": [
"py" "py",
"ipynb"
], ],
"detect_files": [ "detect_files": [
"requirements.txt", "requirements.txt",
@ -1428,7 +1429,8 @@
"Pipfile", "Pipfile",
"tox.ini", "tox.ini",
"setup.py", "setup.py",
"__init__.py" "__init__.py",
"pixi.toml"
], ],
"detect_folders": [], "detect_folders": [],
"disabled": false, "disabled": false,
@ -5298,7 +5300,8 @@
}, },
"detect_extensions": { "detect_extensions": {
"default": [ "default": [
"py" "py",
"ipynb"
], ],
"type": "array", "type": "array",
"items": { "items": {
@ -5313,7 +5316,8 @@
"Pipfile", "Pipfile",
"tox.ini", "tox.ini",
"setup.py", "setup.py",
"__init__.py" "__init__.py",
"pixi.toml"
], ],
"type": "array", "type": "array",
"items": { "items": {

View File

@ -3688,13 +3688,15 @@ By default, the module will be shown if any of the following conditions are met:
- The current directory contains a `requirements.txt` file - The current directory contains a `requirements.txt` file
- The current directory contains a `setup.py` file - The current directory contains a `setup.py` file
- The current directory contains a `tox.ini` file - The current directory contains a `tox.ini` file
- The current directory contains a `pixi.toml` file
- The current directory contains a file with the `.py` extension. - The current directory contains a file with the `.py` extension.
- The current directory contains a file with the `.ipynb` extension.
- A virtual environment is currently activated - A virtual environment is currently activated
### Options ### Options
| Option | Default | Description | | Option | Default | Description |
| -------------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- | | -------------------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| `format` | `'via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style)'` | The format for the module. | | `format` | `'via [${symbol}${pyenv_prefix}(${version} )(\($virtualenv\) )]($style)'` | The format for the module. |
| `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` | | `version_format` | `'v${raw}'` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `'🐍 '` | A format string representing the symbol of Python | | `symbol` | `'🐍 '` | A format string representing the symbol of Python |
@ -3702,10 +3704,9 @@ By default, the module will be shown if any of the following conditions are met:
| `pyenv_version_name` | `false` | Use pyenv to get Python version | | `pyenv_version_name` | `false` | Use pyenv to get Python version |
| `pyenv_prefix` | `'pyenv'` | Prefix before pyenv version display, only used if pyenv is used | | `pyenv_prefix` | `'pyenv'` | Prefix before pyenv version display, only used if pyenv is used |
| `python_binary` | `['python', 'python3', 'python2']` | Configures the python binaries that Starship should executes when getting the version. | | `python_binary` | `['python', 'python3', 'python2']` | Configures the python binaries that Starship should executes when getting the version. |
| `detect_extensions` | `['py']` | Which extensions should trigger this module | | `detect_extensions` | `['py', 'ipynb']` | Which extensions should trigger this module |
| `detect_files` | `['.python-version', 'Pipfile', '__init__.py', 'pyproject.toml', 'requirements.txt', 'setup.py', 'tox.ini']` | Which filenames should trigger this module | | `detect_files` | `['.python-version', 'Pipfile', '__init__.py', 'pyproject.toml', 'requirements.txt', 'setup.py', 'tox.ini', 'pixi.toml']` | Which filenames should trigger this module |
| `detect_folders` | `[]` | Which folders should trigger this module | | `detect_folders` | `[]` | Which folders should trigger this module |
| `detect_env_vars` | `["VIRTUAL_ENV"]` | Which environmental variables should trigger this module |
| `disabled` | `false` | Disables the `python` module. | | `disabled` | `false` | Disables the `python` module. |
::: tip ::: tip

View File

@ -35,7 +35,7 @@ impl<'a> Default for PythonConfig<'a> {
style: "yellow bold", style: "yellow bold",
symbol: "🐍 ", symbol: "🐍 ",
disabled: false, disabled: false,
detect_extensions: vec!["py"], detect_extensions: vec!["py", "ipynb"],
detect_files: vec![ detect_files: vec![
"requirements.txt", "requirements.txt",
".python-version", ".python-version",
@ -44,6 +44,7 @@ impl<'a> Default for PythonConfig<'a> {
"tox.ini", "tox.ini",
"setup.py", "setup.py",
"__init__.py", "__init__.py",
"pixi.toml",
], ],
detect_folders: vec![], detect_folders: vec![],
detect_env_vars: vec!["VIRTUAL_ENV"], detect_env_vars: vec!["VIRTUAL_ENV"],

View File

@ -279,6 +279,30 @@ Python 3.7.9 (7e6e2bb30ac5fbdbd443619cae28c51d5c162a02, Nov 24 2020, 10:03:59)
dir.close() dir.close()
} }
#[test]
fn folder_with_pixi_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("pixi.toml"))?.sync_all()?;
check_python2_renders(&dir, None);
check_python3_renders(&dir, None);
check_pyenv_renders(&dir, None);
check_multiple_binaries_renders(&dir, None);
dir.close()
}
#[test]
fn folder_with_ipynb_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("notebook.ipynb"))?.sync_all()?;
check_python2_renders(&dir, None);
check_python3_renders(&dir, None);
check_pyenv_renders(&dir, None);
check_multiple_binaries_renders(&dir, None);
dir.close()
}
#[test] #[test]
fn disabled_scan_for_pyfiles_and_folder_with_ignored_py_file() -> io::Result<()> { fn disabled_scan_for_pyfiles_and_folder_with_ignored_py_file() -> io::Result<()> {
let dir = tempfile::tempdir()?; let dir = tempfile::tempdir()?;