draugr.html 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>draugr &#8212; Draugr 1.0.1 documentation</title>
  7. <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
  8. <link rel="stylesheet" type="text/css" href="../_static/alabaster.css" />
  9. <link rel="stylesheet" type="text/css" href="../_static/graphviz.css" />
  10. <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
  11. <script src="../_static/jquery.js"></script>
  12. <script src="../_static/underscore.js"></script>
  13. <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
  14. <script src="../_static/doctools.js"></script>
  15. <link rel="canonical" href="pything.github.io/draugr/_modules/draugr.html" />
  16. <link rel="index" title="Index" href="../genindex.html" />
  17. <link rel="search" title="Search" href="../search.html" />
  18. <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  19. <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
  20. </head><body>
  21. <div class="document">
  22. <div class="documentwrapper">
  23. <div class="bodywrapper">
  24. <div class="body" role="main">
  25. <h1>Source code for draugr</h1><div class="highlight"><pre>
  26. <span></span><span class="ch">#!/usr/bin/env python3</span>
  27. <span class="c1"># -*- coding: utf-8 -*-</span>
  28. <span class="n">__project__</span> <span class="o">=</span> <span class="s2">&quot;Draugr&quot;</span>
  29. <span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Christian Heider Nielsen&quot;</span>
  30. <span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0.1&quot;</span>
  31. <span class="vm">__doc__</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">&quot;&quot;&quot;</span>
  32. <span class="s2">Created on 27/04/2019</span>
  33. <span class="s2">@author: cnheider</span>
  34. <span class="s2">&quot;&quot;&quot;</span>
  35. <span class="kn">import</span> <span class="nn">datetime</span>
  36. <span class="kn">import</span> <span class="nn">os</span>
  37. <span class="kn">from</span> <span class="nn">logging</span> <span class="kn">import</span> <span class="n">warning</span>
  38. <span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span>
  39. <span class="kn">import</span> <span class="nn">pkg_resources</span>
  40. <span class="kn">from</span> <span class="nn">apppath</span> <span class="kn">import</span> <span class="n">AppPath</span>
  41. <span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
  42. <span class="c1"># from .drawers import *</span>
  43. <span class="c1"># from .writers import *</span>
  44. <span class="c1"># from .opencv_utilities import *</span>
  45. <span class="c1"># from .torch_utilities import *</span>
  46. <span class="c1"># from .stopping import *</span>
  47. <span class="c1"># from .numpy_utilities import *</span>
  48. <span class="c1"># from .visualisation import *</span>
  49. <span class="kn">from</span> <span class="nn">.metrics</span> <span class="kn">import</span> <span class="o">*</span>
  50. <span class="kn">from</span> <span class="nn">.python_utilities</span> <span class="kn">import</span> <span class="o">*</span>
  51. <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">Path</span><span class="p">(</span><span class="vm">__file__</span><span class="p">)</span><span class="o">.</span><span class="n">parent</span> <span class="o">/</span> <span class="s2">&quot;README.md&quot;</span><span class="p">,</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">this_init_file</span><span class="p">:</span>
  52. <span class="vm">__doc__</span> <span class="o">+=</span> <span class="n">this_init_file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span>
  53. <span class="c1"># with open(Path(__file__).parent.parent / &quot;README.md&quot;, &quot;r&quot;) as this_init_file:</span>
  54. <span class="c1"># __doc__ += this_init_file.read()</span>
  55. <span class="c1"># __all__ = [&quot;PROJECT_APP_PATH&quot;, &quot;PROJECT_NAME&quot;, &quot;PROJECT_VERSION&quot;, &quot;get_version&quot;]</span>
  56. <div class="viewcode-block" id="dist_is_editable"><a class="viewcode-back" href="../generated/draugr.dist_is_editable.html#draugr.dist_is_editable">[docs]</a><span class="k">def</span> <span class="nf">dist_is_editable</span><span class="p">(</span><span class="n">dist</span><span class="p">:</span> <span class="n">Any</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">bool</span><span class="p">:</span>
  57. <span class="sd">&quot;&quot;&quot;</span>
  58. <span class="sd"> Return True if given Distribution is an editable installation.&quot;&quot;&quot;</span>
  59. <span class="kn">import</span> <span class="nn">sys</span>
  60. <span class="k">for</span> <span class="n">path_item</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="p">:</span>
  61. <span class="n">egg_link</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">path_item</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">dist</span><span class="o">.</span><span class="n">project_name</span><span class="si">}</span><span class="s2">.egg-link&quot;</span>
  62. <span class="k">if</span> <span class="n">egg_link</span><span class="o">.</span><span class="n">is_file</span><span class="p">():</span>
  63. <span class="k">return</span> <span class="kc">True</span>
  64. <span class="k">return</span> <span class="kc">False</span></div>
  65. <span class="n">PROJECT_ORGANISATION</span> <span class="o">=</span> <span class="s2">&quot;pything&quot;</span>
  66. <span class="n">PROJECT_NAME</span> <span class="o">=</span> <span class="n">__project__</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="s2">&quot;_&quot;</span><span class="p">)</span>
  67. <span class="n">PROJECT_VERSION</span> <span class="o">=</span> <span class="n">__version__</span>
  68. <span class="n">PROJECT_YEAR</span> <span class="o">=</span> <span class="mi">2018</span>
  69. <span class="n">PROJECT_AUTHOR</span> <span class="o">=</span> <span class="n">__author__</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="s2">&quot;_&quot;</span><span class="p">)</span>
  70. <span class="n">PROJECT_APP_PATH</span> <span class="o">=</span> <span class="n">AppPath</span><span class="p">(</span><span class="n">app_name</span><span class="o">=</span><span class="n">PROJECT_NAME</span><span class="p">,</span> <span class="n">app_author</span><span class="o">=</span><span class="n">PROJECT_AUTHOR</span><span class="p">)</span>
  71. <span class="n">PACKAGE_DATA_PATH</span> <span class="o">=</span> <span class="n">Path</span><span class="p">(</span><span class="n">pkg_resources</span><span class="o">.</span><span class="n">resource_filename</span><span class="p">(</span><span class="n">PROJECT_NAME</span><span class="p">,</span> <span class="s2">&quot;data&quot;</span><span class="p">))</span>
  72. <span class="n">INCLUDE_PROJECT_READMES</span> <span class="o">=</span> <span class="kc">False</span>
  73. <span class="n">distributions</span> <span class="o">=</span> <span class="p">{</span><span class="n">v</span><span class="o">.</span><span class="n">key</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">pkg_resources</span><span class="o">.</span><span class="n">working_set</span><span class="p">}</span>
  74. <span class="k">if</span> <span class="n">PROJECT_NAME</span> <span class="ow">in</span> <span class="n">distributions</span><span class="p">:</span>
  75. <span class="n">distribution</span> <span class="o">=</span> <span class="n">distributions</span><span class="p">[</span><span class="n">PROJECT_NAME</span><span class="p">]</span>
  76. <span class="n">DEVELOP</span> <span class="o">=</span> <span class="n">dist_is_editable</span><span class="p">(</span><span class="n">distribution</span><span class="p">)</span>
  77. <span class="k">else</span><span class="p">:</span>
  78. <span class="n">DEVELOP</span> <span class="o">=</span> <span class="kc">True</span>
  79. <div class="viewcode-block" id="get_version"><a class="viewcode-back" href="../generated/draugr.get_version.html#draugr.get_version">[docs]</a><span class="k">def</span> <span class="nf">get_version</span><span class="p">(</span><span class="n">append_time</span><span class="p">:</span> <span class="n">Any</span> <span class="o">=</span> <span class="n">DEVELOP</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">str</span><span class="p">:</span>
  80. <span class="sd">&quot;&quot;&quot;description&quot;&quot;&quot;</span>
  81. <span class="n">version</span> <span class="o">=</span> <span class="n">__version__</span>
  82. <span class="k">if</span> <span class="ow">not</span> <span class="n">version</span><span class="p">:</span>
  83. <span class="n">version</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s2">&quot;VERSION&quot;</span><span class="p">,</span> <span class="s2">&quot;0.0.0&quot;</span><span class="p">)</span>
  84. <span class="k">if</span> <span class="n">append_time</span><span class="p">:</span>
  85. <span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span>
  86. <span class="n">date_version</span> <span class="o">=</span> <span class="n">now</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s2">&quot;%Y%m</span><span class="si">%d</span><span class="s2">%H%M%S&quot;</span><span class="p">)</span>
  87. <span class="c1"># date_version = time.time()</span>
  88. <span class="k">if</span> <span class="n">version</span><span class="p">:</span>
  89. <span class="c1"># Most git tags are prefixed with &#39;v&#39; (example: v1.2.3) this is</span>
  90. <span class="c1"># never desirable for artifact repositories, so we strip the</span>
  91. <span class="c1"># leading &#39;v&#39; if it&#39;s present.</span>
  92. <span class="n">version</span> <span class="o">=</span> <span class="p">(</span>
  93. <span class="n">version</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
  94. <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">version</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="ow">and</span> <span class="n">version</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;v&quot;</span><span class="p">)</span>
  95. <span class="k">else</span> <span class="n">version</span>
  96. <span class="p">)</span>
  97. <span class="k">else</span><span class="p">:</span>
  98. <span class="c1"># Default version is an ISO8601 compliant datetime. PyPI doesn&#39;t allow</span>
  99. <span class="c1"># the colon &#39;:&#39; character in its versions, and time is required to allow</span>
  100. <span class="c1"># for multiple publications to master in one day. This datetime string</span>
  101. <span class="c1"># uses the &#39;basic&#39; ISO8601 format for both its date and time components</span>
  102. <span class="c1"># to avoid issues with the colon character (ISO requires that date and</span>
  103. <span class="c1"># time components of a date-time string must be uniformly basic or</span>
  104. <span class="c1"># extended, which is why the date component does not have dashes.</span>
  105. <span class="c1">#</span>
  106. <span class="c1"># Publications using datetime versions should only be made from master</span>
  107. <span class="c1"># to represent the HEAD moving forward.</span>
  108. <span class="n">warning</span><span class="p">(</span>
  109. <span class="sa">f</span><span class="s2">&quot;Environment variable VERSION is not set, only using datetime: </span><span class="si">{</span><span class="n">date_version</span><span class="si">}</span><span class="s2">&quot;</span>
  110. <span class="p">)</span>
  111. <span class="c1"># warn(f&#39;Environment variable VERSION is not set, only using timestamp: {version}&#39;)</span>
  112. <span class="n">version</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">version</span><span class="si">}</span><span class="s2">.</span><span class="si">{</span><span class="n">date_version</span><span class="si">}</span><span class="s2">&quot;</span>
  113. <span class="k">return</span> <span class="n">version</span></div>
  114. <span class="k">if</span> <span class="n">__version__</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
  115. <span class="n">__version__</span> <span class="o">=</span> <span class="n">get_version</span><span class="p">(</span><span class="n">append_time</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
  116. <span class="n">__version_info__</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">segment</span><span class="p">)</span> <span class="k">for</span> <span class="n">segment</span> <span class="ow">in</span> <span class="n">__version__</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;.&quot;</span><span class="p">))</span>
  117. </pre></div>
  118. </div>
  119. </div>
  120. </div>
  121. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  122. <div class="sphinxsidebarwrapper">
  123. <p class="logo"><a href="../index.html">
  124. <img class="logo" src="../_static/valknut.svg" alt="Logo"/>
  125. </a></p>
  126. <h1 class="logo"><a href="../index.html">Draugr</a></h1>
  127. <h3>Navigation</h3>
  128. <ul>
  129. <li class="toctree-l1"><a class="reference internal" href="../generated/draugr.html">draugr</a></li>
  130. </ul>
  131. <p class="caption" role="heading"><span class="caption-text">Notes</span></p>
  132. <ul>
  133. <li class="toctree-l1"><a class="reference internal" href="../getting_started.html">Getting Started</a></li>
  134. </ul>
  135. <div class="relations">
  136. <h3>Related Topics</h3>
  137. <ul>
  138. <li><a href="../index.html">Documentation overview</a><ul>
  139. <li><a href="index.html">Module code</a><ul>
  140. </ul></li>
  141. </ul></li>
  142. </ul>
  143. </div>
  144. <div id="searchbox" style="display: none" role="search">
  145. <h3 id="searchlabel">Quick search</h3>
  146. <div class="searchformwrapper">
  147. <form class="search" action="../search.html" method="get">
  148. <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
  149. <input type="submit" value="Go" />
  150. </form>
  151. </div>
  152. </div>
  153. <script>document.getElementById('searchbox').style.display = "block"</script>
  154. </div>
  155. </div>
  156. <div class="clearer"></div>
  157. </div>
  158. <div class="footer">
  159. &copy;.
  160. |
  161. Powered by <a href="http://sphinx-doc.org/">Sphinx 5.0.2</a>
  162. &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
  163. </div>
  164. </body>
  165. </html>