feat: Add Ruff linting, pre-commit hooks, and build scripts
- Configure Ruff for linting and formatting with pre-commit hooks - Add Makefile with convenient commands for development workflow - Create build and upload scripts for Gitea package registry - Update README with documentation for new features - Fix code quality issues identified by Ruff - Add development dependencies (ruff, pre-commit) to pyproject.toml - Update Python version requirement to >=3.9 - Add template for Gitea PyPI configuration - Bump version to 0.3.0 - All tests passing and code properly formatted
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# This file makes the scripts directory a Python package
|
||||
@@ -0,0 +1,85 @@
|
||||
"""
|
||||
Build and upload script for paroles-net-scraper package
|
||||
"""
|
||||
|
||||
import importlib.util
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def run_command(cmd):
|
||||
"""Run a command and handle errors."""
|
||||
print(f"Running: {' '.join(cmd)}")
|
||||
try:
|
||||
subprocess.run(cmd, check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error running command: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point for the build and upload script."""
|
||||
# Get project root directory
|
||||
project_root = Path(__file__).parent.parent.absolute()
|
||||
os.chdir(project_root)
|
||||
|
||||
# Check if we're in the right directory
|
||||
if not (project_root / "pyproject.toml").exists():
|
||||
print("Error: pyproject.toml not found.")
|
||||
sys.exit(1)
|
||||
|
||||
# Install twine if not already installed
|
||||
if importlib.util.find_spec("twine") is None:
|
||||
print("Installing twine...")
|
||||
run_command(["uv", "pip", "install", "twine"])
|
||||
|
||||
# Clean previous builds
|
||||
print("Cleaning previous builds...")
|
||||
dist_dir = project_root / "dist"
|
||||
if dist_dir.exists():
|
||||
shutil.rmtree(dist_dir)
|
||||
|
||||
# Build the package
|
||||
print("Building package...")
|
||||
run_command(["uv", "build"])
|
||||
|
||||
# Check if build was successful
|
||||
if not dist_dir.exists() or not any(dist_dir.iterdir()):
|
||||
print("Error: Build failed or no files created in dist/")
|
||||
sys.exit(1)
|
||||
|
||||
print("Build successful. Files created:")
|
||||
for f in dist_dir.iterdir():
|
||||
print(f" {f.name}")
|
||||
|
||||
# Check if .pypirc exists
|
||||
pypirc_path = Path.home() / ".pypirc"
|
||||
if not pypirc_path.exists():
|
||||
print(
|
||||
"Warning: ~/.pypirc not found. Please create it with your "
|
||||
"Gitea credentials:"
|
||||
)
|
||||
print("")
|
||||
print("[distutils]")
|
||||
print("index-servers = gitea")
|
||||
print("")
|
||||
print("[gitea]")
|
||||
print("repository = https://gitea.parano.ch/api/packages/herel/pypi")
|
||||
print("username = herel")
|
||||
print("password = YOUR_GITEA_TOKEN")
|
||||
print("")
|
||||
print("Replace YOUR_GITEA_TOKEN with a personal access token from Gitea.")
|
||||
sys.exit(1)
|
||||
|
||||
# Upload to Gitea PyPI registry
|
||||
print("Uploading to Gitea PyPI registry...")
|
||||
run_command(["twine", "upload", "--repository", "gitea", "dist/*"])
|
||||
|
||||
print("Package uploaded successfully to Gitea!")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Executable
+68
@@ -0,0 +1,68 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Script to build and upload Python package to Gitea PyPI registry
|
||||
# Usage: ./scripts/build_and_upload.sh
|
||||
|
||||
set -e # Exit on any error
|
||||
|
||||
echo "=== Building and Uploading Package to Gitea ==="
|
||||
|
||||
# Create scripts directory if it doesn't exist
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
||||
cd "$PROJECT_ROOT"
|
||||
|
||||
# Check if we're in the right directory
|
||||
if [[ ! -f "pyproject.toml" ]]; then
|
||||
echo "Error: pyproject.toml not found. Please run this script from the project root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Install twine if not already installed
|
||||
if ! command -v twine &> /dev/null; then
|
||||
echo "Installing twine..."
|
||||
uv pip install twine
|
||||
fi
|
||||
|
||||
# Clean previous builds
|
||||
echo "Cleaning previous builds..."
|
||||
rm -rf dist/
|
||||
|
||||
# Build the package
|
||||
echo "Building package..."
|
||||
uv build
|
||||
|
||||
# Check if build was successful
|
||||
if [[ ! -d "dist" ]] || [[ -z "$(ls -A dist)" ]]; then
|
||||
echo "Error: Build failed or no files created in dist/"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Build successful. Files created:"
|
||||
ls -la dist/
|
||||
|
||||
# Upload to Gitea PyPI registry
|
||||
echo "Uploading to Gitea PyPI registry..."
|
||||
echo "Note: You need to have ~/.pypirc configured with Gitea credentials"
|
||||
echo "See: https://docs.gitea.com/usage/packages/pypi"
|
||||
|
||||
# Check if .pypirc exists
|
||||
if [[ ! -f "$HOME/.pypirc" ]]; then
|
||||
echo "Warning: ~/.pypirc not found. Please create it with your Gitea credentials:"
|
||||
echo ""
|
||||
echo "[distutils]"
|
||||
echo "index-servers = gitea"
|
||||
echo ""
|
||||
echo "[gitea]"
|
||||
echo "repository = https://gitea.parano.ch/api/packages/herel/pypi"
|
||||
echo "username = herel"
|
||||
echo "password = YOUR_GITEA_TOKEN"
|
||||
echo ""
|
||||
echo "Replace YOUR_GITEA_TOKEN with a personal access token from Gitea."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Upload using twine
|
||||
twine upload --repository gitea dist/*
|
||||
|
||||
echo "Package uploaded successfully to Gitea!"
|
||||
Reference in New Issue
Block a user