Skip to content

Commit 8357c33

Browse files
authored
Switch project setup from setup.py to pyproject.toml (#92)
Basically the same as apify/apify-client-python#123. Since we're hiring a new Python engineer hopefully soon, I thought it's time to get rid of some tech debt. This rewrites the project setup to use pyproject.toml instead of setup.py, as pyproject.toml is the modern, recommended way to specify project metadata, and setup.py is being deprecated. I've also updated the publication to PyPI to use the official GitHub action, and to use OIDC for authentication instead of an API token. And I've switched the secrets for building Python Actor base Docker images to use an org-wide GitHub token.
1 parent cd2a5fc commit 8357c33

16 files changed

+159
-161
lines changed

.flake8

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ filename =
33
./docs/*.py,
44
./scripts/*.py,
55
./src/*.py,
6-
./tests/*.py,
7-
./setup.py
6+
./tests/*.py
87
per-file-ignores =
98
docs/*: D
109
scripts/*: D

.github/workflows/integration_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Integration tests
33
on:
44
workflow_call:
55
secrets:
6-
APIFY_TEST_USER_API_TOKEN:
6+
APIFY_TEST_USER_PYTHON_SDK_API_TOKEN:
77
description: API token of the Python SDK testing user on Apify
88
required: true
99

.github/workflows/release.yaml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,16 @@ jobs:
4141
name: Check whether the documentation is up to date
4242
uses: ./.github/workflows/check_docs.yaml
4343

44-
deploy:
44+
publish_to_pypi:
4545
name: Publish to PyPI
4646
needs: [lint_and_type_checks, unit_tests, integration_tests, check_docs]
4747
runs-on: ubuntu-latest
48+
permissions:
49+
contents: write
50+
id-token: write
51+
environment:
52+
name: pypi
53+
url: https://pypi.org/p/apify
4854

4955
steps:
5056
- name: Checkout repository
@@ -56,9 +62,7 @@ jobs:
5662
python-version: 3.8
5763

5864
- name: Install dependencies
59-
run: |
60-
python -m pip install --upgrade pip
61-
pip install --upgrade setuptools twine wheel
65+
run: make install-dev
6266

6367
- # Determine if this is a prerelease or latest release
6468
name: Determine release type
@@ -86,7 +90,7 @@ jobs:
8690
- # Check whether the released version is listed in CHANGELOG.md
8791
name: Check whether the released version is listed in the changelog
8892
if: steps.get-release-type.outputs.release_type != 'alpha'
89-
run: python ./scripts/check_version_in_changelog.py
93+
run: make check-changelog-entry
9094

9195
- # Check version consistency and increment pre-release version number for prereleases (must be the last step before build)
9296
name: Bump pre-release version
@@ -95,18 +99,15 @@ jobs:
9599

96100
- # Build a source distribution and a python3-only wheel
97101
name: Build distribution files
98-
run: python setup.py sdist bdist_wheel
102+
run: make build
99103

100104
- # Check whether the package description will render correctly on PyPI
101105
name: Check package rendering on PyPI
102-
run: python -m twine check dist/*
106+
run: make twine-check
103107

104108
- # Publish package to PyPI using their official GitHub action
105109
name: Publish package to PyPI
106-
run: python -m twine upload --non-interactive --disable-progress-bar dist/*
107-
env:
108-
TWINE_USERNAME: __token__
109-
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
110+
uses: pypa/gh-action-pypi-publish@release/v1
110111

111112
- # Tag the current commit with the version tag if this is not made from the release event (releases are tagged with the release process)
112113
name: Tag Version
@@ -132,4 +133,4 @@ jobs:
132133
-F client_payload[release_tag]=${{ steps.get-release-type.outputs.docker_image_tag }} \
133134
-F client_payload[apify_version]=$PACKAGE_VERSION
134135
env:
135-
GH_TOKEN: ${{ secrets.BUILD_DOCKER_IMAGES_REPOSITORY_DISPATCH_GH_TOKEN }}
136+
GH_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Changelog
22
=========
33

4-
[1.1.0](../../releases/tag/v1.1.0) - Unreleased
4+
[1.1.0](../../releases/tag/v1.1.0) - 2023-05-23
55
-----------------------------------------------
66

77
### Added
@@ -15,7 +15,11 @@ Changelog
1515
- started enforcing local storage to always use the UTF-8 encoding
1616
- fixed saving key-value store values to local storage with the right extension for a given content type
1717

18-
[1.0.0](../../releases/tag/v1.0.0) - 2022-03-13
18+
### Internal changes
19+
20+
- switched from `setup.py` to `pyproject.toml` for specifying project setup
21+
22+
[1.0.0](../../releases/tag/v1.0.0) - 2023-03-13
1923
-----------------------------------------------
2024

2125
### Internal changes

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ and from Markdown documents in the `docs` folder in the `docs` branch, and then
5151

5252
Publishing new versions to [PyPI](https://pypi.org/project/apify) happens automatically through GitHub Actions.
5353

54-
On each commit to the `master` branch, a new beta release is published, taking the version number from `src/apify/_version.py`
54+
On each commit to the `master` branch, a new beta release is published, taking the version number from `pyproject.toml`
5555
and automatically incrementing the beta version suffix by 1 from the last beta release published to PyPI.
5656

57-
A stable version is published when a new release is created using GitHub Releases, again taking the version number from `src/apify/_version.py`.
57+
A stable version is published when a new release is created using GitHub Releases, again taking the version number from `pyproject.toml`.
5858
The built package assets are automatically uploaded to the GitHub release.
5959

60-
If there is already a stable version with the same version number as in `src/apify/_version.py` published to PyPI, the publish process fails,
60+
If there is already a stable version with the same version number as in `pyproject.toml` published to PyPI, the publish process fails,
6161
so don't forget to update the version number before releasing a new version.
6262
The release process also fails when the released version is not described in `CHANGELOG.md`,
6363
so don't forget to describe the changes in the new version there.

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: clean install-dev lint unit-tests integration-tests type-check check-code format docs check-docs check-changelog-entry
1+
.PHONY: clean install-dev build publish twine-check lint unit-tests integration-tests type-check check-code format docs check-docs check-changelog-entry
22

33
# This is default for local testing, but GitHub workflows override it to a higher value in CI
44
INTEGRATION_TESTS_CONCURRENCY = 1
@@ -8,10 +8,18 @@ clean:
88

99
install-dev:
1010
python -m pip install --upgrade pip
11-
pip install --upgrade setuptools wheel
1211
pip install --no-cache-dir -e ".[dev]"
1312
pre-commit install
1413

14+
build:
15+
python -m build
16+
17+
publish:
18+
python -m twine upload dist/*
19+
20+
twine-check:
21+
python -m twine check dist/*
22+
1523
lint:
1624
python3 -m flake8
1725

mypy.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ files =
44
docs,
55
scripts,
66
src,
7-
tests,
8-
setup.py
7+
tests
98
check_untyped_defs = True
109
disallow_incomplete_defs = True
1110
disallow_untyped_calls = True

pyproject.toml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
[project]
2+
name = "apify"
3+
version = "1.1.0"
4+
description = "Apify SDK for Python"
5+
readme = "README.md"
6+
license = {text = "Apache Software License"}
7+
authors = [
8+
{name = "Apify Technologies s.r.o.", email = "support@apify.com" }
9+
]
10+
keywords = ["apify", "sdk", "actor", "scraping", "automation"]
11+
12+
classifiers = [
13+
"Development Status :: 5 - Production/Stable",
14+
"Intended Audience :: Developers",
15+
"License :: OSI Approved :: Apache Software License",
16+
"Operating System :: OS Independent",
17+
"Programming Language :: Python :: 3.8",
18+
"Programming Language :: Python :: 3.9",
19+
"Programming Language :: Python :: 3.10",
20+
"Programming Language :: Python :: 3.11",
21+
"Topic :: Software Development :: Libraries",
22+
]
23+
24+
requires-python = ">=3.8"
25+
dependencies = [
26+
"aiofiles ~= 23.1.0",
27+
"aioshutil ~= 1.3",
28+
"apify-client ~= 1.2.0",
29+
"colorama ~= 0.4.6",
30+
"cryptography ~= 40.0.2",
31+
"httpx ~= 0.24.1",
32+
"psutil ~= 5.9.5",
33+
"pyee ~= 9.1.0",
34+
"sortedcollections ~= 2.1.0",
35+
"typing-extensions ~= 4.6.0",
36+
"websockets ~= 11.0.3",
37+
]
38+
39+
[project.optional-dependencies]
40+
dev = [
41+
"autopep8 ~= 2.0.2",
42+
"build ~= 0.10.0",
43+
"filelock ~= 3.12.0",
44+
"flake8 ~= 6.0.0",
45+
"flake8-bugbear ~= 23.5.9",
46+
"flake8-commas ~= 2.1.0",
47+
"flake8-comprehensions ~= 3.12.0",
48+
"flake8-datetimez ~= 20.10.0",
49+
"flake8-docstrings ~= 1.7.0",
50+
"flake8-encodings ~= 0.5.0",
51+
"flake8-isort ~= 6.0.0",
52+
"flake8-noqa ~= 1.3.1",
53+
"flake8-pytest-style ~= 1.7.2",
54+
"flake8-quotes ~= 3.3.2",
55+
"flake8-unused-arguments ~= 0.0.13",
56+
"isort ~= 5.12.0",
57+
"mypy ~= 1.3.0",
58+
"pep8-naming ~= 0.13.3",
59+
"pre-commit ~= 3.3.2",
60+
"pytest ~= 7.3.1",
61+
"pytest-asyncio ~= 0.21.0",
62+
"pytest-only ~= 2.0.0",
63+
"pytest-randomly ~= 3.12.0",
64+
"pytest-timeout ~= 2.1.0",
65+
"pytest-xdist ~= 3.3.1",
66+
"respx ~= 0.20.1",
67+
"sphinx ~= 6.1.3",
68+
"sphinx-autodoc-typehints ~= 1.22",
69+
"sphinx-markdown-builder == 0.5.4", # pinned to 0.5.4, because 0.5.5 has a formatting bug
70+
"twine ~= 4.0.2",
71+
"types-aiofiles ~= 23.1.0.3",
72+
"types-colorama ~= 0.4.15.11",
73+
"types-psutil ~= 5.9.5.12",
74+
]
75+
76+
[project.urls]
77+
"Homepage" = "https://docs.apify.com/sdk/python/"
78+
"Documentation" = "https://docs.apify.com/sdk/python/"
79+
"Source" = "https://github.com/apify/apify-sdk-python"
80+
"Issue tracker" = "https://github.com/apify/apify-sdk-python/issues"
81+
"Changelog" = "https://github.com/apify/apify-sdk-python/blob/master/CHANGELOG.md"
82+
"Apify Homepage" = "https://apify.com"
83+
84+
[build-system]
85+
requires = ["setuptools>=64.0.0", "wheel"]
86+
build-backend = "setuptools.build_meta"
87+
88+
[tool.setuptools.packages.find]
89+
where = ["src"]
90+
include = ["apify*"]
91+
92+
[tool.setuptools.package-data]
93+
apify = ["py.typed"]

scripts/print_current_package_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
from utils import get_current_package_version
44

5-
# Print the current package version from the src/package_name/_version.py file to stdout
5+
# Print the current package version from the pyproject.toml file to stdout
66
if __name__ == '__main__':
77
print(get_current_package_version(), end='')

scripts/update_version_for_prerelease.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from utils import PACKAGE_NAME, get_current_package_version, set_current_package_version
99

1010
# Checks whether the current package version number was not already used in a published release,
11-
# and if not, modifies the package version number in src/package_name/_version.py
11+
# and if not, modifies the package version number in pyproject.toml
1212
# from a stable release version (X.Y.Z) to a prerelease version (X.Y.ZbN or X.Y.Z.aN or X.Y.Z.rcN)
1313
if __name__ == '__main__':
1414
if len(sys.argv) != 2:
@@ -55,6 +55,6 @@
5555
if prerelease_version > latest_prerelease:
5656
latest_prerelease = prerelease_version
5757

58-
# Write the latest prerelease version number to src/package_name/_version.py
58+
# Write the latest prerelease version number to pyproject.toml
5959
new_prerelease_version_number = f'{current_version}{prerelease_prefix}{latest_prerelease + 1}'
6060
set_current_package_version(new_prerelease_version_number)

0 commit comments

Comments
 (0)