|
| 1 | +# Development Guide |
| 2 | + |
| 3 | +## Setup |
| 4 | + |
| 5 | +1. Clone the repository: |
| 6 | +```bash |
| 7 | +git clone https://github.com/ilovepdf/ilovepdf-python.git |
| 8 | +cd ilovepdf-python |
| 9 | +``` |
| 10 | + |
| 11 | +2. Create and activate a virtual environment: |
| 12 | +```bash |
| 13 | +python -m venv venv |
| 14 | +source venv/bin/activate # Linux/Mac |
| 15 | +# or |
| 16 | +venv\Scripts\activate # Windows |
| 17 | +``` |
| 18 | + |
| 19 | +3. Install dependencies: |
| 20 | +```bash |
| 21 | +pip install -r requirements_dev.txt |
| 22 | +pip install -e . |
| 23 | +``` |
| 24 | + |
| 25 | +> The `-e .` flag installs the package in editable mode. |
| 26 | +
|
| 27 | +## Pyright Configuration |
| 28 | + |
| 29 | +Create `pyrightconfig.json` in the project root: |
| 30 | + |
| 31 | +```json |
| 32 | +{ |
| 33 | + "extraPaths": ["/path/to/lib/python/site-packages"] |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +## Environment Variables |
| 38 | + |
| 39 | +Copy `.env.example` to `.env` and configure: |
| 40 | + |
| 41 | +```bash |
| 42 | +cp .env.example .env |
| 43 | +``` |
| 44 | + |
| 45 | +Required variables: |
| 46 | +- `ILOVEPDF_PUBLIC_KEY` - Your API public key |
| 47 | +- `ILOVEPDF_SECRET_KEY` - Your API secret key |
| 48 | + |
| 49 | +Optional variables: |
| 50 | +- `PYTHONLOGLEVEL` - Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
| 51 | +- `FOLDER_SAMPLE_PATH` - Path to sample files for testing |
| 52 | + |
| 53 | +## Running Tests |
| 54 | + |
| 55 | +```bash |
| 56 | +# Unit tests only |
| 57 | +pytest tests/unit/ |
| 58 | + |
| 59 | +# Integration tests (requires API keys) |
| 60 | +pytest tests/integration/ |
| 61 | + |
| 62 | +# All tests |
| 63 | +pytest tests/ |
| 64 | +``` |
| 65 | + |
| 66 | +## Code Style |
| 67 | + |
| 68 | +The project uses: |
| 69 | +- **Black** for formatting |
| 70 | +- **Ruff** for fast linting and formatting |
| 71 | +- **Pyright** for static type checking |
| 72 | + |
| 73 | +Run formatting and linting: |
| 74 | +```bash |
| 75 | +black . |
| 76 | +ruff check . |
| 77 | +ruff format . |
| 78 | +pyright ilovepdf/ |
| 79 | +``` |
| 80 | + |
| 81 | +For pre-commit hooks (autom |
| 82 | + |
| 83 | +## Adding a New Task |
| 84 | + |
| 85 | +1. Create `ilovepdf/newtask_task.py` extending `Task` |
| 86 | +2. Add unit tests in `tests/unit/` |
| 87 | +3. Add integration test in `tests/integration/` |
| 88 | +4. Add sample script in `samples/` |
| 89 | +5. Update `ilovepdf/__init__.py` to export the task |
| 90 | + |
| 91 | +## Project Structure |
| 92 | + |
| 93 | +``` |
| 94 | +ilovepdf-python/ |
| 95 | +├── ilovepdf/ # Core library |
| 96 | +│ ├── *task.py # Task implementations |
| 97 | +│ ├── task.py # Base task class |
| 98 | +│ ├── exceptions/ # Custom exceptions |
| 99 | +│ └── validators/ # Input validators |
| 100 | +├── samples/ # Usage examples |
| 101 | +├── tests/ # Unit & integration tests |
| 102 | +├── .docker/ # Docker configurations |
| 103 | +├── README.md # Main documentation |
| 104 | +├── INSTALL.md # Installation guide |
| 105 | +└── DEVELOPMENT.md # This file |
| 106 | +``` |
| 107 | + |
| 108 | +## Docker |
| 109 | + |
| 110 | +Build and run tests in Docker using `docker-compose`: |
| 111 | + |
| 112 | +```bash |
| 113 | +# Build images |
| 114 | +docker-compose -f .docker/docker-compose.yml build |
| 115 | + |
| 116 | +# Run tests with a specific Python version |
| 117 | +docker-compose -f .docker/docker-compose.yml run --rm python310 pytest tests/unit |
| 118 | + |
| 119 | +# Run all tests |
| 120 | +docker-compose -f .docker/docker-compose.yml run --rm python310 pytest tests/ |
| 121 | +``` |
| 122 | + |
| 123 | +Available Python versions: `python310`, `python311`, `python312`, `python313`, `python314` |
| 124 | + |
| 125 | +For full Docker instructions, see [`.docker/README.md`](.docker/README.md). |
| 126 | + |
| 127 | +## Getting Help |
| 128 | + |
| 129 | +- Issues: https://github.com/ilovepdf/ilovepdf-python/issues |
| 130 | +- API Docs: https://developer.ilovepdf.com/docs |
0 commit comments