From 1478f8c2e9841e3848703bf0d958b6b063e387f0 Mon Sep 17 00:00:00 2001 From: Thomas O'Donnell Date: Thu, 22 Aug 2019 00:54:22 +0200 Subject: [PATCH] Add support for detecting Python from Pipenv files (#221) Added the ability to enable the Python module based on the existence of the a `Pipfile`. --- docs/config/README.md | 1 + src/modules/python.rs | 8 +++++++- tests/testsuite/python.rs | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/config/README.md b/docs/config/README.md index e1c6cdcc..22f96098 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -421,6 +421,7 @@ 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 `pyproject.toml` file - The current directory contains a file with the `.py` extension +- The current directory contains a `Pipfile` file ### Options diff --git a/src/modules/python.rs b/src/modules/python.rs index b651e1d5..d465e6da 100644 --- a/src/modules/python.rs +++ b/src/modules/python.rs @@ -15,10 +15,16 @@ use super::{Context, Module}; /// - Current directory contains a `requirements.txt` file /// - Current directory contains a `pyproject.toml` file /// - Current directory contains a file with the `.py` extension +/// - Current directory contains a `Pipfile` file pub fn module<'a>(context: &'a Context) -> Option> { let is_py_project = context .new_scan_dir() - .set_files(&["requirements.txt", ".python-version", "pyproject.toml"]) + .set_files(&[ + "requirements.txt", + ".python-version", + "pyproject.toml", + "Pipfile", + ]) .set_extensions(&["py"]) .scan(); diff --git a/tests/testsuite/python.rs b/tests/testsuite/python.rs index 66515b43..6b90695a 100644 --- a/tests/testsuite/python.rs +++ b/tests/testsuite/python.rs @@ -57,6 +57,23 @@ fn folder_with_pyproject_toml() -> io::Result<()> { Ok(()) } +#[test] +#[ignore] +fn folder_with_pipfile() -> io::Result<()> { + let dir = common::new_tempdir()?; + File::create(dir.path().join("Pipfile"))?; + + let output = common::render_module("python") + .arg("--path") + .arg(dir.path()) + .output()?; + let actual = String::from_utf8(output.stdout).unwrap(); + + let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.6.9")); + assert_eq!(expected, actual); + Ok(()) +} + #[test] #[ignore] fn folder_with_py_file() -> io::Result<()> {