captain-kark / python-module-resources Goto Github PK
View Code? Open in Web Editor NEWImport non-python files in a project directory as python namedtuple objects.
License: MIT License
Import non-python files in a project directory as python namedtuple objects.
License: MIT License
The __iter__
method is currently designed to help dict()
work easily, but it makes for-loops deal with dicts, making things clumsy when working with loops.
Find a way to continue using __iter__
as dicts for calls to dict()
, while avoiding this type of interaction in loops.
from some_module_resource import module_json_resource
dict(module_json_resource)
# {"first": {"namedtuple": True}, "second": {"namedtuple": True}}
for resource_key, dict_value in module_json_resource:
namedtuple_value = getattr(module_json_resource, resource_key)
print(hasattr(namedtuple_value.second))
You should be able to import a module and have the contents of the imported object sourced from someplace like /var/config
, /tmp/whatever/
, etc.
Imports would still be requesting the same module that the associated __init__.py
file is located in. It would just affect where the source json/yaml files are searched for.
This might already be the default behavior. If it isn't, it should support this.
You can specify a placeholder Any-typed variable reference in the init file for each module object that is intended to be importable to fix pylint errors.
Yaml configuration files work as well, with the module_resources.YamlResourceModule class.
Should be module_resources.YamlModuleResource
.
This came up during manual testing. I fixed it, but a regression test needs to be written.
See references to clean_value
in module_resources.py for where I handled this issue in the first place.
Running dict()
had a side effect of altering the namedtuple as it iterated through it.
Currently it throws an attribute error, but the message itself should give more details about the source of this fallback dict object, and why the property must be accessed via key.
A resource object should know how to write itself back to the filesystem in the same location and format it was in when it was imported.
Add a new directory, module_resources/examples/{json,yaml}/subdirectory
to the examples, and ensure that imports are handled orderly.
Account for matching names between a file in the module's top-level directory, and a subdirectory within the module. Use from
to distinguish these submodule imports versus named documents in the top-level.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.