Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/pre_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
update_changelog:
name: Update changelog
needs: [release_metadata, wait_for_checks]
uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@main
uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@v0.45.0
with:
version_number: ${{ needs.release_metadata.outputs.version_number }}
changelog: ${{ needs.release_metadata.outputs.changelog }}
Expand All @@ -71,6 +71,10 @@ jobs:
is_prerelease: "yes"
version_number: ${{ needs.release_metadata.outputs.version_number }}
ref: ${{ needs.update_changelog.outputs.changelog_commitish }}
# The build only needs hatch (pure Python); avoid installing the heavy
# runtime/test deps on the action's Python (defaults to 3.14).
install_command: uv pip install --system hatch
build_command: hatch build
# Publishes the package to PyPI using PyPA official GitHub action with OIDC authentication.
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
65 changes: 59 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,28 @@ jobs:
release_metadata:
name: Prepare release metadata
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read # git-cliff enhances release notes with PR links via GITHUB_TOKEN.
issues: read # git-cliff enhances release notes with issue links via GITHUB_TOKEN.
outputs:
version_number: ${{ steps.release_metadata.outputs.version_number }}
tag_name: ${{ steps.release_metadata.outputs.tag_name }}
changelog: ${{ steps.release_metadata.outputs.changelog }}
release_notes: ${{ steps.release_metadata.outputs.release_notes }}
steps:
- name: Verify running on main in the apify org
if: github.ref != 'refs/heads/main' || !startsWith(github.repository, 'apify/')
run: |
echo "::error title=Wrong branch or repository::Releases must run from main in an apify/ repository. ref=${{ github.ref }} repo=${{ github.repository }}"
exit 1

- name: Validate inputs
if: inputs.release_type == 'custom' && inputs.custom_version == ''
run: |
echo "::error title=Missing custom_version::release_type is 'custom' but custom_version is empty. Provide a custom version (e.g. 0.1.0) and re-run the workflow."
exit 1

- uses: apify/actions/git-cliff-release@v1.1.2
name: Prepare release metadata
id: release_metadata
Expand All @@ -45,16 +61,45 @@ jobs:

lint_check:
name: Lint check
uses: apify/workflows/.github/workflows/python_lint_check.yaml@6cbb5232cc59d59047f1e8268da10747e729989e
uses: apify/workflows/.github/workflows/python_lint_check.yaml@v0.45.0
with:
python_versions: '["3.10", "3.11", "3.12", "3.13"]'
install_command: uv pip install --system -e ".[dev]"
lint_command: ruff check langchain_apify tests && ruff format --check langchain_apify tests

type_check:
name: Type check
uses: apify/workflows/.github/workflows/python_type_check.yaml@6cbb5232cc59d59047f1e8268da10747e729989e
uses: apify/workflows/.github/workflows/python_type_check.yaml@v0.45.0
with:
python_versions: '["3.10", "3.11", "3.12", "3.13"]'
install_command: uv pip install --system -e ".[dev]"
type_check_command: mypy langchain_apify

unit_tests:
name: Unit tests
uses: apify/workflows/.github/workflows/python_unit_tests.yaml@v0.45.0
with:
python_versions: '["3.10", "3.11", "3.12", "3.13"]'
operating_systems: '["ubuntu-latest"]'
install_command: uv pip install --system -e ".[dev]"
run_tests_command: pytest --disable-socket --allow-unix-socket tests/unit_tests/

update_changelog:
name: Update changelog
needs: [release_metadata, lint_check, type_check, unit_tests]
uses: apify/workflows/.github/workflows/python_bump_and_update_changelog.yaml@v0.45.0
with:
version_number: ${{ needs.release_metadata.outputs.version_number }}
changelog: ${{ needs.release_metadata.outputs.changelog }}
secrets:
APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN: ${{ secrets.APIFY_SERVICE_ACCOUNT_GITHUB_TOKEN }}

create_github_release:
name: Create github release
needs: [release_metadata, lint_check, type_check]
needs: [release_metadata, update_changelog]
runs-on: ubuntu-latest
permissions:
contents: write # Required to create the tag and the GitHub release.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
Expand All @@ -64,13 +109,15 @@ jobs:
tag_name: ${{ needs.release_metadata.outputs.tag_name }}
name: ${{ needs.release_metadata.outputs.version_number }}
body: ${{ needs.release_metadata.outputs.release_notes }}
# Tag the exact post-bump commit so the release points at the committed version.
target_commitish: ${{ needs.update_changelog.outputs.changelog_commitish }}

publish_to_pypi:
name: Publish to PyPI
needs: [release_metadata, lint_check, type_check]
needs: [release_metadata, update_changelog, create_github_release]
runs-on: ubuntu-latest
permissions:
contents: write
contents: read
id-token: write # Required for OIDC authentication.
environment:
name: pypi
Expand All @@ -79,10 +126,16 @@ jobs:
- name: Prepare distribution
uses: apify/actions/prepare-pypi-distribution@v1.1.2
with:
ref: ${{ github.ref }}
# Build from the exact post-bump commit so the wheel's version metadata
# matches the tag created by create_github_release.
ref: ${{ needs.update_changelog.outputs.changelog_commitish }}
package_name: langchain-apify
is_prerelease: ""
version_number: ${{ needs.release_metadata.outputs.version_number }}
# The build only needs hatch (pure Python); avoid installing the heavy
# runtime/test deps on the action's Python (defaults to 3.14).
install_command: uv pip install --system hatch
build_command: hatch build
# Publishes the package to PyPI using PyPA official GitHub action with OIDC authentication.
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
48 changes: 22 additions & 26 deletions .github/workflows/run_code_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,27 @@ on:
types: [opened, synchronize, reopened]

