Skip to content

Commit

Permalink
Globally disable the pylint import-error check.
Browse files Browse the repository at this point in the history
We intentionally allow importing potentially unavailable modules, but
also explicitly check for them at runtime when using features that require
them.
  • Loading branch information
matthewwardrop committed Nov 1, 2023
1 parent bfadbcc commit 837d6e9
Show file tree
Hide file tree
Showing 18 changed files with 21 additions and 37 deletions.
3 changes: 0 additions & 3 deletions omniduct/databases/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,10 +963,7 @@ def _register_magics(self, base_name):
Documentation for these magics is provided online.
"""
# pylint: disable-next=import-error
from IPython import get_ipython

# pylint: disable-next=import-error
from IPython.core.magic import (
register_line_magic,
register_cell_magic,
Expand Down
2 changes: 1 addition & 1 deletion omniduct/databases/exasol.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _init(self, schema=None, engine_opts=None):

@override
def _connect(self):
import pyexasol # pylint: disable=import-error
import pyexasol

logger.info("Connecting to Exasol ...")
# pylint: disable-next=attribute-defined-outside-init
Expand Down
2 changes: 0 additions & 2 deletions omniduct/databases/hiveserver2.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ def _execute(self, statement, cursor, wait, session_properties, poll_interval=1)
log_offset = 0

if self.driver == "pyhive":
# pylint: disable-next=import-error
from TCLIService.ttypes import TOperationState # noqa: F821

cursor.execute(statement, **{"async": True})
Expand Down Expand Up @@ -249,7 +248,6 @@ def _cursor_empty(self, cursor):
return False

def _cursor_wait(self, cursor, poll_interval=1):
# pylint: disable-next=import-error
from TCLIService.ttypes import TOperationState # noqa: F821

status = cursor.poll().operationState
Expand Down
2 changes: 1 addition & 1 deletion omniduct/databases/neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _init(self):
# Connection
@override
def _connect(self):
from neo4j.v1 import GraphDatabase # pylint: disable=import-error
from neo4j.v1 import GraphDatabase

logger.info("Connecting to Neo4J graph database ...")
auth = (self.username, self.password) if self.username else None
Expand Down
13 changes: 3 additions & 10 deletions omniduct/databases/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,8 @@ def _execute(self, statement, cursor, wait, session_properties):
log and present the user with useful debugging information. If that fails,
the full traceback will be raised instead.
"""
# pylint: disable-next=import-error
from pyhive import (
presto,
)

# pylint: disable-next=import-error
from pyhive.exc import (
DatabaseError,
)
from pyhive import presto
from pyhive.exc import DatabaseError

