Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 8, 2024
1 parent b240dfd commit 1f2abe2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 3 additions & 1 deletion _modules/one/api.html
Original file line number Diff line number Diff line change
Expand Up @@ -2032,8 +2032,10 @@ <h1>Source code for one.api</h1><div class="highlight"><pre>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">[</span><span class="s1">&#39;datasets&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">iloc</span><span class="p">[</span><span class="mi">0</span><span class="p">:</span><span class="mi">0</span><span class="p">]</span> <span class="k">if</span> <span class="n">details</span> <span class="k">else</span> <span class="p">[]</span> <span class="c1"># Return empty</span>
<span class="k">assert</span> <span class="nb">set</span><span class="p">(</span><span class="n">datasets</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">unique</span><span class="p">(</span><span class="s1">&#39;eid&#39;</span><span class="p">))</span> <span class="o">==</span> <span class="p">{</span><span class="n">eid</span><span class="p">}</span>
<span class="k">del</span> <span class="n">filters</span><span class="p">[</span><span class="s1">&#39;default_revisions_only&#39;</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">keep_eid_index</span> <span class="ow">and</span> <span class="s1">&#39;eid&#39;</span> <span class="ow">in</span> <span class="n">datasets</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">names</span><span class="p">:</span>
<span class="n">datasets</span> <span class="o">=</span> <span class="n">datasets</span><span class="o">.</span><span class="n">droplevel</span><span class="p">(</span><span class="s1">&#39;eid&#39;</span><span class="p">)</span>
<span class="n">datasets</span> <span class="o">=</span> <span class="n">util</span><span class="o">.</span><span class="n">filter_datasets</span><span class="p">(</span>
<span class="n">datasets</span><span class="o">.</span><span class="n">droplevel</span><span class="p">(</span><span class="s1">&#39;eid&#39;</span><span class="p">),</span> <span class="n">assert_unique</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">wildcards</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">wildcards</span><span class="p">,</span> <span class="o">**</span><span class="n">filters</span><span class="p">)</span>
<span class="n">datasets</span><span class="p">,</span> <span class="n">assert_unique</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">wildcards</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">wildcards</span><span class="p">,</span> <span class="o">**</span><span class="n">filters</span><span class="p">)</span>
<span class="c1"># Return only the relative path</span>
<span class="k">return</span> <span class="n">datasets</span> <span class="k">if</span> <span class="n">details</span> <span class="k">else</span> <span class="n">datasets</span><span class="p">[</span><span class="s1">&#39;rel_path&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">sort_values</span><span class="p">()</span><span class="o">.</span><span class="n">values</span><span class="o">.</span><span class="n">tolist</span><span class="p">()</span></div>

Expand Down
5 changes: 5 additions & 0 deletions _modules/one/tests/test_one.html
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,11 @@ <h1>Source code for one.tests.test_one</h1><div class="highlight"><pre>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="mi">183</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">dsets</span><span class="p">))</span> <span class="c1"># this may change after a BWM release or patch</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">dsets</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">nlevels</span><span class="p">,</span> <span class="s1">&#39;details data frame should be without eid index&#39;</span><span class="p">)</span>

<span class="c1"># Test keep_eid_index</span>
<span class="n">dsets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">list_datasets</span><span class="p">(</span>
<span class="bp">self</span><span class="o">.</span><span class="n">eid</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">query_type</span><span class="o">=</span><span class="s1">&#39;remote&#39;</span><span class="p">,</span> <span class="n">keep_eid_index</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertEqual</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">dsets</span><span class="o">.</span><span class="n">index</span><span class="o">.</span><span class="n">nlevels</span><span class="p">,</span> <span class="s1">&#39;details data frame should be with eid index&#39;</span><span class="p">)</span>

<span class="c1"># Test missing eid</span>
<span class="n">dsets</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">one</span><span class="o">.</span><span class="n">list_datasets</span><span class="p">(</span><span class="s1">&#39;FMR019/2021-03-18/008&#39;</span><span class="p">,</span> <span class="n">details</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">query_type</span><span class="o">=</span><span class="s1">&#39;remote&#39;</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">assertIsInstance</span><span class="p">(</span><span class="n">dsets</span><span class="p">,</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">)</span>
Expand Down
15 changes: 8 additions & 7 deletions _modules/one/webclient.html
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ <h1>Source code for one.webclient</h1><div class="highlight"><pre>
<span class="n">rest_query</span> <span class="o">=</span> <span class="n">rest_query</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">base_url</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">rest_query</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">):</span>
<span class="n">rest_query</span> <span class="o">=</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="n">rest_query</span>
<span class="n">_logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">base_url</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">rest_query</span><span class="si">}</span><span class="s2">, headers: </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_headers</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
<span class="n">_logger</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">base_url</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">rest_query</span><span class="si">}</span><span class="s1">, headers: </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">_headers</span><span class="si">}</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="n">headers</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_headers</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
<span class="k">if</span> <span class="n">files</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="nb">dict</span><span class="p">)</span> <span class="ow">or</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="k">else</span> <span class="n">data</span>
Expand Down Expand Up @@ -813,8 +813,8 @@ <h1>Source code for one.webclient</h1><div class="highlight"><pre>
<span class="n">rep</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">base_url</span> <span class="o">+</span> <span class="s1">&#39;/auth-token&#39;</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">credentials</span><span class="p">)</span>
<span class="k">except</span> <span class="n">requests</span><span class="o">.</span><span class="n">exceptions</span><span class="o">.</span><span class="n">ConnectionError</span><span class="p">:</span>
<span class="k">raise</span> <span class="ne">ConnectionError</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;Can&#39;t connect to </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">base_url</span><span class="si">}</span><span class="s2">.</span><span class="se">\n</span><span class="s2">&quot;</span> <span class="o">+</span>
<span class="s2">&quot;Check your internet connections and Alyx database firewall&quot;</span>
<span class="sa">f</span><span class="s1">&#39;Can</span><span class="se">\&#39;</span><span class="s1">t connect to </span><span class="si">{</span><span class="bp">self</span><span class="o">.</span><span class="n">base_url</span><span class="si">}</span><span class="s1">.</span><span class="se">\n</span><span class="s1">&#39;</span> <span class="o">+</span>
<span class="s1">&#39;Check your internet connections and Alyx database firewall&#39;</span>
<span class="p">)</span>
<span class="c1"># Assign token or raise exception on auth error</span>
<span class="k">if</span> <span class="n">rep</span><span class="o">.</span><span class="n">ok</span><span class="p">:</span>
Expand Down Expand Up @@ -987,6 +987,7 @@ <h1>Source code for one.webclient</h1><div class="highlight"><pre>

