-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-python-project.sh
More file actions
executable file
·89 lines (70 loc) · 1.99 KB
/
Copy pathcreate-python-project.sh
File metadata and controls
executable file
·89 lines (70 loc) · 1.99 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
PROJECT_NAME=$1
if [ -z "$PROJECT_NAME" ]; then
echo "Usage: create-python-project <project_name>"
exit 1
fi
echo "🚀 Initializing project '$PROJECT_NAME' with uv..."
# Initialize the project using the src layout, python 3.12, and hatchling
uv init --lib --build-backend hatchling --python 3.12 "$PROJECT_NAME"
cd "$PROJECT_NAME"
echo "📦 Adding development dependencies (ruff, mypy, pytest)..."
uv add --dev ruff mypy pytest
echo "⚙️ Configuring pyproject.toml..."
# Append the configurations for Ruff, Mypy, and Pytest to pyproject.toml
cat << 'EOF' >> pyproject.toml
[tool.ruff]
target-version = "py312"
line-length = 88
src = ["src"]
[tool.ruff.lint]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"N", # pep8-naming
"D", # pydocstyle
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"UP", # pyupgrade
]
ignore = [
"D100", # Missing docstring in public module
"D104", # Missing docstring in public package
]
[tool.ruff.lint.per-file-ignores]
# Relax sensible rules in tests (e.g., allow assertions, ignore missing docstrings)
"tests/**/*" = ["S101", "D"]
[tool.ruff.lint.pydocstyle]
convention = "google"
[tool.mypy]
python_version = "3.12"
strict = true
warn_return_any = true
warn_unused_configs = true
check_untyped_defs = true
disallow_untyped_defs = true
[[tool.mypy.overrides]]
module = "tests.*"
# Do not strictly enforce type hinting on test functions
disallow_untyped_defs = false
[tool.pytest.ini_options]
minversion = "8.0"
addopts = "-ra -q --strict-markers"
testpaths = ["tests"]
EOF
echo "📁 Setting up test directory..."
mkdir -p tests
touch tests/__init__.py
cat << 'EOF' > tests/test_basic.py
def test_example() -> None:
assert True
EOF
echo "✅ Running initial validation checks..."
uv run ruff check .
uv run mypy src
uv run pytest
echo "✨ Project '$PROJECT_NAME' successfully bootstrapped!"