Skip to content

Commit

Permalink
Generated gh-pages for commit 177f820
Browse files Browse the repository at this point in the history
Author: Giulio Ungaretti <giulio.ungaretti@gmail.com>

    fix: Recursively update the configuration object (#520)
  • Loading branch information
Documentation Bot committed Mar 16, 2017
1 parent 48f5349 commit f06a43c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
47 changes: 26 additions & 21 deletions _modules/qcodes/config/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@
<div itemprop="articleBody">

<h1>Source code for qcodes.config.config</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">copy</span>
<span></span><span class="kn">import</span> <span class="nn">collections</span>
<span class="kn">import</span> <span class="nn">copy</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">os</span>
Expand Down Expand Up @@ -286,19 +287,19 @@ <h1>Source code for qcodes.config.config</h1><div class="highlight"><pre>

<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">home_file_name</span><span class="p">):</span>
<span class="n">home_config</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">load_config</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">home_file_name</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">home_config</span><span class="p">)</span>
<span class="n">config</span> <span class="o">=</span> <span class="n">update</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">home_config</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_schema</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">schema_home_file_name</span><span class="p">)</span>

<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env_file_name</span><span class="p">):</span>
<span class="n">env_config</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">load_config</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">env_file_name</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">env_config</span><span class="p">)</span>
<span class="n">config</span> <span class="o">=</span> <span class="n">update</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">env_config</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_schema</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">schema_env_file_name</span><span class="p">)</span>

<span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cwd_file_name</span><span class="p">):</span>
<span class="n">cwd_config</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">load_config</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">cwd_file_name</span><span class="p">)</span>
<span class="n">config</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">cwd_config</span><span class="p">)</span>
<span class="n">config</span> <span class="o">=</span> <span class="n">update</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">cwd_config</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_schema</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">schema_cwd_file_name</span><span class="p">)</span>

Expand All @@ -325,9 +326,7 @@ <h1>Source code for qcodes.config.config</h1><div class="highlight"><pre>
<span class="c1"># be overwritten</span>
<span class="n">new_user</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">f</span><span class="p">)[</span><span class="s2">&quot;properties&quot;</span><span class="p">][</span><span class="s2">&quot;user&quot;</span><span class="p">]</span>
<span class="n">user</span> <span class="o">=</span> <span class="n">schema</span><span class="p">[</span><span class="s2">&quot;properties&quot;</span><span class="p">][</span><span class="s1">&#39;user&#39;</span><span class="p">]</span>
<span class="n">user</span><span class="p">[</span><span class="s2">&quot;properties&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span>
<span class="n">new_user</span><span class="p">[</span><span class="s2">&quot;properties&quot;</span><span class="p">]</span>
<span class="p">)</span>
<span class="n">user</span><span class="p">[</span><span class="s2">&quot;properties&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">new_user</span><span class="p">[</span><span class="s2">&quot;properties&quot;</span><span class="p">])</span>
<span class="n">jsonschema</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="n">json_config</span><span class="p">,</span> <span class="n">schema</span><span class="p">)</span>
<span class="k">else</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="n">EMPTY_USER_SCHEMA</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">extra_schema_path</span><span class="p">))</span>
Expand Down Expand Up @@ -396,11 +395,13 @@ <h1>Source code for qcodes.config.config</h1><div class="highlight"><pre>
<span class="c1"># update schema!</span>
<span class="n">schema_entry</span> <span class="o">=</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="n">value_type</span><span class="p">}}</span>
<span class="k">if</span> <span class="n">description</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">schema_entry</span> <span class="o">=</span> <span class="p">{</span><span class="n">key</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="n">value_type</span><span class="p">,</span>
<span class="s2">&quot;default&quot;</span><span class="p">:</span> <span class="n">default</span><span class="p">,</span>
<span class="s2">&quot;description&quot;</span><span class="p">:</span> <span class="n">description</span><span class="p">}</span>
<span class="p">}</span>
<span class="n">schema_entry</span> <span class="o">=</span> <span class="p">{</span>
<span class="n">key</span><span class="p">:</span> <span class="p">{</span>
<span class="s2">&quot;type&quot;</span><span class="p">:</span> <span class="n">value_type</span><span class="p">,</span>
<span class="s2">&quot;default&quot;</span><span class="p">:</span> <span class="n">default</span><span class="p">,</span>
<span class="s2">&quot;description&quot;</span><span class="p">:</span> <span class="n">description</span>
<span class="p">}</span>
<span class="p">}</span>
<span class="c1"># the schema is nested we only update properties of the user object</span>
<span class="n">user</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_schema</span><span class="p">[</span><span class="s1">&#39;properties&#39;</span><span class="p">][</span><span class="s2">&quot;user&quot;</span><span class="p">]</span>
<span class="n">user</span><span class="p">[</span><span class="s2">&quot;properties&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">schema_entry</span><span class="p">)</span>
Expand Down Expand Up @@ -500,12 +501,7 @@ <h1>Source code for qcodes.config.config</h1><div class="highlight"><pre>
<span class="c1"># add cool description to docstring</span>
<span class="n">base_docstring</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span><span class="si">{}</span><span class="s2">.</span><span class="se">\n</span><span class="s2">Current value: </span><span class="si">{}</span><span class="s2">. Type: </span><span class="si">{}</span><span class="s2">. Default: </span><span class="si">{}</span><span class="s2">.&quot;&quot;&quot;</span>

<span class="n">doc</span> <span class="o">=</span> <span class="n">base_docstring</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
<span class="n">description</span><span class="p">,</span>
<span class="n">val</span><span class="p">,</span>
<span class="n">_type</span><span class="p">,</span>
<span class="n">default</span>
<span class="p">)</span>
<span class="n">doc</span> <span class="o">=</span> <span class="n">base_docstring</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">description</span><span class="p">,</span> <span class="n">val</span><span class="p">,</span> <span class="n">_type</span><span class="p">,</span> <span class="n">default</span><span class="p">)</span>

<span class="k">return</span> <span class="n">doc</span>

Expand All @@ -521,15 +517,14 @@ <h1>Source code for qcodes.config.config</h1><div class="highlight"><pre>
<span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">old</span> <span class="o">=</span> <span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__repr__</span><span class="p">()</span>
<span class="n">base</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;Current values: </span><span class="se">\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2"> Current path: </span><span class="se">\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2"> </span><span class="se">\n</span><span class="s2"> </span><span class="si">{}</span><span class="s2">&quot;&quot;&quot;</span>
<span class="k">return</span> <span class="n">base</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">current_config</span><span class="p">,</span>
<span class="bp">self</span><span class="o">.</span><span class="n">current_config_path</span><span class="p">,</span>
<span class="n">old</span><span class="p">)</span></div>
<span class="k">return</span> <span class="n">base</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">current_config</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">current_config_path</span><span class="p">,</span> <span class="n">old</span><span class="p">)</span></div>


