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,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()
|
||||
Reference in New Issue
Block a user