8000 πŸš€ releasing version 1.2.0 @ 2020-04-06 11:41 Β· ARMmbed/mbed-tools-lib@de43a16 Β· GitHub
[go: up one dir, main page]

Skip to content 8000
This repository was archived by the owner on Jul 27, 2020. It is now read-only.

Commit de43a16

Browse files
committed
πŸš€ releasing version 1.2.0 @ 2020-04-06 11:41
[skip ci]
1 parent 16de72b commit de43a16

File tree

11 files changed

+302
-11
lines changed

11 files changed

+302
-11
lines changed

β€ŽCHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,36 @@ beta releases are not included in this history. For a full list of all releases,
1212

1313
[//]: # (begin_release_notes)
1414

15+
"1.2.0" (2020-04-06)
16+
====================
17+
"" "1.2.0" (2020-04-06)
18+
=======================
19+
20+
Features
21+
--------
22+
23+
- Added helpers with regards to python features/concepts. (#20200304)
24+
- Add context manager for handling tools errors and generate a user friendly message about increasing verbosity (#20200403)
25+
26+
27+
Bugfixes
28+
--------
29+
30+
- Fixed pre-commit configuration (#20200323)
31+
32+
33+
Improved Documentation
34+
----------------------
35+
36+
- Added licence notice (#20200319)
37+
38+
39+
Misc
40+
----
41+
42+
- #20200402
43+
44+
1545
"1.1.0" (2020-03-18)
1646
====================
1747
"" "1.1.0" (2020-03-18)

β€Ždocs/exceptions.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
-- Copyright (C) 2020 Arm Mbed. All rights reserved.
3+
-- SPDX-License-Identifier: Apache-2.0
4+
-->
15
<!doctype html>
26
<html lang="en">
37
<head>
@@ -25,7 +29,11 @@ <h1 class="title">Module <code>mbed_tools_lib.exceptions</code></h1>
2529
<summary>
2630
<span>Expand source code</span>
2731
</summary>
28-
<pre><code class="python">&#34;&#34;&#34;Exceptions raised by mbed tools.&#34;&#34;&#34;
32+
<pre><code class="python">#
33+
# Copyright (C) 2020 Arm Mbed. All rights reserved.
34+
# SPDX-License-Identifier: Apache-2.0
35+
#
36+
&#34;&#34;&#34;Exceptions raised by mbed tools.&#34;&#34;&#34;
2937

3038

3139
class ToolsError(Exception):

β€Ždocs/index.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
-- Copyright (C) 2020 Arm Mbed. All rights reserved.
3+
-- SPDX-License-Identifier: Apache-2.0
4+
-->
15
<!doctype html>
26
<html lang="en">
37
<head>
@@ -25,7 +29,11 @@ <h1 class="title">Module <code>mbed_tools_lib</code></h1>
2529
<summary>
2630
<span>Expand source code</span>
2731
</summary>
28-
<pre><code class="python">&#34;&#34;&#34;Exposes the primary interfaces for the library.&#34;&#34;&#34;
32+
<pre><code class="python">#
33+
# Copyright (C) 2020 Arm Mbed. All rights reserved.
34+
# SPDX-License-Identifier: Apache-2.0
35+
#
36+
&#34;&#34;&#34;Exposes the primary interfaces for the library.&#34;&#34;&#34;
2937

3038
from mbed_tools_lib._version import __version__</code></pre>
3139
</details>
@@ -41,6 +49,10 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
4149
<dd>
4250
<section class="desc"><p>Helpers for logging errors according to severity of the exception.</p></section>
4351
</dd>
52+
<dt><code class="name"><a title="mbed_tools_lib.python_helpers" href="python_helpers.html">mbed_tools_lib.python_helpers</a></code></dt>
53+
<dd>
54+
<section class="desc"><p>Helpers for python language related functions.</p></section>
55+
</dd>
4456
</dl>
4557
</section>
4658
<section>
@@ -60,6 +72,7 @@ <h1>Index</h1>
6072
<ul>
6173
<li><code><a title="mbed_tools_lib.exceptions" href="exceptions.html">mbed_tools_lib.exceptions</a></code></li>
6274
<li><code><a title="mbed_tools_lib.logging" href="logging.html">mbed_tools_lib.logging</a></code></li>
75+
<li><code><a title="mbed_tools_lib.python_helpers" href="python_helpers.html">mbed_tools_lib.python_helpers</a></code></li>
6376
</ul>
6477
</li>
6578
</ul>

β€Ždocs/logging.html

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
-- Copyright (C) 2020 Arm Mbed. All rights reserved.
3+
-- SPDX-License-Identifier: Apache-2.0
4+
-->
15
<!doctype html>
26
<html lang="en">
37
<head>
@@ -25,11 +29,64 @@ <h1 class="title">Module <code>mbed_tools_lib.logging</code></h1>
2529
<summary>
2630
<span>Expand source code</span>
2731
</summary>
28-
<pre><code class="python">&#34;&#34;&#34;Helpers for logging errors according to severity of the exception.&#34;&#34;&#34;
32+
<pre><code class="python">#
33+
# Copyright (C) 2020 Arm Mbed. All rights reserved.
34+
# SPDX-License-Identifier: Apache-2.0
35+
#
36+
&#34;&#34;&#34;Helpers for logging errors according to severity of the exception.&#34;&#34;&#34;
37+
from typing import Type, Optional, cast
38+
from types import TracebackType
2939
import logging
40+
from mbed_tools_lib.exceptions import ToolsError
3041

3142
LOGGING_FORMAT = &#34;%(levelname)s: %(message)s&#34;
3243

44+
VERBOSITY_HELP = {
45+
logging.CRITICAL: &#34;-v&#34;,
46+
logging.ERROR: &#34;-v&#34;,
47+
logging.WARNING: &#34;-vv&#34;,
48+
logging.INFO: &#34;-vvv&#34;,
49+
logging.DEBUG: &#34;--traceback&#34;,
50+
}
51+
52+
53+
def _exception_message(err: BaseException, log_level: int, traceback: bool) -&gt; str:
54+
&#34;&#34;&#34;Generate a user facing message with help on how to get more information from the logs.&#34;&#34;&#34;
55+
error_msg = str(err)
56+
if log_level != logging.DEBUG or not traceback:
57+
cli_option = VERBOSITY_HELP.get(log_level, &#34;-v&#34;)
58+
error_msg += f&#34;\n\nMore information may be available by using the command line option &#39;{cli_option}&#39;.&#34;
59+
return error_msg
60+
61+
62+
class MbedToolsHandler:
63+
&#34;&#34;&#34;Context Manager to catch Mbed Tools exceptions and generate a helpful user facing message.&#34;&#34;&#34;
64+
65+
def __init__(self, logger: logging.Logger, traceback: bool = False):
66+
&#34;&#34;&#34;Keep track of the logger to use and whether or not a traceback should be generated.&#34;&#34;&#34;
67+
self._logger = logger
68+
self._traceback = traceback
69+
70+
def __enter__(self) -&gt; &#34;MbedToolsHandler&#34;:
71+
&#34;&#34;&#34;Return the Context Manager.&#34;&#34;&#34;
72+
return self
73+
74+
def __exit__(
75+
self,
76+
exc_type: Optional[Type[BaseException]],
77+
exc_value: Optional[BaseException],
78+
exc_traceback: Optional[TracebackType],
79+
) -&gt; bool:
80+
&#34;&#34;&#34;Handle any raised exceptions, suppressing Tools errors and generating an error message instead.&#34;&#34;&#34;
81+
if exc_type and issubclass(exc_type, ToolsError):
82+
error_msg = _exception_message(cast(BaseException, exc_value), logging.root.level, self._traceback)
83+
self._logger.error(error_msg, exc_info=self._traceback)
84+
# Do not propagate exceptions derived from ToolsError
85+
return True
86+
87+
# Propagate all other exceptions
88+
return False
89+
3390

3491
def log_exception(logger: logging.Logger, exception: Exception, show_traceback: bool = False) -&gt; None:
3592
&#34;&#34;&#34;Logs an exception in both normal and verbose forms.
@@ -129,6 +186,49 @@ <h2 id="args">Args</h2>
129186
</dl>
130187
</section>
131188
<section>
189+
<h2 class="section-title" id="header-classes">Classes</h2>
190+
<dl>
191+
<dt id="mbed_tools_lib.logging.MbedToolsHandler"><code class="flex name class">
192+
<span>class <span class="ident">MbedToolsHandler</span></span>
193+
<span>(</span><span>logger:Β logging.Logger, traceback:Β boolΒ =Β False)</span>
194+
</code></dt>
195+
<dd>
196+
<section class="desc"><p>Context Manager to catch Mbed Tools exceptions and generate a helpful user facing message.</p>
197+
<p>Keep track of the logger to use and whether or not a traceback should be generated.</p></section>
198+
<details class="source">
199+
<summary>
200+
<span>Expand source code</span>
201+
</summary>
202+
<pre><code class="python">class MbedToolsHandler:
203+
&#34;&#34;&#34;Context Manager to catch Mbed Tools exceptions and generate a helpful user facing message.&#34;&#34;&#34;
204+
205+
def __init__(self, logger: logging.Logger, traceback: bool = False):
206+
&#34;&#34;&#34;Keep track of the logger to use and whether or not a traceback should be generated.&#34;&#34;&#34;
207+
self._logger = logger
208+
self._traceback = traceback
209+
210+
def __enter__(self) -&gt; &#34;MbedToolsHandler&#34;:
211+
&#34;&#34;&#34;Return the Context Manager.&#34;&#34;&#34;
212+
return self
213+
214+
def __exit__(
215+
self,
216+
exc_type: Optional[Type[BaseException]],
217+
exc_value: Optional[BaseException],
218+
exc_traceback: Optional[TracebackType],
219+
) -&gt; bool:
220+
&#34;&#34;&#34;Handle any raised exceptions, suppressing Tools errors and generating an error message instead.&#34;&#34;&#34;
221+
if exc_type and issubclass(exc_type, ToolsError):
222+
error_msg = _exception_message(cast(BaseException, exc_value), logging.root.level, self._traceback)
223+
self._logger.error(error_msg, exc_info=self._traceback)
224+
# Do not propagate exceptions derived from ToolsError
225+
return True
226+
227+
# Propagate all other exceptions
228+
return False</code></pre>
229+
</details>
230+
</dd>
231+
</dl>
132232
</section>
133233
</article>
134234
<nav id="sidebar">
@@ -148,6 +248,13 @@ <h1>Index</h1>
148248
<li><code><a title="mbed_tools_lib.logging.set_log_level" href="#mbed_tools_lib.logging.set_log_level">set_log_level</a></code></li>
149249
</ul>
150250
</li>
251+
<li><h3><a href="#header-classes">Classes</a></h3>
252+
<ul>
253+
<li>
254+
<h4><code><a title="mbed_tools_lib.logging.MbedToolsHandler" href="#mbed_tools_lib.logging.MbedToolsHandler">MbedToolsHandler</a></code></h4>
255+
</li>
256+
</ul>
257+
</li>
151258
</ul>
152259
</nav>
153260
</main>

β€Ždocs/python_helpers.html

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<!--
2+
-- Copyright (C) 2020 Arm Mbed. All rights reserved.
3+
-- SPDX-License-Identifier: Apache-2.0
4+
-->
5+
<!doctype html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8">
9+
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
10+
<meta name="generator" content="pdoc 0.7.5" />
11+
<title>mbed_tools_lib.python_helpers API documentation</title>
12+
<meta name="description" content="Helpers for python language related functions." />
13+
<link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'>
14+
<link href='https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/8.0.0/sanitize.min.css' rel='stylesheet'>
15+
<link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/github.min.css" rel="stylesheet">
16+
<style>.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{font-weight:bold}#index h4 + ul{margin-bottom:.6em}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
17+
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
18+
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
19+
</head>
20+
<body>
21+
<main>
22+
<article id="content">
23+
<header>
24+
<h1 class="title">Module <code>mbed_tools_lib.python_helpers</code></h1>
25+
</header>
26+
<section id="section-intro">
27+
<p>Helpers for python language related functions.</p>
28+
<details class="source">
29+
<summary>
30+
<span>Expand source code</span>
31+
</summary>
32+
<pre><code class="python">#
33+
# Copyright (C) 2020 Arm Mbed. All rights reserved.
34+
# SPDX-License-Identifier: Apache-2.0
35+
#
36+
&#34;&#34;&#34;Helpers for python language related functions.&#34;&#34;&#34;
37+
import sys
38+
from collections import namedtuple
39+
from typing import NamedTuple, Iterable, Any, cast
40+
41+
42+
def minimum_python_version(major: int, minor: int) -&gt; bool:
43+
&#34;&#34;&#34;States whether the python in use is more recent than set major,minor versions.&#34;&#34;&#34;
44+
return sys.version_info.major &gt;= major and sys.version_info.minor &gt;= minor
45+
46+
47+
def named_tuple_with_defaults(typename: str, field_names: Iterable[str], defaults: Iterable[Any]) -&gt; NamedTuple:
48+
&#34;&#34;&#34;Gets a named tuple set with default values.
49+
50+
defaults field only appeared in Python 3.7.
51+
See https://stackoverflow.com/questions/11351032/namedtuple-and-default-values-for-optional-keyword-arguments
52+
&#34;&#34;&#34;
53+
if minimum_python_version(3, 7):
54+
return namedtuple(typename=typename, field_names=field_names, defaults=defaults) # type: ignore
55+
else:
56+
a_tuple: NamedTuple = namedtuple(typename=typename, field_names=field_names) # type: ignore
57+
a_tuple.__new__.__defaults__ = tuple(defaults) # type: ignore
58+
return cast(NamedTuple, a_tuple)</code></pre>
59+
</details>
60+
</section>
61+
<section>
62+
</section>
63+
<section>
64+
</section>
65+
<section>
66+
<h2 class="section-title" id="header-functions">Functions</h2>
67+
<dl>
68+
<dt id="mbed_tools_lib.python_helpers.minimum_python_version"><code class="name flex">
69+
<span>def <span class="ident">minimum_python_version</span></span>(<span>major:Β int, minor:Β int) ->Β bool</span>
70+
</code></dt>
71+
<dd>
72+
<section class="desc"><p>States whether the python in use is more recent than set major,minor versions.</p></section>
73+
<details class="source">
74+
<summary>
75+
<span>Expand source code</span>
76+
</summary>
77+
<pre><code class="python">def minimum_python_version(major: int, minor: int) -&gt; bool:
78+
&#34;&#34;&#34;States whether the python in use is more recent than set major,minor versions.&#34;&#34;&#34;
79+
return sys.version_info.major &gt;= major and sys.version_info.minor &gt;= minor</code></pre>
80+
</details>
81+
</dd>
82+
<dt id="mbed_tools_lib.python_helpers.named_tuple_with_defaults"><code class="name flex">
83+
<span>def <span class="ident">named_tuple_with_defaults</span></span>(<span>typename:Β str, field_names:Β Iterable[str], defaults:Β Iterable[Any]) ->Β <classΒ 'NamedTuple'></span>
84+
</code></dt>
85+
<dd>
86+
<section class="desc"><p>Gets a named tuple set with default values.</p>
87+
<p>defaults field only appeared in Python 3.7.
88+
See <a href="https://stackoverflow.com/questions/11351032/namedtuple-and-default-values-for-optional-keyword-arguments">https://stackoverflow.com/questions/11351032/namedtuple-and-default-values-for-optional-keyword-arguments</a></p></section>
89+
<details class="source">
90+
<summary>
91+
<span>Expand source code</span>
92+
</summary>
93+
<pre><code class="python">def named_tuple_with_defaults(typename: str, field_names: Iterable[str], defaults: Iterable[Any]) -&gt; NamedTuple:
94+
&#34;&#34;&#34;Gets a named tuple set with default values.
95+
96+
defaults field only appeared in Python 3.7.
97+
See https://stackoverflow.com/questions/11351032/namedtuple-and-default-values-for-optional-keyword-arguments
98+
&#34;&#34;&#34;
99+
if minimum_python_version(3, 7):
100+
return namedtuple(typename=typename, field_names=field_names, defaults=defaults) # type: ignore
101+
else:
102+
a_tuple: NamedTuple = namedtuple(typename=typename, field_names=field_names) # type: ignore
103+
a_tuple.__new__.__defaults__ = tuple(defaults) # type: ignore
104+
return cast(NamedTuple, a_tuple)</code></pre>
105+
</details>
106+
</dd>
107+
</dl>
108+
</section>
109+
<section>
110+
</section>
111+
</article>
112+
<nav id="sidebar">
113+
<h1>Index</h1>
114+
<div class="toc">
115+
<ul></ul>
116+
</div>
117+
<ul id="index">
118+
<li><h3>Super-module</h3>
119+
<ul>
120+
<li><code><a title="mbed_tools_lib" href="index.html">mbed_tools_lib</a></code></li>
121+
</ul>
122+
</li>
123+
<li><h3><a href="#header-functions">Functions</a></h3>
124+
<ul class="">
125+
<li><code><a title="mbed_tools_lib.python_helpers.minimum_python_version" href="#mbed_tools_lib.python_helpers.minimum_python_version">minimum_python_version</a></code></li>
126+
<li><code><a title="mbed_tools_lib.python_helpers.named_tuple_with_defaults" href="#mbed_tools_lib.python_helpers.named_tuple_with_defaults">named_tuple_with_defaults</a></code></li>
127+
</ul>
128+
</li>
129+
</ul>
130+
</nav>
131+
</main>
132+
<footer id="footer">
133+
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.5</a>.</p>
134+
</footer>
135+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
136+
<script>hljs.initHighlightingOnLoad()</script>
137+
</body>
138+
</html>

β€Žmbed_tools_lib/_version.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
1111
This file is autogenerated, do not modify by hand.
1212
"""
13-
__version__ = "1.1.0"
14-
COMMIT = "11b11ff24d682a4584da52d6f4b17bfc8061d8d9"
13+
__version__ = "1.2.0"
14+
COMMIT = "16de72b2317cc55d83a961134ae1aefcbb8e79a0"
1515
MAJOR = 1
16-
MINOR = 1
16+
MINOR = 2
1717
PATCH = 0

β€Žnews/20200304.feature

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Žnews/20200319.doc

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Žnews/20200323.bugfix

Lines changed: 0 additions & 1 deletion
This file was deleted.

β€Žnews/20200402.misc

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
Β (0)
0