Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Make module publicity determination respect $PYTHONPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
gbroques committed Aug 6, 2020
1 parent cec5793 commit 4b57b42
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/pydocstyle/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Python code parser."""

import sys
import textwrap
import tokenize as tk
from itertools import chain, dropwhile
Expand Down Expand Up @@ -126,9 +127,15 @@ def is_public(self):

def _is_inside_private_package(self):
"""Return True if the module is inside a private package."""
path = Path(self.name)
package_names = path.parts[:-1]
return any([self._is_private_name(package) for package in package_names])
path = Path(self.name).parent # Ignore the actual module's name
syspath = [Path(p) for p in sys.path] # Convert to pathlib.Path.

while path != path.parent and path not in syspath: # Bail if we are at the root directory or in `PYTHONPATH`.
if self._is_private_name(path.name):
return True
path = path.parent

return False

def _is_public_name(self, module_name):
"""Determine whether a "module name" (i.e. module or package name) is public."""
Expand Down
1 change: 1 addition & 0 deletions src/tests/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ def test_matrix_multiplication_with_decorators(code):


@pytest.mark.parametrize("public_path", (
Path(""),
Path("module.py"),
Path("package") / "module.py",
Path("package") / "__init__.py",
Expand Down

0 comments on commit 4b57b42

Please sign in to comment.