Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shangsky/module-tools
python module tools
https://github.com/shangsky/module-tools
Last synced: about 2 months ago
JSON representation
python module tools
- Host: GitHub
- URL: https://github.com/shangsky/module-tools
- Owner: ShangSky
- License: mit
- Created: 2022-04-15T08:53:07.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-04-18T07:43:51.000Z (over 2 years ago)
- Last Synced: 2024-11-14T19:11:31.202Z (about 2 months ago)
- Language: Python
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Module Tools
Tools for python modules
## Installation
```shell
$ pip install module-tools
```## Examples
```python
"""
package
__init__.py
sub_package
__init__.py
modulec.py -> var5, var6 = 3, "c"
modulea.py -> var1, var2, add = 1, "a", lambda a, b: a + b
moduleb.py -> var3, var4 = 2, "b"
"""from package.modulea import add
from module_tools import find_module_strings, find_modules, import_string, iter_objs_from_modules
add1 = import_string("package.modulea.add")
print(add1 is add) # Trueprint(set(find_module_strings("package")) == {"package.modulea", "package.moduleb"}) # True
print(
set(find_module_strings("package", recursive=True))
== {"package.modulea", "package.moduleb", "package.sub_pakage.modulec"}
) # True
from package import modulea, moduleb
from package.sub_package import modulecprint(set(find_modules("package")) == {modulea, moduleb}) # True
print(set(find_modules("package", recursive=True)) == {modulea, moduleb, modulec}) # Trueprint(set(iter_objs_from_modules(["package"], cls=int)) == {1, 2}) # True
print(set(iter_objs_from_modules(["package"], cls=int, recursive=True)) == {1, 2, 3}) # Trueprint(
set(iter_objs_from_modules(["package"], cls=int, recursive=True, func=lambda x: x < 3))
== {1, 2}
) # True
```