Last active
August 20, 2024 04:28
-
-
Save mohit2152sharma/e1437176adb9eafffbe4f5de36ac3c9e to your computer and use it in GitHub Desktop.
Script to check if the given directory is a python project or not. (Assumes it to be a python project if there exists `requirements.txt` or `pyproject.toml` or any file ending with `.py`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
is_python_project() { | |
local dir=$1 | |
local filename | |
filename=$(basename "$dir") | |
# assumes a directory is a python project, if it has files which are usually found in python project root directory like | |
# requirements.txt, pyproject.toml and setup.py | |
if [[ -f "$dir"/requirements.txt || -f "$dir"/pyproject.toml || -f "$dir"/setup.py || "$filename" == *.py ]]; then | |
echo "${dir} is a python project" | |
return 0 | |
else | |
available_dirs=$(ls "$dir") | |
if [[ -n "$available_dirs" ]]; then | |
for file in "$dir"/*; do | |
if [[ -d "$file" ]]; then | |
is_python_project "$file" | |
fi | |
done | |
fi | |
fi | |
return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment