Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Airbyte CDK: move from gradle to poetry #36250

Merged
merged 57 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
d61c8c2
move check tasks out of gradle into a shell script
erohmensing Mar 12, 2024
565e9d9
move extra tasks i'm not sure what we'll do with yet
erohmensing Mar 12, 2024
d30ab5f
update check python cdk ci task and remove clean task. expect this to…
erohmensing Mar 12, 2024
427fe61
trigger tests?
erohmensing Mar 12, 2024
8b0ed42
fail scripts on errors
erohmensing Mar 12, 2024
0396930
delete prep java task
erohmensing Mar 12, 2024
92186ef
remove extra dependencies from gradle configuration
erohmensing Mar 12, 2024
38ab886
comment out actual image pushing and stuff that posts to slack for te…
erohmensing Mar 12, 2024
b3a1d61
remove anything about ec2 runners
erohmensing Mar 12, 2024
fb338b4
remove one more potential push
erohmensing Mar 12, 2024
691596b
comment out autocommit
erohmensing Mar 12, 2024
530e0c3
comment out pull request creation
erohmensing Mar 12, 2024
9463599
remove dependency
erohmensing Mar 12, 2024
8397962
comment out publish python package
erohmensing Mar 12, 2024
e055280
Revert "remove anything about ec2 runners"
erohmensing Mar 12, 2024
aa211f7
remove java and gradle from publish command definition
erohmensing Mar 12, 2024
d88f786
bring back dependency
erohmensing Mar 12, 2024
5a064ee
use --load instead of --push in order to not push to remote
erohmensing Mar 12, 2024
031e97e
comment out cdk tests while working on publish
erohmensing Mar 12, 2024
b683693
add path to command
erohmensing Mar 12, 2024
892e377
move assemble tasks out of gradle into a shell script
erohmensing Mar 12, 2024
bb6b015
remove gradle stuff
erohmensing Mar 18, 2024
2d9595e
first pass - setup to poetry
erohmensing Mar 18, 2024
f4623ff
alphebatize packages
erohmensing Mar 18, 2024
fb3ef86
trigger ci
erohmensing Mar 18, 2024
f5e4d17
test: use global flake8 config
erohmensing Mar 18, 2024
8d31971
stop spamming me pls
erohmensing Mar 18, 2024
9674dd6
rm type-check-and-test.sh
erohmensing Mar 18, 2024
92d4b07
remove unused scripts
erohmensing Mar 18, 2024
662d457
don't mind deleted files for mypy
erohmensing Mar 18, 2024
8a88a3f
use global pyproject.toml for coverage
erohmensing Mar 18, 2024
984d3a6
update python version
erohmensing Mar 20, 2024
4d4dedb
remove gradle folder
erohmensing Mar 20, 2024
55bc3ad
more docs stuff
erohmensing Mar 20, 2024
650567a
add comment about how to install local cdk once everything is poetry
erohmensing Mar 20, 2024
dc36680
use poetry to bump version
erohmensing Mar 21, 2024
3fcb8b3
update version to match lastest version
erohmensing Mar 21, 2024
4fdfd16
use --cov instead of coverage run
erohmensing Mar 21, 2024
5c823ac
add example config
erohmensing Mar 25, 2024
745b929
update readme
erohmensing Mar 25, 2024
f2446dc
add more poe scripts
erohmensing Mar 25, 2024
10abd75
check-local vs check-ci
erohmensing Mar 25, 2024
05da30d
try out new action to pyblish pypi package
erohmensing Mar 25, 2024
8bdaa74
add extra args
erohmensing Mar 25, 2024
0951f62
remove test change
erohmensing Mar 25, 2024
b25b1b8
try a different action
erohmensing Mar 25, 2024
2aa9ad6
remove test repo
erohmensing Mar 25, 2024
633aa1e
some fixes to bump version
erohmensing Mar 25, 2024
0a64474
remove commenting
erohmensing Mar 25, 2024
6a35300
update version to match lastest version
erohmensing Mar 25, 2024
80503f1
small fixes
erohmensing Mar 25, 2024
999e454
format file
erohmensing Mar 25, 2024
69244ef
don't support mypy via poe just yet
erohmensing Mar 25, 2024
559c895
don't support mypy via poe just yet. add help to all poe tasks
erohmensing Mar 25, 2024
c8c4c5c
support mypy via poe
erohmensing Mar 25, 2024
3fda806
undo changes to airbyte-ci
erohmensing Mar 25, 2024
18e4d75
bump pyproject.toml back to master version
erohmensing Mar 25, 2024
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
48 changes: 26 additions & 22 deletions .github/workflows/publish-cdk-command-manually.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,25 @@ jobs:
build-cdk:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v4
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions/setup-java@v3
erohmensing marked this conversation as resolved.
Show resolved Hide resolved
with:
distribution: "zulu"
java-version: "21"
- name: Install Poetry
erohmensing marked this conversation as resolved.
Show resolved Hide resolved
id: install_poetry
uses: snok/install-poetry@v1
- name: Checkout Airbyte
uses: actions/checkout@v3
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Install Dependencies
id: install_dependencies
working-directory: airbyte-cdk/python
run: poetry install
- name: Build CDK Package
run: (cd airbyte-cdk/python; ./gradlew --no-daemon --no-build-cache :build)
working-directory: airbyte-cdk/python
run: poetry run poe build
- name: Post failure to Slack channel dev-connectors-extensibility
if: ${{ failure() }}
uses: slackapi/slack-github-action@v1.23.0
Expand Down Expand Up @@ -113,6 +118,9 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install Poetry
id: install_poetry
uses: snok/install-poetry@v1
- name: Checkout Airbyte
uses: actions/checkout@v3
with:
Expand All @@ -122,16 +130,20 @@ jobs:
- name: "Publish Python CDK: bump version"
id: bumpversion
run: |
pip install bumpversion
cd airbyte-cdk/python
# Bump docker image version
# TODO: this should not be necessary, as it's the source-declarative-manifest one which should be published separately
pip install bumpversion
bumpversion ${{ github.event.inputs.release-type }}
new_version="$(grep -i 'current_version = ' .bumpversion.cfg | sed -e 's/.* = //')"
# Bump package version
poetry version ${{ github.event.inputs.release-type }}
new_version="$(poetry version -s)"
awk -v NEW_VERSION="$new_version" -v CHANGELOG_MESSAGE="${{ github.event.inputs.changelog-message }}" 'NR==3{print "## " NEW_VERSION "\n" CHANGELOG_MESSAGE "\n"}1' CHANGELOG.md > tmp && mv tmp CHANGELOG.md
echo NEW_VERSION=$new_version >> $GITHUB_OUTPUT
- name: Commit and Push Changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
file_pattern: airbyte-cdk/python/setup.py airbyte-cdk/python/.bumpversion.cfg airbyte-cdk/python/CHANGELOG.md airbyte-cdk/python/Dockerfile
file_pattern: airbyte-cdk/python/pyproject.toml airbyte-cdk/python/.bumpversion.cfg airbyte-cdk/python/CHANGELOG.md airbyte-cdk/python/Dockerfile
commit_message: 🤖 Bump ${{ github.event.inputs.release-type }} version of Python CDK
commit_user_name: Octavia Squidington III
commit_user_email: octavia-squidington-iii@users.noreply.github.com
Expand Down Expand Up @@ -165,6 +177,7 @@ jobs:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN_AIRBYTE_TEAM }}

