Skip to content

Latest commit

 

History

History
160 lines (115 loc) · 3.4 KB

File metadata and controls

160 lines (115 loc) · 3.4 KB

Development Guide

Setup

  1. Clone the repository:
git clone https://github.com/ilovepdf/iloveimg-python.git
cd iloveimg-python
  1. Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or
venv\Scripts\activate     # Windows
  1. Install dependencies:
pip install -r requirements_dev.txt
pip install -e .

The -e . flag installs the package in editable mode.

Pyright Configuration

Create pyrightconfig.json in the project root:

{
  "extraPaths": ["/path/to/lib/python/site-packages"]
}

Environment Variables

Copy .env.example to .env and configure:

cp .env.example .env

Required variables:

  • ILOVEIMG_PUBLIC_KEY - Your API public key
  • ILOVEIMG_SECRET_KEY - Your API secret key

Optional variables:

  • PYTHONLOGLEVEL - Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • FOLDER_SAMPLE_PATH - Path to sample files for testing

Running Tests

# Unit tests only
pytest tests/unit/

# Integration tests (requires API keys)
pytest tests/integration/

# All tests
pytest tests/

Code Style

The project uses:

  • Black for formatting
  • Ruff for fast linting and formatting
  • Pyright for static type checking

Run formatting and linting:

black .
ruff check .
ruff format .
pyright iloveimg/

For pre-commit hooks (autom

Adding a New Task

  1. Create iloveimg/newtask_task.py extending Task
  2. Add unit tests in tests/unit/
  3. Add integration test in tests/integration/
  4. Add sample script in samples/
  5. Update iloveimg/__init__.py to export the task

Project Structure

iloveimg-python/
├── iloveimg/           # Core library
│   ├── *task.py        # Task implementations
│   ├── task.py         # Base task class
│   ├── exceptions/     # Custom exceptions
│   └── validators/     # Input validators
├── samples/            # Usage examples
├── tests/              # Unit & integration tests
├── .docker/            # Docker configurations
├── README.md           # Main documentation
├── INSTALL.md          # Installation guide
└── DEVELOPMENT.md      # This file

Docker

Build and run tests in Docker using docker-compose:

# Build images
docker-compose -f .docker/docker-compose.yml build

# Run tests with a specific Python version
docker-compose -f .docker/docker-compose.yml run --rm python310 pytest tests/unit

# Run all tests
docker-compose -f .docker/docker-compose.yml run --rm python310 pytest tests/

Available Python versions: python310, python311, python312, python313, python314

For full Docker instructions, see .docker/README.md.

Getting Help

Versioning

  • The version is defined only in pyproject.toml[project].version.

Example: to bump from 1.0.1 to 1.0.2, change in pyproject.toml:

  • version = "1.0.1"version = "1.0.2"

For a new release, just update the version in pyproject.toml.

Publishing to PyPI

To publish a new version to PyPI:

  1. Update the version in pyproject.toml.
  2. Build the distributions:
pip install build twine
python -m build
  1. Upload to PyPI:
TWINE_USERNAME="__token__"
TWINE_PASSWORD="<your PyPI token>"
twine upload dist/*