Skip to content

Commit eee346e

Browse files
committed
update
1 parent 9a232cd commit eee346e

File tree

23 files changed

+668
-21
lines changed

23 files changed

+668
-21
lines changed

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"python.testing.pytestArgs": ["tests"],
3+
"python.testing.unittestEnabled": false,
4+
"python.testing.pytestEnabled": true
5+
}

Dockerfile

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,45 @@
11
FROM python:3.11-slim AS base
2-
ENV LANG=C.UTF-8 \
3-
LC_ALL=C.UTF-8 \
4-
PYTHONDONTWRITEBYTECODE=1 \
5-
PYTHONFAULTHANDLER=1
2+
3+
# Set Python environment variables
4+
ENV PYTHONDONTWRITEBYTECODE=1 \
5+
PYTHONUNBUFFERED=1 \
6+
PYTHONFAULTHANDLER=1 \
7+
LANG=C.UTF-8 \
8+
LC_ALL=C.UTF-8
9+
10+
# Install basic dependencies
611
RUN apt-get update && \
7-
apt-get install -y --no-install-recommends gcc && \
8-
apt-get install -y ffmpeg libsm6 libxext6 && \
9-
apt-get install -y zbar-tools && \
10-
apt-get install -y libzbar-dev
11-
RUN pip install --upgrade pip
12+
apt-get install -y --no-install-recommends \
13+
gcc \
14+
&& rm -rf /var/lib/apt/lists/*
15+
16+
# Upgrade pip
17+
RUN pip install --no-cache-dir --upgrade pip
1218

1319
FROM base AS builder
20+
21+
# Create and activate virtual environment
1422
RUN python -m venv /.venv
1523
ENV PATH="/.venv/bin:$PATH"
16-
COPY requirements.txt .
17-
RUN pip install -r requirements.txt
24+
25+
# Install dependencies
26+
COPY pyproject.toml .
27+
RUN pip install --no-cache-dir .
1828

1929
FROM base as runtime
30+
31+
# Set working directory
2032
WORKDIR /app
33+
34+
# Copy virtual environment from builder
2135
COPY --from=builder /.venv /.venv
2236
ENV PATH="/.venv/bin:$PATH"
23-
COPY . /app
37+
38+
# Copy application code
39+
COPY . .
40+
41+
# Expose port (adjust if needed)
2442
EXPOSE 8000
43+
44+
# Run the application
2545
CMD ["python", "main.py"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024-present Your Name or Organization
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
1-
package:
2-
pip freeze > requirements.txt
3-
venv:
4-
source ./venv/bin/activate
5-
build:
6-
docker build -t template-python .
1+
.PHONY: help install dev-install test format lint type-check clean build run
2+
3+
help: ## Show this help menu
4+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
5+
6+
install: ## Install production dependencies
7+
uv pip install .
8+
9+
dev-install: ## Install development dependencies
10+
uv pip install -e ".[dev]"
11+
12+
test: ## Run tests with pytest
13+
pytest -v --cov=src --cov-report=term-missing
14+
15+
format: ## Format code with black and isort
16+
black .
17+
isort .
18+
19+
lint: ## Lint code with ruff
20+
ruff check .
21+
22+
type-check: ## Run type checking with mypy
23+
mypy src tests
24+
25+
clean: ## Clean build artifacts
26+
rm -rf build/ dist/ *.egg-info/ .coverage .pytest_cache/ .mypy_cache/ .ruff_cache/
27+
find . -type d -name __pycache__ -exec rm -rf {} +
28+
29+
build: ## Build Docker image
30+
docker build -t template-python .
31+
32+
run: ## Run Docker container
33+
docker run -it --rm template-python
34+
35+
package: ## Create requirements.txt
36+
uv pip freeze > requirements.txt
37+
38+
setup: ## Initial project setup
39+
uv venv
40+
$(MAKE) dev-install
41+
cp .env.example .env

README.md

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,109 @@
1-
# template-python
2-
Template python project
1+
# Python Project Template
2+
3+
A modern Python project template with best practices for development, testing, and deployment.
4+
5+
## Features
6+
7+
- Modern Python (3.11+) project structure
8+
- Development tools configuration (pytest, black, isort, mypy, ruff)
9+
- Docker support
10+
- GitHub Actions ready
11+
- Comprehensive documentation structure
12+
- Jupyter notebook support
13+
14+
## Project Structure
15+
16+
```
17+
.
18+
├── docs/ # Documentation files
19+
├── notebooks/ # Jupyter notebooks
20+
├── src/ # Source code
21+
│ ├── common/ # Common utilities and shared code
22+
│ ├── modules/ # Feature modules
23+
│ │ └── api/ # API related code
24+
│ ├── shared/ # Shared resources
25+
│ └── utils/ # Utility functions
26+
└── tests/ # Test files
27+
```
28+
29+
## Getting Started
30+
31+
### Prerequisites
32+
33+
- Python 3.11 or higher
34+
- [uv](https://github.com/astral-sh/uv) for dependency management
35+
36+
### Installation
37+
38+
1. Clone the repository:
39+
```bash
40+
git clone https://github.com/yourusername/template-python.git
41+
cd template-python
42+
```
43+
44+
2. Create a virtual environment and install dependencies:
45+
```bash
46+
uv venv
47+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
48+
uv pip install -e ".[dev]"
49+
```
50+
51+
3. Copy the environment file and adjust as needed:
52+
```bash
53+
cp .env.example .env
54+
```
55+
56+
### Development
57+
58+
This project uses several development tools:
59+
60+
- **pytest**: Testing framework
61+
- **black**: Code formatting
62+
- **isort**: Import sorting
63+
- **mypy**: Static type checking
64+
- **ruff**: Fast Python linter
65+
66+
Run tests:
67+
```bash
68+
pytest
69+
```
70+
71+
Format code:
72+
```bash
73+
black .
74+
isort .
75+
```
76+
77+
Run type checking:
78+
```bash
79+
mypy src tests
80+
```
81+
82+
Run linting:
83+
```bash
84+
ruff check .
85+
```
86+
87+
### Docker
88+
89+
Build the Docker image:
90+
```bash
91+
make build
92+
```
93+
94+
Run the container:
95+
```bash
96+
make run
97+
```
98+
99+
## Contributing
100+
101+
1. Fork the repository
102+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
103+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
104+
4. Push to the branch (`git push origin feature/amazing-feature`)
105+
5. Open a Pull Request
106+
107+
## License
108+
109+
This project is licensed under the MIT License - see the LICENSE file for details.

docs/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Project Documentation
2+
3+
Welcome to the documentation for the Python Template Project.
4+
5+
## Table of Contents
6+
7+
1. [Getting Started](getting-started.md)
8+
2. [Project Structure](project-structure.md)
9+
3. [Development Guide](development.md)
10+
4. [API Documentation](api.md)
11+
5. [Testing Guide](testing.md)
12+
6. [Deployment Guide](deployment.md)
13+
14+
## Overview
15+
16+
This template provides a foundation for Python projects with:
17+
18+
- Modern Python project structure
19+
- Development tooling configuration
20+
- Testing framework setup
21+
- Docker support
22+
- Documentation templates
23+
- CI/CD examples
24+
25+
## Quick Links
26+
27+
- [Installation Guide](getting-started.md#installation)
28+
- [Development Setup](development.md#setup)
29+
- [Running Tests](testing.md#running-tests)
30+
- [Docker Guide](deployment.md#docker)
31+
- [API Reference](api.md#endpoints)
32+
33+
## Contributing
34+
35+
See our [Contributing Guide](CONTRIBUTING.md) for details on how to contribute to this project.
36+
37+
## License
38+
39+
This project is licensed under the MIT License - see the [LICENSE](../LICENSE) file for details.

main.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,59 @@
1-
print("Hello, World!")
1+
#!/usr/bin/env python3
2+
3+
import logging
4+
import os
5+
from pathlib import Path
6+
from typing import Optional
7+
8+
# Configure logging
9+
logging.basicConfig(
10+
level=logging.INFO,
11+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
12+
)
13+
logger = logging.getLogger(__name__)
14+
15+
16+
def setup_environment() -> dict[str, str]:
17+
"""Load environment variables from .env file."""
18+
env_vars = {}
19+
env_path = Path(".env")
20+
21+
if env_path.exists():
22+
with env_path.open() as f:
23+
for line in f:
24+
line = line.strip()
25+
if line and not line.startswith("#"):
26+
key, value = line.split("=", 1)
27+
env_vars[key.strip()] = value.strip()
28+
29+
return env_vars
30+
31+
32+
def main() -> None:
33+
"""Main application entry point."""
34+
try:
35+
# Load environment variables
36+
env_vars = setup_environment()
37+
app_name = env_vars.get("APP_NAME", "template-python")
38+
env = env_vars.get("ENV", "development")
39+
debug = env_vars.get("DEBUG", "false").lower() == "true"
40+
41+
# Configure logging level based on debug setting
42+
if debug:
43+
logging.getLogger().setLevel(logging.DEBUG)
44+
logger.debug("Debug mode enabled")
45+
46+
logger.info(f"Starting {app_name} in {env} environment")
47+
48+
# Your application initialization code here
49+
# For example:
50+
# app = create_app()
51+
# app.run()
52+
53+
except Exception as e:
54+
logger.error(f"Application failed to start: {e}", exc_info=True)
55+
raise
56+
57+
58+
if __name__ == "__main__":
59+
main()

0 commit comments

Comments
 (0)