Skip to content

Commit

Permalink
Move required packages to extras and guess default driver
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Nov 14, 2024
1 parent f520878 commit 328dea9
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
pip install --upgrade pip setuptools wheel
pip install flake8 flake8-print coverage
python testsrequire.py
python setup.py develop
pip install -e .[http,native,async]
# Limit each test time execution.
pip install pytest-timeout
- name: Run flake8
Expand Down
26 changes: 24 additions & 2 deletions clickhouse_sqlalchemy/drivers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
from . import base
from .http import base as http_driver

base.dialect = http_driver.dialect
try:
from .native import base as native_driver

base.dialect = native_driver.dialect
except ImportError:
pass

if not hasattr(base, 'dialect'):
try:
from .http import base as http_driver

base.dialect = http_driver.dialect
except ImportError:
pass

if not hasattr(base, 'dialect'):
try:
from .asynch import base as asynch_driver
base.dialect = asynch_driver.dialect
except ImportError:
pass

if not hasattr(base, 'dialect'):
raise RuntimeError('Unable to detect default dialect. Please install one.')
30 changes: 30 additions & 0 deletions clickhouse_sqlalchemy/drivers/default.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

DefaultDialect = None

try:
from .native import base as native_driver

DefaultDialect = native_driver.dialect
except ImportError:
pass

if DefaultDialect is None:
try:
from .http import base as http_driver

DefaultDialect = http_driver.dialect
except ImportError:
pass

if DefaultDialect is None:
try:
from .asynch import base as asynch_driver

DefaultDialect = asynch_driver.dialect
except ImportError:
pass

if DefaultDialect is None:
raise RuntimeError('Unable to detect default dialect. Please install one.')

dialect = DefaultDialect
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def read_version():
'clickhouse{}=clickhouse_sqlalchemy.drivers.{}'.format(driver, d_path)

for driver, d_path in [
('', 'http.base:ClickHouseDialect_http'),
('', 'default:DefaultDialect'),
('.http', 'http.base:ClickHouseDialect_http'),
('.native', 'native.base:ClickHouseDialect_native'),
('.asynch', 'asynch.base:ClickHouseDialect_asynch'),
Expand Down Expand Up @@ -97,10 +97,12 @@ def read_version():
python_requires='>=3.7, <4',
install_requires=[
'sqlalchemy>=2.0.0,<2.1.0',
'requests',
'clickhouse-driver>=0.1.2',
'asynch>=0.2.2,<=0.2.4',
],
extras_require={
'http': ['requests'],
'native': ['clickhouse-driver>=0.1.2'],
'async': ['asynch>=0.2.2,<=0.2.4']
},
# Registering `clickhouse` as dialect.
entry_points={
'sqlalchemy.dialects': dialects
Expand Down
1 change: 0 additions & 1 deletion testsrequire.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
'sqlalchemy>=2.0.0,<2.1.0',
'greenlet>=2.0.1',
'alembic',
'requests',
'responses',
'parameterized'
]
Expand Down

0 comments on commit 328dea9

Please sign in to comment.