<span class="k">def</span> <span class="nf">_validate_file_url</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">url</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Asserts that URL matches HTTP_DATA_SERVER parameter.</span>

<span class="sd"> Currently only one remote HTTP server is supported for a given AlyxClient instance. If</span>
<span class="sd"> the URL contains only the relative path part, the full URL is returned.</span>

Expand Down Expand Up @@ -1234,7 +1235,7 @@ <h1>Source code for one.webclient</h1><div class="highlight"><pre>
<span class="k">if</span> <span class="s1">&#39;django&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;django&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;django&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;,&#39;</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;django&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;django&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
<span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;django&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;django&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">pk,</span><span class="si">{</span><span class="nb">id</span><span class="si">}</span><span class="s2">&quot;</span>
<span class="c1"># otherwise, look for a dictionary of filter terms</span>
<span class="k">if</span> <span class="n">kwargs</span><span class="p">:</span>
Expand Down Expand Up @@ -1303,7 +1304,7 @@ <h1>Source code for one.webclient</h1><div class="highlight"><pre>
<span class="c1"># Prepare data to patch</span>
<span class="n">patch_dict</span> <span class="o">=</span> <span class="p">{</span><span class="n">field_name</span><span class="p">:</span> <span class="n">data</span><span class="p">}</span>
<span class="c1"># Upload new extended_qc to session</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rest</span><span class="p">(</span><span class="n">endpoint</span><span class="p">,</span> <span class="s2">&quot;partial_update&quot;</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">patch_dict</span><span class="p">)</span>
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">rest</span><span class="p">(</span><span class="n">endpoint</span><span class="p">,</span> <span class="s1">&#39;partial_update&#39;</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="n">uuid</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">patch_dict</span><span class="p">)</span>
<span class="k">return</span> <span class="n">ret</span><span class="p">[</span><span class="n">field_name</span><span class="p">]</span></div>


Expand Down Expand Up @@ -1352,7 +1353,7 @@ <h1>Source code for one.webclient</h1><div class="highlight"><pre>

<span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">current</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
<span class="n">_logger</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span>
<span class="sa">f</span><span class="s1">&#39;Current json field </span><span class="si">{</span><span class="n">field_name</span><span class="si">}</span><span class="s1"> does not contains a dict, aborting update&#39;</span>
<span class="sa">f</span><span class="s1">&#39;Current json field &quot;</span><span class="si">{</span><span class="n">field_name</span><span class="si">}</span><span class="s1">&quot; does not contains a dict, aborting update&#39;</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">current</span>

Expand Down Expand Up @@ -1410,7 +1411,7 @@ <h1>Source code for one.webclient</h1><div class="highlight"><pre>
<span class="sa">f</span><span class="s1">&#39;</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s1">: Key not found in endpoint </span><span class="si">{</span><span class="n">endpoint</span><span class="si">}</span><span class="s1"> field </span><span class="si">{</span><span class="n">field_name</span><span class="si">}</span><span class="s1">&#39;</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">current</span>
<span class="n">_logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Removing key from dict: &#39;</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s2">&#39;&quot;</span><span class="p">)</span>
<span class="n">_logger</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="sa">f</span><span class="s1">&#39;Removing key from dict: &quot;</span><span class="si">{</span><span class="n">key</span><span class="si">}</span><span class="s1">&quot;&#39;</span><span class="p">)</span>
<span class="n">current</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">key</span><span class="p">)</span>
<span class="c1"># Re-write contents without removed key</span>
<span class="n">written</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">json_field_write</span><span class="p">(</span>
Expand Down

0 comments on commit 1f2abe2

Please sign in to comment.