Skip to content

Draft: Enable parsing of extension-less files #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pydeps/dummymodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ def is_module(directory):


def is_pysource(fname):
"""A file name is a python source file iff it ends with '.py' and doesn't
start with a dot.
"""A file name is a python source file iff (it's extensionless or
ends with '.py') and doesn't start with a dot.
"""
return not fname.startswith('.') and fname.endswith('.py')
if not fname.startswith('.'):
if len(fname.split('.')) == 1 or fname.endswith('.py'):
return True
return False


def fname2modname(fname, package_root):
Expand Down
3 changes: 2 additions & 1 deletion pydeps/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import tempfile
from contextlib import contextmanager

from . import dummymodule

class Target(object):
"""The compilation target.
Expand All @@ -28,7 +29,7 @@ def __init__(self, path):
sys.exit(1)
self.is_dir = os.path.isdir(self.path)
self.is_module = self.is_dir and '__init__.py' in os.listdir(self.path)
self.is_pysource = os.path.splitext(self.path)[1] in ('.py', '.pyc', '.pyo')
self.is_pysource = dummymodule.is_pysource(self.path)
self.fname = os.path.basename(self.path)
if self.is_dir:
self.dirname = self.fname
Expand Down
7 changes: 7 additions & 0 deletions tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def test_file():
with create_files(files) as workdir:
assert simpledeps('a.py') == set()

def test_file_no_py_extension():
files = """
a: |
import collections
"""
with create_files(files) as workdir:
assert 'other -> a' in simpledeps('a', '--pylib')

def test_file_pylib():
files = """
Expand Down