publish-cdk:
name: Publish Python CDK to PyPi
needs: bump-version
runs-on: ubuntu-latest
steps:
Expand All @@ -173,16 +186,12 @@ jobs:
with:
repository: ${{ github.event.inputs.repo }}
ref: ${{ github.event.inputs.gitref }}
- name: Publish Python Package
uses: mariamrf/py-package-publish-action@v1.1.0
- name: Build and publish to pypi
uses: JRubics/poetry-publish@v2.0
with:
# specify the same version as in ~/.python-version
pypi_token: ${{ secrets.PYPI_TOKEN }}
python_version: "3.10"
pip_version: "23.2"
subdir: "airbyte-cdk/python/"
env:
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
package_directory: "airbyte-cdk/python"
- name: Post failure to Slack channel dev-connectors-extensibility
if: ${{ failure() }}
uses: slackapi/slack-github-action@v1.23.0
Expand Down Expand Up @@ -224,11 +233,6 @@ jobs:
with:
repository: airbytehq/airbyte
ref: ${{ github.event.inputs.gitref }}
- name: Install Java
erohmensing marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "21"
- name: Install Python
uses: actions/setup-python@v4
with:
Expand Down
22 changes: 12 additions & 10 deletions .github/workflows/python_cdk_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ jobs:
steps:
- name: Checkout Airbyte
uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
distribution: "zulu"
java-version: "21"
- name: Install Pip
run: curl -fsSL https://bootstrap.pypa.io/get-pip.py | python3
- name: Install Pyenv
run: python3 -m pip install virtualenv --user
- name: Run Gradle Check on Python CDK
run: (cd airbyte-cdk/python && CI=true ./gradlew --no-daemon --no-build-cache --scan check)
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Install Dependencies
id: install_dependencies
working-directory: airbyte-cdk/python
run: poetry install
- name: Build CDK Package
working-directory: airbyte-cdk/python
run: poetry run poe build
- name: Check Python CDK
working-directory: airbyte-cdk/python
run: poetry run poe check-ci

