-
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathproject_info.py
More file actions
47 lines (33 loc) · 1.22 KB
/
project_info.py
File metadata and controls
47 lines (33 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""Resolves project information about the current working directory."""
import shutil
from pathlib import Path
from typing import Literal
def is_pre_commit_installed() -> bool:
return any(shutil.which(tool) for tool in ("pre-commit", "prek"))
def get_default_version_provider() -> Literal[
"commitizen", "cargo", "composer", "npm", "pep621", "poetry", "uv"
]:
pyproject_path = Path("pyproject.toml")
if pyproject_path.is_file():
if "[tool.poetry]" in pyproject_path.read_text():
return "poetry"
if Path("uv.lock").is_file():
return "uv"
return "pep621"
if Path("setup.py").is_file():
return "pep621"
if Path("Cargo.toml").is_file():
return "cargo"
if Path("package.json").is_file():
return "npm"
if Path("composer.json").is_file():
return "composer"
return "commitizen"
def get_default_config_filename() -> Literal["pyproject.toml", ".cz.toml"]:
return "pyproject.toml" if Path("pyproject.toml").is_file() else ".cz.toml"
def get_default_version_scheme() -> Literal["pep440", "semver"]:
return (
"pep440"
if Path("pyproject.toml").is_file() or Path("setup.py").is_file()
else "semver"
)