Skip to content

Commit c3f24ce

Browse files
Derive LIBRARY_VERSION from package version
Use importlib.metadata.version with a fallback when the package is not installed. Add Versioning and PyPI publishing instructions to DEVELOPMENT.md
1 parent 7e90089 commit c3f24ce

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

DEVELOPMENT.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,33 @@ For full Docker instructions, see [`.docker/README.md`](.docker/README.md).
128128

129129
- Issues: https://github.com/ilovepdf/ilovepdf-python/issues
130130
- API Docs: https://developer.ilovepdf.com/docs
131+
132+
## Versioning
133+
134+
- The version is defined only in `pyproject.toml``[project].version`.
135+
136+
Example: to bump from `1.0.1` to `1.0.2`, change in `pyproject.toml`:
137+
138+
- `version = "1.0.1"``version = "1.0.2"`
139+
140+
For a new release, just update the version in `pyproject.toml`.
141+
142+
## Publishing to PyPI
143+
144+
To publish a new version to PyPI:
145+
146+
1. Update the version in `pyproject.toml`.
147+
2. Build the distributions:
148+
149+
```bash
150+
pip install build twine
151+
python -m build
152+
```
153+
154+
3. Upload to PyPI:
155+
156+
```bash
157+
TWINE_USERNAME="__token__"
158+
TWINE_PASSWORD="<your PyPI token>"
159+
twine upload dist/*
160+
```

ilovepdf/ilovepdf_api.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from collections.abc import Callable
1414
from dataclasses import dataclass
1515
from datetime import datetime, timezone
16+
from importlib.metadata import version as pkg_version
1617
from typing import Any
1718

1819
import jwt
@@ -41,7 +42,15 @@
4142
API_VERSION = "v1"
4243
START_SERVER_URL = os.getenv("START_SERVER_URL", "https://api.ilovepdf.com")
4344
API_HOST = os.getenv("API_HOST", "api.ilovepdf.com")
44-
LIBRARY_VERSION = "python.0.0.1"
45+
46+
PACKAGE_NAME = "ilovepdf"
47+
48+
try:
49+
_package_version = pkg_version(PACKAGE_NAME)
50+
except Exception:
51+
_package_version = "0.0.0"
52+
53+
LIBRARY_VERSION = f"python.{_package_version}"
4554

4655
# HTTP Status Codes
4756
HTTP_OK = 200

0 commit comments

Comments
 (0)