Skip to content

Commit

Permalink
support for both psycopg2 and 3 (#32)
Browse files Browse the repository at this point in the history
* support for both psycopg2 and 3

* fix

* more imports

* monkey patch

* update PG versions

* adapt README
  • Loading branch information
3nids authored Apr 9, 2024
1 parent 9969668 commit 9cbf10f
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 10 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ jobs:

strategy:
matrix:
pg-version: ['9.6', '10', '11']
psycopg-version: [2, 3]
pg-version: [12, 13, 14, 15, 16]
fail-fast: true

# Service containers to run with `runner-job`
Expand Down Expand Up @@ -59,9 +60,10 @@ jobs:
run: |
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install -r requirements-psycopg${{ matrix.psycopg-version }}.txt
- name: Install pirogue
run: python -m pip install -e .
run: python -m pip install -e .[psycopg${{ matrix.psycopg-version }}]

- name: Setup tests
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__/
*.egg-info
.idea
.DS_Store
*.orig
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# pirogue
A tool to automatically create views and triggers on PostgreSQL databases

It supports both psycopg 2 and 3. One or the other is required.

Read the docs: https://opengisch.github.io/pirogue
5 changes: 4 additions & 1 deletion pirogue/information_schema.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from psycopg import Cursor
try:
from psycopg import Cursor
except ImportError:
from psycopg2.extensions import cursor as Cursor

from pirogue.exceptions import (
InvalidSkipColumns,
Expand Down
8 changes: 7 additions & 1 deletion pirogue/multiple_inheritance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os

import psycopg
try:
import psycopg
except ImportError:
import psycopg2 as psycopg
import psycopg2.sql as __sql

psycopg.sql = __sql

from pirogue.exceptions import InvalidDefinition, TableHasNoPrimaryKey, VariableError
from pirogue.information_schema import (
Expand Down
5 changes: 4 additions & 1 deletion pirogue/simple_joins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os

import psycopg
try:
import psycopg
except ImportError:
import psycopg2 as psycopg

from pirogue.exceptions import InvalidDefinition, NoReferenceFound, TableHasNoPrimaryKey
from pirogue.information_schema import primary_key, reference_columns
Expand Down
5 changes: 4 additions & 1 deletion pirogue/single_inheritance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os

import psycopg
try:
import psycopg
except ImportError:
import psycopg2 as psycopg

from pirogue.exceptions import TableHasNoPrimaryKey
from pirogue.information_schema import default_value, primary_key, reference_columns
Expand Down
5 changes: 4 additions & 1 deletion pirogue/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from psycopg import Cursor
try:
from psycopg import Cursor
except ImportError:
from psycopg2.extensions import cursor as Cursor

from pirogue.exceptions import InvalidColumn, TableHasNoPrimaryKey
from pirogue.information_schema import columns, default_value, primary_key
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ enabled = true
readme = {file = ["README.md"], content-type = "text/markdown"}
dependencies = {file = ["requirements.txt"]}
optional-dependencies.test = {file = ["requirements-test.txt"]}
optional-dependencies.psycopg2 = {file = ["requirements-psycopg2.txt"]}
optional-dependencies.psycopg3 = {file = ["requirements-psycopg3.txt"]}

[tool.isort]
profile = "black"
Expand Down
1 change: 1 addition & 0 deletions requirements-psycopg2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
psycopg2>=2.9.9
1 change: 1 addition & 0 deletions requirements-psycopg3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
psycopg>=3.1.18
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
pyyaml>=6.0.1
psycopg>=3.1.18
6 changes: 5 additions & 1 deletion test/test_multiple_inheritance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import unittest

import psycopg
try:
import psycopg
except ImportError:
import psycopg2 as psycopg

import yaml

from pirogue import MultipleInheritance
Expand Down
6 changes: 5 additions & 1 deletion test/test_simple_joins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import unittest

import psycopg
try:
import psycopg
except ImportError:
import psycopg2 as psycopg

import yaml

from pirogue import MultipleInheritance, SimpleJoins
Expand Down

0 comments on commit 9cbf10f

Please sign in to comment.