Skip to content

Commit

Permalink
Merge pull request #9 from Parquery/mristin/ignore-ImportError-when-g…
Browse files Browse the repository at this point in the history
…etting-the-module-of-the-file

ignore ImportError when getting the module of the file
  • Loading branch information
mristin authored Sep 21, 2018
2 parents 082f3eb + 53e7951 commit c4110dc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
1.1.1
=====
* ``ImportError`` is ignored if module of the file could not be figured out (*e.g.* when the ``__init__.py`` is
missing in the directory which is often the case for the scripts).

1.1.0
=====
* Ignore files with ``# pyicontract-lint=disabled``
Expand Down
5 changes: 4 additions & 1 deletion icontract_lint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ def check_file(path: pathlib.Path) -> List[Error]:
if _DISABLED_DIRECTIVE_RE.match(line):
return []

modname = ".".join(astroid.modutils.modpath_from_file(filename=path.as_posix()))
try:
modname = ".".join(astroid.modutils.modpath_from_file(filename=path.as_posix()))
except ImportError:
modname = '<unknown module>'

try:
tree = astroid.parse(code=text, module_name=modname, path=path.as_posix())
Expand Down
2 changes: 1 addition & 1 deletion pyicontract_lint_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__title__ = 'pyicontract-lint'
__description__ = 'Lint contracts defined with icontract library.'
__url__ = 'https://github.com/Parquery/pyicontract-lint'
__version__ = '1.1.0'
__version__ = '1.1.1'
__author__ = 'Marko Ristin'
__author_email__ = 'marko.ristin@gmail.com'
__license__ = 'MIT'
Expand Down

0 comments on commit c4110dc

Please sign in to comment.