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

[Regression] Fix psycopg2 version install #113

Merged
merged 42 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d93fbba
remove vscode and ds_store from git tracking
mikealfare Jun 6, 2024
97f7ef7
default to psycopg2-binary everywhere
mikealfare Jun 6, 2024
54895eb
add post build hook to swap out psycopg2-binary for psycopg2 based on…
mikealfare Jun 6, 2024
cb7307b
update integration tests for the new psycopg2 install approach
mikealfare Jun 6, 2024
94da850
changelog
mikealfare Jun 6, 2024
19e5a52
update post-build hook to a pre-build hook
mikealfare Jun 6, 2024
f86d9d5
replace script with inline execution
mikealfare Jun 6, 2024
9854f22
use hatch run instead of pip install
mikealfare Jun 6, 2024
7504b56
typo in the env var
mikealfare Jun 6, 2024
528d3ce
fix a type
mikealfare Jun 6, 2024
07b0c22
syntax
mikealfare Jun 6, 2024
dbfa07d
typo
mikealfare Jun 6, 2024
1e97224
get the value from the list
mikealfare Jun 6, 2024
8b1d3fd
debugging
mikealfare Jun 6, 2024
5460c61
type
mikealfare Jun 6, 2024
eb34154
remove hatch build hook that is not working as expected
mikealfare Jun 7, 2024
ac937f4
simplify psycopg2 check and override expected psycopg2 version since …
mikealfare Jun 7, 2024
1ffb3cb
use hatch envs for psycopg2 test
mikealfare Jun 7, 2024
b0d5553
add manual workaround and associated test
mikealfare Jun 7, 2024
a02bd81
roll ubuntu image back to 22.04 to support python 3.8
mikealfare Jun 7, 2024
08ed814
fix syntax error in test
mikealfare Jun 7, 2024
4808e0b
fix the typo in the workaround in the readme
mikealfare Jun 7, 2024
991f066
fix syntax to resolve || before |
mikealfare Jun 7, 2024
cc891c0
add post install command to swap out psycopg2
mikealfare Jun 12, 2024
2fc1c02
use full install instead of editable install
mikealfare Jun 12, 2024
6f51bcd
fix venv activate syntax
mikealfare Jun 12, 2024
7d00964
fix rm syntax
mikealfare Jun 13, 2024
d95529e
Merge branch 'main' into fix-psycopg2-version-install
mikealfare Jun 13, 2024
2c7d516
remove references to hatch in psycopg2 test
mikealfare Jun 13, 2024
2c1ee82
remove inapplicable tests
mikealfare Jun 13, 2024
796aa41
swap out post-install-command for a build hook
mikealfare Jun 13, 2024
721e515
add build post hook
mikealfare Jun 13, 2024
7e830ba
remove all hatch hooks
mikealfare Jun 13, 2024
f17d448
revert dev changes in pyproject.toml
mikealfare Jun 13, 2024
52cd912
remove hatch as a test req for psycopg2
mikealfare Jun 13, 2024
af57f2e
move the script into a separate file to be reused
mikealfare Jun 14, 2024
43b5342
update workaround to use jq over string parsing
mikealfare Jun 14, 2024
3daa2d0
mark script as executable
mikealfare Jun 14, 2024
41e3126
fix syntax in error message
mikealfare Jun 14, 2024
d2fd8f9
revert to string parsing to avoid jq dep
mikealfare Jun 14, 2024
d3b0cc5
update manual workaround to be more robust to future changes
mikealfare Jun 17, 2024
36f94d7
fix syntax
mikealfare Jun 17, 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
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20240605-202614.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Default to psycopg2-binary and allow overriding to psycopg2 via DBT_PSYCOPG2_NAME
(restores previous behavior)
time: 2024-06-05T20:26:14.801254-04:00
custom:
Author: mikealfare
Issue: "96"
18 changes: 18 additions & 0 deletions .github/scripts/psycopg2-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
python -m venv venv
source venv/bin/activate
python -m pip install .

if [[ "$PSYCOPG2_WORKAROUND" == true ]]; then
PSYCOPG2_VERSION=$(pip show psycopg2-binary | grep Version | cut -d " " -f 2)
pip uninstall -y psycopg2-binary
pip install psycopg2==$PSYCOPG2_VERSION
fi

PSYCOPG2_NAME=$((pip show psycopg2 || pip show psycopg2-binary) | grep Name | cut -d " " -f 2)
if [[ "$PSYCOPG2_NAME" != "$PSYCOPG2_EXPECTED_NAME" ]]; then
echo -e 'Expected: "$PSYCOPG2_EXPECTED_NAME" but found: "$PSYCOPG2_NAME"'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we pipe this to stderr >&2

