From 2e82a12288511fe5fac0eb618988ef81daae9b59 Mon Sep 17 00:00:00 2001 From: LP Date: Fri, 17 Mar 2023 08:17:43 +0530 Subject: [PATCH] bumped up version --- README.md | 2 +- pypackageinspector/__init__.py | 2 ++ pypackageinspector/main.py | 43 +++++++++++++++++----------------- setup.py | 2 +- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 9e1e906..7331f74 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Publish Package](https://github.com/LpCodes/pypackageinspector/actions/workflows/python-publish.yml/badge.svg)](https://github.com/LpCodes/pypackageinspector/actions/workflows/python-publish.yml) +[![Publish Package](https://github.com/LpCodes/pypackageinspector/actions/workflows/python-publish.yml/badge.svg)](https://github.com/LpCodes/pypackageinspector/actions/workflows/python-publish.yml) ![PyPI](https://img.shields.io/pypi/v/pypackageinspector)[![Downloads](https://static.pepy.tech/personalized-badge/pypackageinspector?period=total&units=none&left_color=black&right_color=brightgreen&left_text=Downloads)](https://pepy.tech/project/pypackageinspector) # pypackageinspector pyCryptobox is a package in Python that inspects a Python package and prints out all the functions and methods defined in that package. It takes a single argument, package, which is a string representing the name of the package to be inspected. diff --git a/pypackageinspector/__init__.py b/pypackageinspector/__init__.py index 4f7d511..67f3f00 100644 --- a/pypackageinspector/__init__.py +++ b/pypackageinspector/__init__.py @@ -1 +1,3 @@ from .main import inspector + +__version__ = '1.0.2' diff --git a/pypackageinspector/main.py b/pypackageinspector/main.py index e1ae264..83d156c 100644 --- a/pypackageinspector/main.py +++ b/pypackageinspector/main.py @@ -1,7 +1,8 @@ import importlib.util +from typing import List -def inspector(package, inspect_functions=True, inspect_methods=True): +def inspector(package: str, inspect_functions: bool = True, inspect_methods: bool = True) -> None: """ Inspect a Python package and print out its functions and/or methods. @@ -13,35 +14,35 @@ def inspector(package, inspect_functions=True, inspect_methods=True): Returns: None """ - spec = importlib.util.find_spec(package) - - if spec is None: + try: + spec = importlib.util.find_spec(package) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + except (ImportError, AttributeError): print(f"Error: Package or module '{package}' not found.") return - module = importlib.import_module(package) - # get all functions and methods - functions = [] - methods = [] - if inspect_functions: - functions = [func for func in dir(module) if callable(getattr(module, func))] - if inspect_methods: - methods = [method for method in dir(module) if not callable(getattr(module, method))] + functions: List[str] = [] + methods: List[str] = [] + for name in dir(module): + obj = getattr(module, name) + if inspect_functions and callable(obj): + functions.append(name) + elif inspect_methods and not callable(obj): + methods.append(name) # print functions - if inspect_functions: - print("Functions:") + if inspect_functions and functions: + print("\n" + "=" * 20 + " Functions " + "=" * 20) for i, func in enumerate(functions): - print(f"{i}. {func}") + print(f"{i + 1}. {func}") # print methods - if inspect_methods: - if inspect_functions: - print("\nMethods:") - else: - print("Methods:") + if inspect_methods and methods: + print("\n" + "=" * 20 + " Methods " + "=" * 20) for i, method in enumerate(methods): - print(f"{i}. {method}") + print(f"{i + 1}. {method}") + diff --git a/setup.py b/setup.py index ce960a8..caee6d2 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="pypackageinspector", - version="1.0.1", + version="1.0.2", author="https://github.com/LpCodes", description="A Python package to inspect other Python packages.", long_description_content_type="text/markdown",