try:
cursor = cursor or presto.Cursor(
Expand Down Expand Up @@ -266,7 +259,7 @@ def _table_list(self, namespace, like=None, **kwargs):

@override
def _table_exists(self, table, **kwargs):
from pyhive.exc import DatabaseError # pylint: disable=import-error
from pyhive.exc import DatabaseError

logger.disabled = True
try:
Expand Down
2 changes: 1 addition & 1 deletion omniduct/databases/pyspark.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _init(

@override
def _connect(self):
from pyspark.sql import SparkSession # pylint: disable=import-error
from pyspark.sql import SparkSession

builder = SparkSession.builder.appName(self.app_name)
if self.master:
Expand Down
1 change: 0 additions & 1 deletion omniduct/filesystems/_pyarrow_compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=import-error
from pyarrow.filesystem import FileSystem
from pyarrow.util import implements, _stringify_path

Expand Down
2 changes: 0 additions & 2 deletions omniduct/filesystems/_webhdfs_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# pylint: disable=import-error # protected via the webhdfs module.

import http.client
import json
import xml.dom.minidom
Expand Down
1 change: 0 additions & 1 deletion omniduct/filesystems/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,6 @@ def upload(self, source, dest=None, overwrite=False, fs=None):
# Magics
@override
def _register_magics(self, base_name):
# pylint: disable-next=import-error
from IPython.core.magic import register_line_magic, register_cell_magic

@register_line_magic(f"{base_name}.listdir")
Expand Down
7 changes: 3 additions & 4 deletions omniduct/filesystems/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _init(
self._client = None

# Ensure self.host is updated with correct AWS region
import boto3 # pylint: disable=import-error
import boto3

self.host = f"autoscaling.{(session or boto3.Session(profile_name=self.aws_profile)).region_name or 'us-east-1'}.amazonaws.com"

Expand All @@ -88,10 +88,9 @@ def _connect(self):
self._resource = self._session.resource("s3")

def _get_boto3_session(self):
import boto3 # pylint: disable=import-error
import boto3

if self.use_opinel:
# pylint: disable-next=import-error
from opinel.utils.credentials import read_creds

# Refresh access token, and attach credentials to current object for debugging
Expand All @@ -111,7 +110,7 @@ def _is_connected(self):
if self._client is None:
return False
# Check if still able to perform requests against AWS
import botocore # pylint: disable=import-error
import botocore

try:
self._client.list_buckets()
Expand Down
6 changes: 3 additions & 3 deletions omniduct/filesystems/webhdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _path_separator(self):
# File node properties
@override
def _exists(self, path):
from pywebhdfs.errors import FileNotFound # pylint: disable=import-error
from pywebhdfs.errors import FileNotFound

try:
self.__webhdfs.get_file_dir_status(path)
Expand All @@ -121,7 +121,7 @@ def _exists(self, path):

@override
def _isdir(self, path):
from pywebhdfs.errors import FileNotFound # pylint: disable=import-error
from pywebhdfs.errors import FileNotFound

try:
stats = self.__webhdfs.get_file_dir_status(path)
Expand All @@ -131,7 +131,7 @@ def _isdir(self, path):

@override
def _isfile(self, path):
from pywebhdfs.errors import FileNotFound # pylint: disable=import-error
from pywebhdfs.errors import FileNotFound

try:
stats = self.__webhdfs.get_file_dir_status(path)
Expand Down
2 changes: 1 addition & 1 deletion omniduct/remotes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def prepare_smartcards(self):
return smartcard_added

def _prepare_smartcard(self, name, filename):
import pexpect # pylint: disable=import-error
import pexpect

remover = pexpect.spawn(f'ssh-add -e "{filename}"')
i = remover.expect(["Card removed:", "Could not remove card", pexpect.TIMEOUT])
Expand Down
2 changes: 1 addition & 1 deletion omniduct/remotes/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _connect(self):
inspired by the `pxssh` module of `pexpect` (https://github.com/pexpect/pexpect).
We have adjusted this workflow to our purposes.
"""
import pexpect # pylint: disable=import-error
import pexpect

# Create socket directory if it doesn't exist.
socket_dir = os.path.dirname(self._socket_path)
Expand Down
2 changes: 1 addition & 1 deletion omniduct/remotes/ssh_paramiko.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _init(self):

@override
def _connect(self):
import paramiko # pylint: disable=import-error
import paramiko

# pylint: disable-next=attribute-defined-outside-init
self.__client = paramiko.SSHClient()
Expand Down
2 changes: 1 addition & 1 deletion omniduct/restful/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def request(self, endpoint, method="get", **kwargs):
Returns:
requests.Response: The response object associated with this request.
"""
import requests # pylint: disable=import-error
import requests

url = urljoin(self.base_url, endpoint)
return requests.request(
Expand Down
4 changes: 2 additions & 2 deletions omniduct/utils/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ def show_about(
}

try:
from IPython import get_ipython # pylint: disable=import-error
from IPython.display import display, HTML # pylint: disable=import-error
from IPython import get_ipython
from IPython.display import display, HTML

ip = get_ipython()
if ip is not None and ip.has_trait("kernel"):
Expand Down
4 changes: 2 additions & 2 deletions omniduct/utils/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def wrapped(*args, **kwargs):


def _process_line_arguments(line_arguments):
from IPython import get_ipython # pylint: disable=import-error
from IPython import get_ipython

args = []
kwargs = {}
Expand Down Expand Up @@ -56,7 +56,7 @@ def register_magics(self, base_name=None):
raise RuntimeError("Cannot register magics without a base_name.")

try:
from IPython import get_ipython # pylint: disable=import-error
from IPython import get_ipython

ip = get_ipython()
assert ip is not None
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ disable = [
"duplicate-code",
"eval-used",
"fixme",
"import-error",
"import-outside-toplevel",
"invalid-name",
"line-too-long",
Expand Down

0 comments on commit 837d6e9

Please sign in to comment.