exit 1
fi

deactivate
rm -r ./venv
47 changes: 32 additions & 15 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defaults:
jobs:
integration:
name: Integration Tests
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

strategy:
fail-fast: false
Expand Down Expand Up @@ -102,24 +102,41 @@ jobs:

psycopg2-check:
name: "Test psycopg2 build version"
runs-on: ${{ matrix.scenario.platform }}
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
scenario:
- {platform: ubuntu-latest, psycopg2-name: psycopg2}
- {platform: macos-12, psycopg2-name: psycopg2-binary}
platform: [ubuntu-22.04, macos-12]
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
python-version: ["3.8", "3.11"]
steps:
- name: "Check out repository"
uses: actions/checkout@v4

- name: "Test psycopg2 name"
run: |
python -m pip install .
PSYCOPG2_PIP_ENTRY=$(pip list | grep "psycopg2 " || pip list | grep psycopg2-binary)
echo $PSYCOPG2_PIP_ENTRY
PSYCOPG2_NAME="${PSYCOPG2_PIP_ENTRY%% *}"
echo $PSYCOPG2_NAME
if [[ "${PSYCOPG2_NAME}" != "${{ matrix.scenario.psycopg2-name }}" ]]; then
exit 1
fi
- name: "Set up Python ${{ matrix.python-version }}"
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: "Test psycopg2 name - default"
run: .github/scripts/psycopg2-check.sh
env:
PSYCOPG2_EXPECTED_NAME: psycopg2-binary

- name: "Test psycopg2 name - invalid override"
run: .github/scripts/psycopg2-check.sh
env:
DBT_PSYCOPG2_NAME: rubber-baby-buggy-bumpers
mikealfare marked this conversation as resolved.
Show resolved Hide resolved
PSYCOPG2_EXPECTED_NAME: psycopg2-binary

- name: "Test psycopg2 name - override"
run: .github/scripts/psycopg2-check.sh
env:
DBT_PSYCOPG2_NAME: psycopg2
PSYCOPG2_EXPECTED_NAME: psycopg2-binary # we have not implemented the hook yet, so this doesn't work

- name: "Test psycopg2 name - manual override"
# verify that the workaround documented in the `README.md` continues to work
run: .github/scripts/psycopg2-check.sh
env:
PSYCOPG2_WORKAROUND: true
PSYCOPG2_EXPECTED_NAME: psycopg2
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,9 @@ cython_debug/

# testing artifacts
/logs

# MacOS
.DS_Store

# vscode
.vscode/
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ more information on using dbt with Postgres, consult [the docs](https://docs.get
- [Install dbt](https://docs.getdbt.com/docs/installation)
- Read the [introduction](https://docs.getdbt.com/docs/introduction/) and [viewpoint](https://docs.getdbt.com/docs/about/viewpoint/)

### `psycopg2-binary` vs. `psycopg2`

By default, `dbt-postgres` installs `psycopg2-binary`. This is great for development, and even testing, as it does not require any OS dependencies; it's a pre-built wheel. However, building `psycopg2` from source will grant performance improvements that are desired in a production environment. In order to install `psycopg2`, use the following steps:

```bash
PSYCOPG2_VERSION=$(pip show psycopg2-binary | grep Version | cut -d " " -f 2)
pip uninstall -y psycopg2-binary
pip install psycopg2==$PSYCOPG2_VERSION
```

This ensures the version of `psycopg2` will match that of `psycopg2-binary`.

## Join the dbt Community

- Be part of the conversation in the [dbt Community Slack](http://community.getdbt.com/)
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ classifiers = [
"Programming Language :: Python :: 3.11",
]
dependencies = [
# install `psycopg2` on linux (assumed production)
'psycopg2>=2.9,<3.0; platform_system == "Linux"',
# install `psycopg2-binary` on macos/windows (assumed development)
'psycopg2-binary>=2.9,<3.0; platform_system != "Linux"',
"psycopg2-binary>=2.9,<3.0",
VersusFacit marked this conversation as resolved.
Show resolved Hide resolved
"dbt-adapters>=0.1.0a1,<2.0",
# add dbt-core to ensure backwards compatibility of installation, this is not a functional dependency
"dbt-core>=1.8.0a1",
Expand Down
96 changes: 0 additions & 96 deletions tests/functional/test_selection/conftest.py
mikealfare marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Loading
Loading