Compiler can load from file-like objects

This commit is contained in:
Andrew Elgert 2023-03-14 11:45:30 -04:00
parent 8dc51d70e7
commit b1f9eb45d2
2 changed files with 10 additions and 6 deletions

View File

@ -3,6 +3,7 @@ then
python -m venv .venv
. .venv/bin/activate
pip install -U coverage setuptools setuptools_scm wheel
pip install -e .
else
. .venv/bin/activate
fi

View File

@ -456,15 +456,18 @@ class Compiler:
def __init__(self):
self.root = Namespace(())
def load_filelike(self, module_path, f):
x = Decoder(f.read()).next()
if x.key == SCHEMA:
self.load_schema((Symbol(module_path),), x)
elif x.key == BUNDLE:
for (p, s) in x[0].items():
self.load_schema(p, s)
def load(self, filename):
filename = pathlib.Path(filename)
with open(filename, 'rb') as f:
x = Decoder(f.read()).next()
if x.key == SCHEMA:
self.load_schema((Symbol(filename.stem),), x)
elif x.key == BUNDLE:
for (p, s) in x[0].items():
self.load_schema(p, s)
self.load_filelike(filename.stem, f)
def load_schema(self, module_path, schema):
if schema[0][VERSION] != 1: