Skip to content

Commit

Permalink
NO SLEEP 'TIL 1.0.00000000000hhhhhh
Browse files Browse the repository at this point in the history
  • Loading branch information
dluman committed Dec 28, 2022
1 parent df54fda commit 0ec4c28
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Given the following template file (let's call it `Item.py`):
import time
from time import sleep

class Item(object):
class Item:

copy = False

Expand All @@ -38,6 +38,7 @@ def __dumb(self):
def main():
template = Form(mod = "Item", cls = "Item")
template.remove("time")
template.add_base(object)
template.make("ItemCopy", copy = True, __dumb = __dumb)

if __name__ == "__main__":
Expand All @@ -48,6 +49,9 @@ The module should make a new file in the current working directory: `ItemCopy.py
whose `__str__` magic will report to you that it's a _copy_ (the above example changes
the value of the `copy` instance variable).

As of a couple of minor versions ago (of course I forget which), you may not _remove_
things from the template by name _and_ add inhertiances (well, as of `0.6.0` at least).

## Notes

The module can handle single or multiple inheritance as of `0.2.0` -- find it everywhere
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setuptools.setup(
name="springform",
version="0.5.5",
version="0.6.0",
packages=['springform'],
package_dir={'springform': 'src'},
include_package_data=True,
Expand Down
14 changes: 13 additions & 1 deletion src/Forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, mod: str = "", cls: str = ""):
)
self.__elements = {
"impt": {},
"bases": {},
"bases": [],
"func": {},
"vars": {}
}
Expand Down Expand Up @@ -64,6 +64,7 @@ def __inherit(self) -> None:
bases = []
if self.__cls:
# TODO: Find a better way to get this information with libCST or ast
# (Maybe it already exists in the _Model__instance?)
mdl = eval(f"importlib.import_module('{self.__mod}').{self.__cls}")
for base in mdl.__bases__:
bases.append(base.__name__)
Expand All @@ -76,7 +77,18 @@ def __assemble(self) -> None:
)
self.__update(members)

def add_base(self, base: any) -> None:
""" Adds new base if not a duplicate """
if inspect.isclass(base):
base = base.__name__
if base not in self.__elements["bases"]:
self.__elements["bases"].append(base)
self.__elements["bases"].sort()

def remove(self, removal: str = "") -> None:
""" Removes an element by any root name """
if inspect.isclass(removal):
removal = removal.__name__
for category in self.__elements:
elements = self.__elements[category]
if removal in elements:
Expand Down

0 comments on commit 0ec4c28

Please sign in to comment.