jobs:
code_check:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12", "3.13"]
poetry-version: ["latest"]
steps:
- name: Checkout repository
uses: actions/checkout@v2
lint_check:
name: Lint check
uses: apify/workflows/.github/workflows/python_lint_check.yaml@v0.45.0
with:
python_versions: '["3.10", "3.11", "3.12", "3.13"]'
install_command: uv pip install --system -e ".[dev]"
lint_command: ruff check langchain_apify tests && ruff format --check langchain_apify tests

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
type_check:
name: Type check
uses: apify/workflows/.github/workflows/python_type_check.yaml@v0.45.0
with:
python_versions: '["3.10", "3.11", "3.12", "3.13"]'
install_command: uv pip install --system -e ".[dev]"
type_check_command: mypy langchain_apify

- name: Run image
uses: abatilo/actions-poetry@v3
with:
poetry-version: ${{ matrix.poetry-version }}

- name: Install dependencies
run: poetry sync --no-interaction --no-ansi --with lint --with test --with dev

- name: Run lint
run: make lint

- name: Run tests
run: make test
unit_tests:
name: Unit tests
uses: apify/workflows/.github/workflows/python_unit_tests.yaml@v0.45.0
with:
python_versions: '["3.10", "3.11", "3.12", "3.13"]'
operating_systems: '["ubuntu-latest"]'
install_command: uv pip install --system -e ".[dev]"
run_tests_command: pytest --disable-socket --allow-unix-socket tests/unit_tests/
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Open a GitHub issue at <https://github.com/apify/langchain-apify/issues>. A few

- Branch from `main`.
- Keep one logical change per PR. A PR that fixes a bug *and* adds a feature is harder to review and harder to revert if needed.
- Before opening: run `make lint` and `make test` locally. CI will also run integration tests; you don't need an `APIFY_TOKEN` to open the PR (CI has its own).
- Before opening: run `hatch run lint` and `hatch run test` locally. CI will also run integration tests; you don't need an `APIFY_TOKEN` to open the PR (CI has its own).
- If your change affects the public API, update the README and any in-repo examples.
- If your change adds a new tool family or generic primitive, add or extend the corresponding test file under `tests/unit_tests/`.

Expand Down Expand Up @@ -49,7 +49,7 @@ resolution and raised ValueError if neither was present.
## What review looks for

- **Correctness on the public API surface.** Any new tool must follow the `_ApifyGenericTool` envelope contract (a JSON string of `{"run": {...}, "items": [...]}`) and route Actor calls through `ApifyToolsClient` (`_client.py`), not the SDK directly.
- **`make lint` and `make test` pass locally.** Integration tests pass under CI's token; you don't need to run them yourself unless you're touching `_client.py`.
- **`hatch run lint` and `hatch run test` pass locally.** Integration tests pass under CI's token; you don't need to run them yourself unless you're touching `_client.py`.
- **No new `apify_api_token` field declarations.** The canonical token kwarg is `apify_token`; the legacy `apify_api_token` is honoured only via the existing deprecation plumbing in `_utils.py` and per-tool model validators. New code should not introduce fresh `apify_api_token` fields.
- **No manually bumped `version =` in `pyproject.toml`.** Versions come from commit messages via `git-cliff`.
- **Shared defaults stay in `_constants.py`.** Don't reintroduce magic literals (`300`, `100`, `120`, etc.); import the named constant instead.
Expand Down
27 changes: 15 additions & 12 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,53 @@ This file covers everything you need to run the code locally: install, format, l

## Installation

To work on this repo locally, you first need to clone the repository and install the dependencies. You can do this by running the following commands:
This project uses [uv](https://docs.astral.sh/uv/) for dependency management and [Hatch](https://hatch.pypa.io/) as the build backend and task runner.

Clone the repository and install the project with its development dependencies:

```bash
git clone https://github.com/apify/langchain-apify
cd langchain-apify

poetry sync --all-groups
# for poetry version < 2.0
poetry install --with dev,test,lint --no-root --sync
uv sync --extra dev
```

Development tasks are defined as Hatch scripts in `pyproject.toml` and run with `hatch run <task>`. Hatch manages an isolated environment with the dev dependencies, so install it once (e.g. `uv tool install hatch` or `pipx install hatch`).

## Formatting and linting

To format the code, use the following command:

```bash
make format
hatch run format
```

To lint the code, use the following command:
To lint and type-check the code, use the following commands:

```bash
make lint
hatch run lint
hatch run typecheck
```

## Testing

To run unit tests, use the following command:

```bash
make test
hatch run test
```

To run integration tests, use the following command:

```bash
APIFY_TOKEN="YOUR_TOKEN" make integration_test
APIFY_TOKEN="YOUR_TOKEN" hatch run integration-test
```

To run single test file, use `TEST_FILE` argument:
To run a single test file, pass it as an argument:

```bash
make test TEST_FILE=path_to/test_file.py
APIFY_TOKEN="YOUR_TOKEN" make integration_test TEST_FILE=path_to/test_file.py
hatch run test tests/unit_tests/test_file.py
APIFY_TOKEN="YOUR_TOKEN" hatch run integration-test tests/integration_tests/test_file.py
```

> `APIFY_API_TOKEN` is also accepted as a deprecated alias for `APIFY_TOKEN` (emits a `DeprecationWarning`). New code and examples should use `APIFY_TOKEN`.
73 changes: 0 additions & 73 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,5 @@ It is **NOT** designed for:

## Contributing

For local setup (Poetry install, running tests and linting), see [DEVELOPMENT.md](DEVELOPMENT.md).
For local setup (install, running tests and linting), see [DEVELOPMENT.md](DEVELOPMENT.md).
For PR scope, commit message conventions, and review expectations, see [CONTRIBUTING.md](CONTRIBUTING.md).
Loading
Loading