Skip to content

Commit

Permalink
tox -e lint
Browse files Browse the repository at this point in the history
  • Loading branch information
sloria committed Jan 18, 2024
1 parent 6c6d455 commit ea454df
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
22 changes: 13 additions & 9 deletions src/ped/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
Example: ped django.core.urlresolvers
"""
from types import ModuleType
from typing import Optional, Tuple, Any
import argparse
import importlib
import inspect
import os
import shlex
import subprocess
import sys
from pathlib import Path
from types import ModuleType
from typing import Any, Optional, Tuple

from .guess_module import guess_module, get_names_by_prefix
from .guess_module import get_names_by_prefix, guess_module
from .pypath import patch_sys_path
from .style import print_error, style, sprint, GREEN
from pathlib import Path
from .style import GREEN, print_error, sprint, style

__version__ = "2.1.0"

Expand Down Expand Up @@ -89,13 +89,15 @@ def get_info(ipath: str) -> Tuple[str, str, Optional[int]]:
module_name = ipath
try:
obj = import_object(module_name)
except ImportError:
except ImportError as error:
guessed = guess_module(ipath)
if guessed:
module_name = guessed[0]
obj = import_object(module_name)
else:
raise ImportError(f'Cannot find any module that matches "{ipath}"')
raise ImportError(
f'Cannot find any module that matches "{ipath}"'
) from error
fpath = find_file(obj)
if not fpath:
raise ImportError(f'Cannot find any module that matches "{ipath}"')
Expand All @@ -113,8 +115,10 @@ def import_object(ipath: str) -> ModuleType:
mod = importlib.import_module(module_name)
try:
return getattr(mod, symbol_name)
except AttributeError:
raise ImportError(f'Cannot import "{symbol_name}" from "{module_name}"')
except AttributeError as error:
raise ImportError(
f'Cannot import "{symbol_name}" from "{module_name}"'
) from error
raise err


Expand Down
2 changes: 1 addition & 1 deletion src/ped/guess_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Much of this code is adapted from IPython.core.completerlib
(see NOTICE for license information).
"""
from typing import List, Generator
import difflib
import inspect
import os
Expand All @@ -12,6 +11,7 @@
import time
import zipimport
from importlib.machinery import all_suffixes
from typing import Generator, List

_suffixes = all_suffixes()

Expand Down
4 changes: 2 additions & 2 deletions src/ped/install_completion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Script to install bash and zsh completion for ped."""
from pathlib import Path
import sys
import os
import sys
from pathlib import Path

from .style import print_error, style

Expand Down
4 changes: 2 additions & 2 deletions src/ped/pypath.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List
import sys
import shutil
import subprocess
import sys
from typing import List


def patch_sys_path() -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/ped/style.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional, IO, Any
import os
import sys
from typing import IO, Any, Optional

RED = 31
GREEN = 32
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ped.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import email
import email.mime
from email.mime.message import MIMEMessage
from pathlib import Path

import pytest
from scripttest import TestFileEnvironment as FileEnvironment

import ped
from ped.guess_module import guess_module
from pathlib import Path


def test_dir_opening(monkeypatch):
Expand Down

0 comments on commit ea454df

Please sign in to comment.