Skip to content

Commit

Permalink
bumped up version
Browse files Browse the repository at this point in the history
  • Loading branch information
LpCodes committed Mar 17, 2023
1 parent 51a874d commit 2e82a12
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions pypackageinspector/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from .main import inspector

__version__ = '1.0.2'
43 changes: 22 additions & 21 deletions pypackageinspector/main.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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}")



2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 2e82a12

Please sign in to comment.