Skip to content

Commit 56ab70d

Browse files
committed
Add --find-package flag to automatically find the name of the current package.
1 parent 5b0b60b commit 56ab70d

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

.pre-commit-hooks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
- id: pydeps
22
name: Generate a graph of dependencies
3-
entry: pydeps
3+
entry: pydeps --find-package
44
language: python

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
# built documents.
5555
#
5656
# The short X.Y version.
57-
version = '1.9.4'
57+
version = '1.9.5'
5858
# The full version, including alpha/beta/rc tags.
59-
release = '1.9.4'
59+
release = '1.9.5'
6060

6161
# The language for content autogenerated by Sphinx. Refer to documentation
6262
# for a list of supported languages.

pydeps/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
Python module dependency visualization. This package installs the ``pydeps``
44
command, and normal usage will be to use it from the command line.
55
"""
6-
__version__ = "1.9.4"
6+
__version__ = "1.9.5"

pydeps/cli.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import logging
1212
import os
1313
import sys
14+
import subprocess
1415
import textwrap
1516
from . import __version__
1617

@@ -42,6 +43,17 @@ def _verbose(n, *args, **kwargs):
4243
return _verbose
4344

4445

46+
def _find_current_package():
47+
startdir = cwd = os.getcwd()
48+
while 'setup.py' not in os.listdir(cwd) and cwd != os.path.dirname(cwd):
49+
cwd = os.path.dirname(cwd)
50+
if 'setup.py' not in os.listdir(cwd):
51+
raise Exception("--find-package didn't find setup.py in current, or any parent, directory")
52+
os.chdir(cwd)
53+
package_name = subprocess.check_output("python setup.py --name", shell=True).decode('u8').strip()
54+
return package_name
55+
56+
4557
def base_argparser(argv=()):
4658
"""Initial parser that can set values for the rest of the parsing process.
4759
"""
@@ -56,6 +68,7 @@ def base_argparser(argv=()):
5668
_p.add_argument('-L', '--log', help=textwrap.dedent('''
5769
set log-level to one of CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET.
5870
'''))
71+
_p.add_argument('--find-package', action='store_true', help="tries to automatically find the name of the current package.")
5972
_args, argv = _p.parse_known_args(argv)
6073

6174
if _args.log:
@@ -82,7 +95,7 @@ def parse_args(argv=()):
8295
"""Parse command line arguments, and return a dict.
8396
"""
8497
_p, _args, argv = base_argparser(argv)
85-
98+
find_package = _args.find_package
8699
config_files = []
87100

88101
if not _args.no_config: # process config files
@@ -102,7 +115,12 @@ def parse_args(argv=()):
102115
config_files.append(home_pydeps)
103116

104117
args = Arguments(config_files, debug=True, parents=[_p])
105-
args.add('fname', kind="FNAME:input", help='filename')
118+
119+
if not find_package:
120+
args.add('fname', kind="FNAME:input", help='filename')
121+
else:
122+
args.add('--fname', kind="FNAME:input", help='filename')
123+
106124
args.add('-v', '--verbose', default=0, action='count', help="be more verbose (-vv, -vvv for more verbosity)")
107125
args.add('-o', default=None, kind="FNAME:output", dest='output', metavar="file", help="write output to 'file'")
108126
args.add('-T', default='svg', dest='format', help="output format (svg|png)")
@@ -141,7 +159,7 @@ def parse_args(argv=()):
141159
noise_level=200, noshow=True, output=None, pylib=False, pylib_all=False,
142160
show=False, show_cycles=False, show_deps=False, show_dot=False,
143161
show_raw_deps=False, verbose=0, include_missing=True, reverse=False,
144-
start_color=0
162+
start_color=0, find_package=False,
145163
)
146164

147165
_args.show = True
@@ -158,6 +176,8 @@ def parse_args(argv=()):
158176
_args.max_bacon = sys.maxsize
159177
if _args.keep_target_cluster or _args.min_cluster_size > 0 or _args.max_cluster_size > 0:
160178
_args.cluster = True
179+
if find_package:
180+
_args.fname = _find_current_package()
161181

162182
_args.format = getattr(_args, 'T', getattr(_args, 'format', None))
163183

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from distutils.core import setup
1212
from setuptools.command.test import test as TestCommand
1313

14-
version='1.9.4'
14+
version='1.9.5'
1515

1616

1717
class PyTest(TestCommand):

0 commit comments

Comments
 (0)