123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>draugr — Draugr 1.0.1 documentation</title>
- <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
- <link rel="stylesheet" type="text/css" href="../_static/alabaster.css" />
- <link rel="stylesheet" type="text/css" href="../_static/graphviz.css" />
- <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
- <script src="../_static/jquery.js"></script>
- <script src="../_static/underscore.js"></script>
- <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
- <script src="../_static/doctools.js"></script>
- <link rel="canonical" href="pything.github.io/draugr/_modules/draugr.html" />
- <link rel="index" title="Index" href="../genindex.html" />
- <link rel="search" title="Search" href="../search.html" />
-
- <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
-
-
- <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
- </head><body>
-
- <div class="document">
- <div class="documentwrapper">
- <div class="bodywrapper">
-
- <div class="body" role="main">
-
- <h1>Source code for draugr</h1><div class="highlight"><pre>
- <span></span><span class="ch">#!/usr/bin/env python3</span>
- <span class="c1"># -*- coding: utf-8 -*-</span>
- <span class="n">__project__</span> <span class="o">=</span> <span class="s2">"Draugr"</span>
- <span class="n">__author__</span> <span class="o">=</span> <span class="s2">"Christian Heider Nielsen"</span>
- <span class="n">__version__</span> <span class="o">=</span> <span class="s2">"1.0.1"</span>
- <span class="vm">__doc__</span> <span class="o">=</span> <span class="sa">r</span><span class="s2">"""</span>
- <span class="s2">Created on 27/04/2019</span>
- <span class="s2">@author: cnheider</span>
- <span class="s2">"""</span>
- <span class="kn">import</span> <span class="nn">datetime</span>
- <span class="kn">import</span> <span class="nn">os</span>
- <span class="kn">from</span> <span class="nn">logging</span> <span class="kn">import</span> <span class="n">warning</span>
- <span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span>
- <span class="kn">import</span> <span class="nn">pkg_resources</span>
- <span class="kn">from</span> <span class="nn">apppath</span> <span class="kn">import</span> <span class="n">AppPath</span>
- <span class="kn">from</span> <span class="nn">pathlib</span> <span class="kn">import</span> <span class="n">Path</span>
- <span class="c1"># from .drawers import *</span>
- <span class="c1"># from .writers import *</span>
- <span class="c1"># from .opencv_utilities import *</span>
- <span class="c1"># from .torch_utilities import *</span>
- <span class="c1"># from .stopping import *</span>
- <span class="c1"># from .numpy_utilities import *</span>
- <span class="c1"># from .visualisation import *</span>
- <span class="kn">from</span> <span class="nn">.metrics</span> <span class="kn">import</span> <span class="o">*</span>
- <span class="kn">from</span> <span class="nn">.python_utilities</span> <span class="kn">import</span> <span class="o">*</span>
- <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">"README.md"</span><span class="p">,</span> <span class="s2">"r"</span><span class="p">)</span> <span class="k">as</span> <span class="n">this_init_file</span><span class="p">:</span>
- <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>
- <span class="c1"># with open(Path(__file__).parent.parent / "README.md", "r") as this_init_file:</span>
- <span class="c1"># __doc__ += this_init_file.read()</span>
- <span class="c1"># __all__ = ["PROJECT_APP_PATH", "PROJECT_NAME", "PROJECT_VERSION", "get_version"]</span>
- <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">-></span> <span class="nb">bool</span><span class="p">:</span>
- <span class="sd">"""</span>
- <span class="sd"> Return True if given Distribution is an editable installation."""</span>
- <span class="kn">import</span> <span class="nn">sys</span>
- <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>
- <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">"</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"</span>
- <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>
- <span class="k">return</span> <span class="kc">True</span>
- <span class="k">return</span> <span class="kc">False</span></div>
- <span class="n">PROJECT_ORGANISATION</span> <span class="o">=</span> <span class="s2">"pything"</span>
- <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">" "</span><span class="p">,</span> <span class="s2">"_"</span><span class="p">)</span>
- <span class="n">PROJECT_VERSION</span> <span class="o">=</span> <span class="n">__version__</span>
- <span class="n">PROJECT_YEAR</span> <span class="o">=</span> <span class="mi">2018</span>
- <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">" "</span><span class="p">,</span> <span class="s2">"_"</span><span class="p">)</span>
- <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>
- <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">"data"</span><span class="p">))</span>
- <span class="n">INCLUDE_PROJECT_READMES</span> <span class="o">=</span> <span class="kc">False</span>
- <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>
- <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>
- <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>
- <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>
- <span class="k">else</span><span class="p">:</span>
- <span class="n">DEVELOP</span> <span class="o">=</span> <span class="kc">True</span>
- <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">-></span> <span class="nb">str</span><span class="p">:</span>
- <span class="sd">"""description"""</span>
- <span class="n">version</span> <span class="o">=</span> <span class="n">__version__</span>
- <span class="k">if</span> <span class="ow">not</span> <span class="n">version</span><span class="p">:</span>
- <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">"VERSION"</span><span class="p">,</span> <span class="s2">"0.0.0"</span><span class="p">)</span>
- <span class="k">if</span> <span class="n">append_time</span><span class="p">:</span>
- <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>
- <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">"%Y%m</span><span class="si">%d</span><span class="s2">%H%M%S"</span><span class="p">)</span>
- <span class="c1"># date_version = time.time()</span>
- <span class="k">if</span> <span class="n">version</span><span class="p">:</span>
- <span class="c1"># Most git tags are prefixed with 'v' (example: v1.2.3) this is</span>
- <span class="c1"># never desirable for artifact repositories, so we strip the</span>
- <span class="c1"># leading 'v' if it's present.</span>
- <span class="n">version</span> <span class="o">=</span> <span class="p">(</span>
- <span class="n">version</span><span class="p">[</span><span class="mi">1</span><span class="p">:]</span>
- <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">"v"</span><span class="p">)</span>
- <span class="k">else</span> <span class="n">version</span>
- <span class="p">)</span>
- <span class="k">else</span><span class="p">:</span>
- <span class="c1"># Default version is an ISO8601 compliant datetime. PyPI doesn't allow</span>
- <span class="c1"># the colon ':' character in its versions, and time is required to allow</span>
- <span class="c1"># for multiple publications to master in one day. This datetime string</span>
- <span class="c1"># uses the 'basic' ISO8601 format for both its date and time components</span>
- <span class="c1"># to avoid issues with the colon character (ISO requires that date and</span>
- <span class="c1"># time components of a date-time string must be uniformly basic or</span>
- <span class="c1"># extended, which is why the date component does not have dashes.</span>
- <span class="c1">#</span>
- <span class="c1"># Publications using datetime versions should only be made from master</span>
- <span class="c1"># to represent the HEAD moving forward.</span>
- <span class="n">warning</span><span class="p">(</span>
- <span class="sa">f</span><span class="s2">"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">"</span>
- <span class="p">)</span>
- <span class="c1"># warn(f'Environment variable VERSION is not set, only using timestamp: {version}')</span>
- <span class="n">version</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</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">"</span>
- <span class="k">return</span> <span class="n">version</span></div>
- <span class="k">if</span> <span class="n">__version__</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
- <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>
- <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">"."</span><span class="p">))</span>
- </pre></div>
- </div>
-
- </div>
- </div>
- <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
- <div class="sphinxsidebarwrapper">
- <p class="logo"><a href="../index.html">
- <img class="logo" src="../_static/valknut.svg" alt="Logo"/>
- </a></p>
- <h1 class="logo"><a href="../index.html">Draugr</a></h1>
- <h3>Navigation</h3>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../generated/draugr.html">draugr</a></li>
- </ul>
- <p class="caption" role="heading"><span class="caption-text">Notes</span></p>
- <ul>
- <li class="toctree-l1"><a class="reference internal" href="../getting_started.html">Getting Started</a></li>
- </ul>
- <div class="relations">
- <h3>Related Topics</h3>
- <ul>
- <li><a href="../index.html">Documentation overview</a><ul>
- <li><a href="index.html">Module code</a><ul>
- </ul></li>
- </ul></li>
- </ul>
- </div>
- <div id="searchbox" style="display: none" role="search">
- <h3 id="searchlabel">Quick search</h3>
- <div class="searchformwrapper">
- <form class="search" action="../search.html" method="get">
- <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
- <input type="submit" value="Go" />
- </form>
- </div>
- </div>
- <script>document.getElementById('searchbox').style.display = "block"</script>
- </div>
- </div>
- <div class="clearer"></div>
- </div>
- <div class="footer">
- ©.
-
- |
- Powered by <a href="http://sphinx-doc.org/">Sphinx 5.0.2</a>
- & <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
-
- </div>
-
-
- </body>
- </html>
|