set-instatus-incident-on-failure:
name: Create Instatus Incident on Failure
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-mypy-on-modified-cdk-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- run: pip install mypy==1.6.0
- name: Get Python changed files
id: changed-py-files
uses: tj-actions/changed-files@v23
uses: tj-actions/changed-files@v43
with:
files: "airbyte-cdk/python/airbyte_cdk/**/*.py"
- name: Run if any of the listed files above is changed
Expand Down
3 changes: 0 additions & 3 deletions airbyte-cdk/python/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[bumpversion]
current_version = 0.75.0
commit = False

[bumpversion:file:setup.py]

[bumpversion:file:Dockerfile]
58 changes: 34 additions & 24 deletions airbyte-cdk/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,35 @@ The CDK provides an improved developer experience by providing basic implementat

This document is a general introduction to the CDK. Readers should have basic familiarity with the [Airbyte Specification](https://docs.airbyte.com/understanding-airbyte/airbyte-protocol/) before proceeding.

## Getting Started
# Setup

Generate an empty connector using the code generator. First clone the Airbyte repository then from the repository root run
## Prerequisites

#### Poetry

Before you can start working on this project, you will need to have Poetry installed on your system. Please follow the instructions below to install Poetry:

1. Open your terminal or command prompt.
2. Install Poetry using the recommended installation method:

```bash
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.5.1 python3 -
```

Alternatively, you can use `pip` to install Poetry:

```bash
cd airbyte-integrations/connector-templates/generator
./generate.sh
pip install --user poetry
```

then follow the interactive prompt. Next, find all `TODO`s in the generated project directory -- they're accompanied by lots of comments explaining what you'll need to do in order to implement your connector. Upon completing all TODOs properly, you should have a functioning connector.
3. After the installation is complete, close and reopen your terminal to ensure the newly installed `poetry` command is available in your system's PATH.

For more detailed instructions and alternative installation methods, please refer to the official Poetry documentation: https://python-poetry.org/docs/#installation

### Using Poetry in the Project

Once Poetry is installed, you can use it to manage the project's dependencies and virtual environment. To get started, navigate to the project's root directory in your terminal and follow these steps:

Additionally, you can follow [this tutorial](https://docs.airbyte.com/connector-development/cdk-python/) for a complete walkthrough of creating an HTTP connector using the Airbyte CDK.

### Concepts & Documentation

Expand All @@ -42,39 +59,32 @@ See the [concepts docs](docs/concepts/) for a tour through what the API offers.

### First time setup

We assume `python` points to Python 3.9 or higher.

Setup a virtual env:
Install the project dependencies and development tools:

```bash
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]" # [dev] installs development-only dependencies
poetry install
```

#### Iteration

- Iterate on the code locally
- Run tests via `python -m pytest -s unit_tests`
- Perform static type checks using `mypy airbyte_cdk`. `MyPy` configuration is in `mypy.ini`.
- Run `mypy <files to check>` to only check specific files. This is useful as the CDK still contains code that is not compliant.
- The `type_check_and_test.sh` script bundles both type checking and testing in one convenient command. Feel free to use it!
- Iterate on the CDK code locally
- Run tests via `poetry run poe unit-test-with-cov`, or `python -m pytest -s unit_tests` if you want to pass pytest options.
- Run `poetry run poe check` to lint and unit test the code in one command.
- Run `bin/run-mypy-on-modified-files.sh` to run `mypy` static type checking on the files you have modified compared to master. This is useful as the CDK still contains code that is not compliant.

##### Autogenerated files

If the iteration you are working on includes changes to the models, you might want to regenerate them. In order to do that, you can run:
If the iteration you are working on includes changes to the models or the connector generator, you might want to regenerate them. In order to do that, you can run:

```bash
cd airbyte-cdk/python
./gradlew build
poetry run poe build
```

This will generate the files based on the schemas, add the license information and format the code. If you want to only do the former and rely on
pre-commit to the others, you can run the appropriate generation command i.e. `./gradlew generateComponentManifestClassFiles`.
This will generate the code generator docker image and the component manifest files based on the schemas and templates.

#### Testing

All tests are located in the `unit_tests` directory. Run `python -m pytest --cov=airbyte_cdk unit_tests/` to run them. This also presents a test coverage report.
All tests are located in the `unit_tests` directory. Run `poetry run poe unit-test-with-cov` to run them. This also presents a test coverage report. For faster iteration with no coverage report and more options, `python -m pytest -s unit_tests` is a good place to start.

#### Building and testing a connector with your local CDK

Expand Down Expand Up @@ -131,7 +141,7 @@ airbyte-ci connectors --use-local-cdk --name=<CONNECTOR> test

#### When you don't have access to the API

There can be some time where you do not have access to the API (either because you don't have the credentials, network access, etc...) You will probably still want to do end-to-end testing at least once. In order to do so, you can emulate the server you would be reaching using a server stubbing tool.
There may be a time when you do not have access to the API (either because you don't have the credentials, network access, etc...) You will probably still want to do end-to-end testing at least once. In order to do so, you can emulate the server you would be reaching using a server stubbing tool.

For example, using [mockserver](https://www.mock-server.com/), you can set up an expectation file like this:

Expand Down
4 changes: 1 addition & 3 deletions airbyte-cdk/python/airbyte_cdk/connector_builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ Note:

First, make sure you build the latest Docker image:
```
./gradlew airbyte-cdk:python:airbyteDocker
docker build -t airbyte/source-declarative-manifest:dev .
```

The docker image name and tag, respectively, are the values of the `io.airbyte.name` and `io.airbyte.version` `LABEL`s in the Dockerfile.

#### Run

Then run any of the connector commands as follows:
Expand Down
6 changes: 4 additions & 2 deletions airbyte-cdk/python/bin/generate-component-manifest-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

[ -z "$ROOT_DIR" ] && exit 1
ROOT_DIR=$(cd ../../ && pwd)

YAML_DIR=airbyte-cdk/python/airbyte_cdk/sources/declarative
OUTPUT_DIR=airbyte-cdk/python/airbyte_cdk/sources/declarative/models
Expand Down Expand Up @@ -33,7 +33,9 @@ function main() {
# We can revisit this if there is movement on a fix.
temp_file=$(mktemp)
sed 's/ _parameters:/ parameters:/g' "$ROOT_DIR/$OUTPUT_DIR/$filename_wo_ext.py" > "${temp_file}"
mv "${temp_file}" "$ROOT_DIR/$OUTPUT_DIR/$filename_wo_ext.py"
output_file="$ROOT_DIR/$OUTPUT_DIR/$filename_wo_ext.py"
mv "${temp_file}" "${output_file}"
echo "Generated component manifest files into '${output_file}'."
done
}

Expand Down
42 changes: 0 additions & 42 deletions airbyte-cdk/python/bin/low-code-unit-tests.sh

This file was deleted.

8 changes: 4 additions & 4 deletions airbyte-cdk/python/bin/run-mypy-on-modified-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cd "$(dirname "${0}")/.." || exit 1

# TODO change this to include unit_tests as well once it's in a good state
{
git diff --name-only --relative ':(exclude)unit_tests'
git diff --name-only --staged --relative ':(exclude)unit_tests'
git diff --name-only master... --relative ':(exclude)unit_tests'
} | grep -E '\.py$' | sort | uniq | xargs .venv/bin/python -m mypy --config-file mypy.ini --install-types --non-interactive
git diff --name-only --diff-filter=d --relative ':(exclude)unit_tests'
git diff --name-only --diff-filter=d --staged --relative ':(exclude)unit_tests'
git diff --name-only --diff-filter=d master... --relative ':(exclude)unit_tests'
} | grep -E '\.py$' | sort | uniq | xargs mypy --config-file mypy.ini --install-types --non-interactive
32 changes: 0 additions & 32 deletions airbyte-cdk/python/bin/validate-yaml-schema.sh

This file was deleted.

Loading
Loading