<span class="k">class</span> <span class="nc">DotDict</span><span class="p">(</span><span class="nb">dict</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Wrapper dict that allows to get dotted attributes</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="k">if</span> <span class="n">value</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
<span class="k">pass</span>
Expand Down Expand Up @@ -567,6 +562,16 @@ <h1>Source code for qcodes.config.config</h1><div class="highlight"><pre>
<span class="c1"># dot acces baby</span>
<span class="fm">__setattr__</span> <span class="o">=</span> <span class="fm">__setitem__</span>
<span class="fm">__getattr__</span> <span class="o">=</span> <span class="fm">__getitem__</span>


<span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="n">d</span><span class="p">,</span> <span class="n">u</span><span class="p">):</span>
<span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">u</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="n">collections</span><span class="o">.</span><span class="n">Mapping</span><span class="p">):</span>
<span class="n">r</span> <span class="o">=</span> <span class="n">update</span><span class="p">(</span><span class="n">d</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="p">{}),</span> <span class="n">v</span><span class="p">)</span>
<span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">r</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="o">=</span> <span class="n">u</span><span class="p">[</span><span class="n">k</span><span class="p">]</span>
<span class="k">return</span> <span class="n">d</span>
</pre></div>

</div>
Expand Down
2 changes: 1 addition & 1 deletion api/generated/qcodes.instrument_drivers.QDev.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this

<dl class="attribute">
<dt id="qcodes.instrument_drivers.QDev.QDac.QDac.voltage_range_status">
<code class="descname">voltage_range_status</code><em class="property"> = {'X 0.1': 1, 'X 1': 10}</em><a class="headerlink" href="#qcodes.instrument_drivers.QDev.QDac.QDac.voltage_range_status" title="Permalink to this definition"></a></dt>
<code class="descname">voltage_range_status</code><em class="property"> = {'X 1': 10, 'X 0.1': 1}</em><a class="headerlink" href="#qcodes.instrument_drivers.QDev.QDac.QDac.voltage_range_status" title="Permalink to this definition"></a></dt>
<dd></dd></dl>

<dl class="method">
Expand Down
2 changes: 1 addition & 1 deletion api/generated/qcodes.instrument_drivers.ithaco.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ <h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>measured_param</strong> (<a class="reference internal" href="qcodes.Parameter.html#qcodes.Parameter" title="qcodes.Parameter"><em>Parameter</em></a>) &#8211; a gettable parameter returning the
voltage read from the Ithaco output.</li>
<li><strong>c_amp_ins</strong> (<a class="reference internal" href="#qcodes.instrument_drivers.ithaco.Ithaco_1211.Ithaco_1211" title="qcodes.instrument_drivers.ithaco.Ithaco_1211.Ithaco_1211"><em>Ithaco_1211</em></a>) &#8211; <p>an Ithaco instance where you manually
<li><strong>c_amp_ins</strong> (<a class="reference internal" href="#module-qcodes.instrument_drivers.ithaco.Ithaco_1211" title="qcodes.instrument_drivers.ithaco.Ithaco_1211"><em>Ithaco_1211</em></a>) &#8211; <p>an Ithaco instance where you manually
maintain the present settings of the real Ithaco amp.</p>
<p>Note: it should be possible to use other current preamps, if they
define parameters <code class="docutils literal"><span class="pre">sens</span></code> (sensitivity, in A/V), <code class="docutils literal"><span class="pre">sens_factor</span></code>
Expand Down
Loading

0 comments on commit f06a43c

Please sign in to comment.