Skip to content

Commit

Permalink
deploy: aa3245f
Browse files Browse the repository at this point in the history
  • Loading branch information
olynch committed Nov 15, 2023
1 parent 6e6a784 commit ae73199
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Binary file modified .doctrees/environment.pickle
Binary file not shown.
13 changes: 8 additions & 5 deletions _modules/acsets/acsets.html
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ <h1>Source code for acsets.acsets</h1><div class="highlight"><pre>
<span class="n">ob_models</span> <span class="o">=</span> <span class="p">{</span>
<span class="n">ob</span><span class="p">:</span> <span class="n">create_model</span><span class="p">(</span>
<span class="n">ob</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
<span class="n">id_field_internal</span><span class="o">=</span><span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="n">Field</span><span class="p">(</span><span class="n">alias</span><span class="o">=</span><span class="s2">&quot;_id&quot;</span><span class="p">)),</span>
<span class="o">**</span><span class="p">{</span>
<span class="n">prop</span><span class="o">.</span><span class="n">name</span><span class="p">:</span> <span class="p">(</span><span class="n">Union</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">valtype</span><span class="p">(</span><span class="n">prop</span><span class="p">),</span> <span class="kc">None</span><span class="p">],</span> <span class="kc">None</span><span class="p">)</span>
<span class="k">for</span> <span class="n">prop</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">props_outof</span><span class="p">(</span><span class="n">ob</span><span class="p">)</span>
Expand Down Expand Up @@ -828,11 +829,13 @@ <h1>Source code for acsets.acsets</h1><div class="highlight"><pre>
<span class="sd"> Returns:</span>
<span class="sd"> A dictionary mapping property name to the value</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="p">{</span>
<span class="n">props</span> <span class="o">=</span> <span class="p">{</span>
<span class="n">f</span><span class="o">.</span><span class="n">name</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">subpart</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">f</span><span class="p">,</span> <span class="n">oneindex</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">schema</span><span class="o">.</span><span class="n">props_outof</span><span class="p">(</span><span class="n">ob</span><span class="p">)</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_subpart</span><span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
<span class="p">}</span></div>
<span class="p">}</span>
<span class="n">props</span><span class="p">[</span><span class="s2">&quot;_id&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span>
<span class="k">return</span> <span class="n">props</span></div>


<div class="viewcode-block" id="ACSet.export_pydantic">
Expand Down Expand Up @@ -889,7 +892,7 @@ <h1>Source code for acsets.acsets</h1><div class="highlight"><pre>
<span class="sd"> Returns:</span>
<span class="sd"> The JSON object of the serialized ACSet.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">export_pydantic</span><span class="p">()</span><span class="o">.</span><span class="n">dict</span><span class="p">()</span></div>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">export_pydantic</span><span class="p">()</span><span class="o">.</span><span class="n">dict</span><span class="p">(</span><span class="n">by_alias</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div>


<div class="viewcode-block" id="ACSet.to_json_file">
Expand All @@ -901,7 +904,7 @@ <h1>Source code for acsets.acsets</h1><div class="highlight"><pre>
<span class="sd"> fname: The file name to write the JSON to.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fname</span><span class="p">,</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fh</span><span class="p">:</span>
<span class="n">fh</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">to_json_str</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">))</span></div>
<span class="n">fh</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">to_json_str</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> <span class="n">by_alias</span><span class="o">=</span><span class="kc">True</span><span class="p">))</span></div>


<div class="viewcode-block" id="ACSet.to_json_str">
Expand All @@ -912,7 +915,7 @@ <h1>Source code for acsets.acsets</h1><div class="highlight"><pre>
<span class="sd"> Returns:</span>
<span class="sd"> The JSON string of the serialized ACSet.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">export_pydantic</span><span class="p">()</span><span class="o">.</span><span class="n">json</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span></div>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">export_pydantic</span><span class="p">()</span><span class="o">.</span><span class="n">json</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">,</span> <span class="n">by_alias</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span></div>


<div class="viewcode-block" id="ACSet.read_json">
Expand Down
11 changes: 7 additions & 4 deletions lib/acsets/acsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ def __init__(
ob_models = {
ob: create_model(
ob.name,
id_field_internal=(int, Field(alias="_id")),
**{
prop.name: (Union[self.valtype(prop), None], None)
for prop in self.props_outof(ob)
Expand Down Expand Up @@ -634,11 +635,13 @@ def prop_dict(self, ob: Ob, i: int) -> dict[str, Any]:
Returns:
A dictionary mapping property name to the value
"""
return {
props = {
f.name: self.subpart(i, f, oneindex=True)
for f in self.schema.props_outof(ob)
if self.has_subpart(i, f)
}
props["_id"] = i + 1
return props

def export_pydantic(self):
"""Serialize the ACSet to a pydantic model.
Expand Down Expand Up @@ -686,7 +689,7 @@ def to_json_obj(self):
Returns:
The JSON object of the serialized ACSet.
"""
return self.export_pydantic().dict()
return self.export_pydantic().dict(by_alias=True)

def to_json_file(self, fname, *args, **kwargs):
"""Serialize the ACSet to a JSON file.
Expand All @@ -695,15 +698,15 @@ def to_json_file(self, fname, *args, **kwargs):
fname: The file name to write the JSON to.
"""
with open(fname, "w") as fh:
fh.write(self.to_json_str(*args, **kwargs))
fh.write(self.to_json_str(*args, **kwargs, by_alias=True))

def to_json_str(self, *args, **kwargs):
"""Serialize the ACSet to a JSON string.
Returns:
The JSON string of the serialized ACSet.
"""
return self.export_pydantic().json(*args, **kwargs)
return self.export_pydantic().json(*args, **kwargs, by_alias=True)

@classmethod
def read_json(cls, name: str, schema: Schema, s: str):
Expand Down

0 comments on commit ae73199

Please sign in to comment.