Skip to content

Commit

Permalink
moving pyodbc within function in file_ingestion.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tim.reichard committed Oct 27, 2021
1 parent 2437c2a commit 2f2e682
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ History
=======


v0.15.3 (2021-10-27)

* Move the import of pyodbc within the function that uses it since it requires additional dependencies.


v0.15.2 (2021-10-13)

* Fix error in FICE enrolled logic by setting enrolled field instead of confirmed.
Expand Down
8 changes: 7 additions & 1 deletion aioradio/file_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# pylint: disable=broad-except
# pylint: disable=consider-using-enumerate
# pylint: disable=import-outside-toplevel
# pylint: disable=invalid-name
# pylint: disable=logging-fstring-interpolation
# pylint: disable=too-many-arguments
Expand All @@ -18,6 +19,7 @@
import logging
import os
import re
import sys
import time
import zipfile
from asyncio import sleep
Expand All @@ -37,7 +39,6 @@

from aioradio.aws.secrets import get_secret
from aioradio.psycopg2 import establish_psycopg2_connection
from aioradio.pyodbc import establish_pyodbc_connection

DIRECTORY = Path(__file__).parent.absolute()
LOG = logging.getLogger('file_ingestion')
Expand Down Expand Up @@ -1042,6 +1043,11 @@ async def child_wrapper(*args, **kwargs) -> Any:
if item['db'] in ['pyodbc', 'psycopg2']:
creds = {**json.loads(await get_secret(item['secret'], item['region'])), **{'database': item.get('database', '')}}
if item['db'] == 'pyodbc':
# Add import here because it requires extra dependencies many systems
# don't have out of the box so only import when explicitly being used
if 'pyodbc' not in sys.modules:
from aioradio.pyodbc import \
establish_pyodbc_connection
conns[item['name']] = await establish_pyodbc_connection(**creds, autocommit=False)
elif item['db'] == 'psycopg2':
conns[item['name']] = await establish_psycopg2_connection(**creds)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
long_description = fileobj.read()

setup(name='aioradio',
version='0.15.2',
version='0.15.3',
description='Generic asynchronous i/o python utilities for AWS services (SQS, S3, DynamoDB, Secrets Manager), Redis, MSSQL (pyodbc), JIRA and more',
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 2f2e682

Please sign in to comment.