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"
],
"detect_extensions": [
"py"
"py",
"ipynb"
],
"detect_files": [
"requirements.txt",
@ -1428,7 +1429,8 @@
"Pipfile",
"tox.ini",
"setup.py",
"__init__.py"
"__init__.py",
"pixi.toml"
],
"detect_folders": [],
"disabled": false,
@ -5298,7 +5300,8 @@
},
"detect_extensions": {
"default": [
"py"
"py",
"ipynb"
],
"type": "array",
"items": {
@ -5313,7 +5316,8 @@
"Pipfile",
"tox.ini",
"setup.py",
"__init__.py"
"__init__.py",
"pixi.toml"
],
"type": "array",
"items": {
@ -6548,4 +6552,4 @@
]
}
}
}
}

View File

@ -3688,25 +3688,26 @@ 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 `setup.py` 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 `.ipynb` extension.
- A virtual environment is currently activated
### Options
| Option | Default | Description |
| -------------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------- |
| `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` |
| `symbol` | `'🐍 '` | A format string representing the symbol of Python |
| `style` | `'yellow bold'` | The style for the module. |
| `pyenv_version_name` | `false` | Use pyenv to get Python version |
| `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. |
| `detect_extensions` | `['py']` | 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_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. |
| Option | Default | Description |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| `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` |
| `symbol` | `'🐍 '` | A format string representing the symbol of Python |
| `style` | `'yellow bold'` | The style for the module. |
| `pyenv_version_name` | `false` | Use pyenv to get Python version |
| `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. |
| `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', 'pixi.toml']` | Which filenames should trigger this module |
| `detect_folders` | `[]` | Which folders should trigger this module |
| `disabled` | `false` | Disables the `python` module. |
::: tip

View File

@ -35,7 +35,7 @@ impl<'a> Default for PythonConfig<'a> {
style: "yellow bold",
symbol: "🐍 ",
disabled: false,
detect_extensions: vec!["py"],
detect_extensions: vec!["py", "ipynb"],
detect_files: vec![
"requirements.txt",
".python-version",
@ -44,6 +44,7 @@ impl<'a> Default for PythonConfig<'a> {
"tox.ini",
"setup.py",
"__init__.py",
"pixi.toml",
],
detect_folders: vec![],
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()
}
#[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]
fn disabled_scan_for_pyfiles_and_folder_with_ignored_py_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;