From 70506d71aa66816a6881d3ecef801ff81c272fde Mon Sep 17 00:00:00 2001 From: Michael Cusack <80846125+mpcusack-color@users.noreply.github.com> Date: Tue, 15 Jun 2021 10:53:09 -0700 Subject: [PATCH] Use inspect instead of dir for listing methods (#24) * Use inspect instead of dir for listing method --- clr/commands.py | 6 +++--- setup.py | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/clr/commands.py b/clr/commands.py index 82e83de2f9b..677dd6c8737 100644 --- a/clr/commands.py +++ b/clr/commands.py @@ -42,9 +42,9 @@ def _load_namespace(key): # Prefer doc string, otherwise explicit .longdescr, otherwise .descr longdescr = inspect.getdoc(instance) or getattr(instance, "longdescr", descr) command_callables = { - attribute_name[4:]: getattr(instance, attribute_name) - for attribute_name in dir(instance) - if attribute_name.startswith("cmd_") + method_name[4:]: method + for method_name, method in inspect.getmembers(self, inspect.ismethod) + if method_name.startswith("cmd_") } # Build CommandSpecs for each command. These contain metadata about the # command and its args. These are kept in a seperate dataclass from the diff --git a/setup.py b/setup.py index e02c900035e..b95a1f4ba04 100644 --- a/setup.py +++ b/setup.py @@ -4,17 +4,21 @@ setup( name="clr", - version="0.3.4", + version="0.3.5", description="A command line tool for executing custom python scripts.", author="Color", author_email="dev@getcolor.com", url="/~https://github.com/color/clr", packages=["clr"], - entry_points={"console_scripts": ["clr = clr:main"],}, + entry_points={ + "console_scripts": ["clr = clr:main"], + }, install_requires=requirements, setup_requires=["pytest-runner"], tests_require=requirements + ["pytest==6.2.4"], license="MIT", include_package_data=True, - package_data={"": ["completion.*"],}, + package_data={ + "": ["completion.*"], + }, )