From 43fe5cd8be60034b81e386eb0010374784d57516 Mon Sep 17 00:00:00 2001 From: OllisGit <24205767+OllisGit@users.noreply.github.com> Date: Sun, 12 Apr 2020 11:11:22 +0200 Subject: [PATCH 1/5] Update __init__.py Copied the description about errors-argument from Pyh-Doc (https://docs.python.org/3/howto/unicode.html). Im not sure how to create the HTML-Doc out of this file. So, I could not test the doc-output. --- src/octoprint/util/__init__.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index f9e7ffe54..1c601935a 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -41,7 +41,19 @@ logger = logging.getLogger(__name__) def to_bytes(s_or_u, encoding="utf-8", errors="strict"): # type: (Union[unicode, bytes], str, str) -> bytes - """Make sure ``s_or_u`` is a bytestring.""" + """ + Make sure ``s_or_u`` is a bytestring. + + Arguments: + s_or_u (string or unicode): The value to convert + encoding (string): default 'utf-8' + errors (string): The errors argument is the same as the argument of the decode() method but supports a few more possible handlers. + As well as 'strict', 'ignore', and 'replace' (which in this case inserts a question mark instead of the unencodable character), + there is also 'xmlcharrefreplace' (inserts an XML character reference), backslashreplace (inserts a \uNNNN escape sequence) + and namereplace (inserts a \N{...} escape sequence). + Returns: + bytes: converted bytes. + """ if s_or_u is None: return s_or_u @@ -56,7 +68,18 @@ def to_bytes(s_or_u, encoding="utf-8", errors="strict"): def to_unicode(s_or_u, encoding="utf-8", errors="strict"): # type: (Union[unicode, bytes], str, str) -> unicode - """Make sure ``s_or_u`` is a unicode string.""" + """ + Make sure ``s_or_u`` is a unicode string. + + Arguments: + s_or_u (string or unicode): The value to convert + encoding (string): default 'utf-8' + errors (string): The errors argument specifies the response when the input string can’t be converted according to the encoding’s rules. + Legal values for this argument are 'strict' (raise a UnicodeDecodeError exception), 'replace' (use U+FFFD, REPLACEMENT CHARACTER), + 'ignore' (just leave the character out of the Unicode result), or 'backslashreplace' (inserts a \xNN escape sequence). + Returns: + string: converted string. + """ if s_or_u is None: return s_or_u From 2fc094a56359502388ce4efbb414aad78404c44e Mon Sep 17 00:00:00 2001 From: OllisGit <24205767+OllisGit@users.noreply.github.com> Date: Sun, 12 Apr 2020 11:43:06 +0200 Subject: [PATCH 2/5] Changed doc for html-generation --- src/octoprint/util/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 1c601935a..dd7274d6b 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -49,8 +49,8 @@ def to_bytes(s_or_u, encoding="utf-8", errors="strict"): encoding (string): default 'utf-8' errors (string): The errors argument is the same as the argument of the decode() method but supports a few more possible handlers. As well as 'strict', 'ignore', and 'replace' (which in this case inserts a question mark instead of the unencodable character), - there is also 'xmlcharrefreplace' (inserts an XML character reference), backslashreplace (inserts a \uNNNN escape sequence) - and namereplace (inserts a \N{...} escape sequence). + there is also 'xmlcharrefreplace' (inserts an XML character reference), backslashreplace (inserts a \\uNNNN escape sequence) + and namereplace (inserts a \\N{...} escape sequence). Returns: bytes: converted bytes. """ @@ -76,7 +76,7 @@ def to_unicode(s_or_u, encoding="utf-8", errors="strict"): encoding (string): default 'utf-8' errors (string): The errors argument specifies the response when the input string can’t be converted according to the encoding’s rules. Legal values for this argument are 'strict' (raise a UnicodeDecodeError exception), 'replace' (use U+FFFD, REPLACEMENT CHARACTER), - 'ignore' (just leave the character out of the Unicode result), or 'backslashreplace' (inserts a \xNN escape sequence). + 'ignore' (just leave the character out of the Unicode result), or 'backslashreplace' (inserts a \\xNN escape sequence). Returns: string: converted string. """ From e6b747aef5e9570163596899c144863e0246ceb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 14 Apr 2020 13:06:24 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=93=9D=20docs:=20link=20to=20python?= =?UTF-8?q?=20docs=20for=20encoding=20&=20errors=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We don't want to try to duplicate python docs, let's use what already exists and just make it easier to find. --- docs/conf.py | 4 +++- src/octoprint/util/__init__.py | 15 +++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 9de6f2608..0a319229f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -35,8 +35,10 @@ needs_sphinx = '1.3' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = ['codeblockext', 'onlineinclude', 'sphinx.ext.todo', 'sphinx.ext.autodoc', 'sphinxcontrib.httpdomain', - 'sphinx.ext.napoleon', 'sphinxcontrib.mermaid'] + 'sphinx.ext.napoleon', 'sphinxcontrib.mermaid', 'sphinx.ext.intersphinx'] todo_include_todos = True +intersphinx_mapping = {'python': ('https://docs.python.org/3', None), + 'python2': ('https://docs.python.org/2', None)} # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index dd7274d6b..bdb5ab164 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -42,15 +42,12 @@ logger = logging.getLogger(__name__) def to_bytes(s_or_u, encoding="utf-8", errors="strict"): # type: (Union[unicode, bytes], str, str) -> bytes """ - Make sure ``s_or_u`` is a bytestring. + Make sure ``s_or_u`` is a byte string. Arguments: s_or_u (string or unicode): The value to convert - encoding (string): default 'utf-8' - errors (string): The errors argument is the same as the argument of the decode() method but supports a few more possible handlers. - As well as 'strict', 'ignore', and 'replace' (which in this case inserts a question mark instead of the unencodable character), - there is also 'xmlcharrefreplace' (inserts an XML character reference), backslashreplace (inserts a \\uNNNN escape sequence) - and namereplace (inserts a \\N{...} escape sequence). + encoding (string): encoding to use if necessary, see :meth:`python:str.encode` + errors (string): error handling to use if necessary, see :meth:`python:str.encode` Returns: bytes: converted bytes. """ @@ -73,10 +70,8 @@ def to_unicode(s_or_u, encoding="utf-8", errors="strict"): Arguments: s_or_u (string or unicode): The value to convert - encoding (string): default 'utf-8' - errors (string): The errors argument specifies the response when the input string can’t be converted according to the encoding’s rules. - Legal values for this argument are 'strict' (raise a UnicodeDecodeError exception), 'replace' (use U+FFFD, REPLACEMENT CHARACTER), - 'ignore' (just leave the character out of the Unicode result), or 'backslashreplace' (inserts a \\xNN escape sequence). + encoding (string): encoding to use if necessary, see :meth:`python:bytes.decode` + errors (string): error handling to use if necessary, see :meth:`python:bytes.decode` Returns: string: converted string. """ From 31161e7a086daf60fca2ea65baf973d56dfaaeb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 14 Apr 2020 13:15:40 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=93=9D=20docs:=20minor=20fixes=20in?= =?UTF-8?q?=20octoprint.util?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/util/__init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index bdb5ab164..00bd0a03d 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -89,7 +89,10 @@ def to_unicode(s_or_u, encoding="utf-8", errors="strict"): def to_native_str(s_or_u): # type: (Union[unicode, bytes]) -> str - """Make sure ``s_or_u`` is a 'str'.""" + """ + Make sure ``s_or_u`` is a native 'str' for the current Python version + + Will ensure a byte string under Python 2 and a unicode string under Python 3.""" if sys.version_info[0] == 2: return to_bytes(s_or_u) else: @@ -280,7 +283,9 @@ Returns: """ -to_str = deprecated("to_str has been renamed to to_bytes", since="1.3.11")(to_bytes) +to_str = deprecated("to_str has been renamed to to_bytes", + includedoc="to_str has been renamed to to_bytes", + since="1.3.11")(to_bytes) def get_formatted_size(num): From e366bbb5886e0ce4a3056e3c2d962134ff2f3bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 14 Apr 2020 13:25:15 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=93=9D=20docs:=20update=20devenv=20se?= =?UTF-8?q?tup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/development/environment.rst | 40 ++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/docs/development/environment.rst b/docs/development/environment.rst index de1b7e353..b22514d99 100644 --- a/docs/development/environment.rst +++ b/docs/development/environment.rst @@ -19,7 +19,7 @@ below. * Checkout the OctoPrint sources from their Git repository: - * ``git clone -b devel https://github.com/OctoPrint/OctoPrint.git`` + * ``git clone https://github.com/OctoPrint/OctoPrint.git`` * Enter the checked out source folder: ``cd OctoPrint`` * Create virtual environments in the checked out source folder for both Python 2.7 and Python 3.7 to use for @@ -29,6 +29,12 @@ below. * PY2: ``virtualenv --python=python2 venv2`` * PY3: ``virtualenv --python=python3 venv3`` + .. note:: + + This assumes that `python2` and `python3` are binaries available directly on your ``PATH``. If your Python 2 and 3 + binaries cannot be found on your ``PATH`` like this you'll need to specify the full paths to them here, + e.g. ``virtualenv --python=/path/to/python2/bin/python venv2`` + * Activate one of the virtual environments: * PY2: ``source venv2/bin/activate`` (Linux, macOS) or ``source venv2/Scripts/activate`` (Git Bash under Windows, see below) @@ -214,28 +220,42 @@ PyCharm - Add Run/Debug Configuration, select "Python": * Name: OctoPrint server - * Script: path to ``run`` in the OctoPrint checkout folder (e.g. ``~/devel/OctoPrint/run`` or ``C:\Devel\OctoPrint\run``) - * Script parameters: ``serve --debug`` + * Module name: ``octoprint`` + * Module parameters: ``serve --debug`` * Project: ``OctoPrint`` * Python interpreter: the ``venv`` local virtual environment * Working directory: the OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) - * If you want dependencies to auto-update on run if necessary: "Before Launch" > "+" > "Run external tool" > "+" + * If you want build artifacts to be cleaned up on run (recommended): "Before Launch" > "+" > "Run external tool" > "+" - * Name: Update OctoPrint dependencies - * Program: ``$PyInterpreterDirectory$/pip`` (or ``$PyInterpreterDirectory$/pip.exe`` on Windows) - * Parameters: ``install -e .[develop,plugins]`` + * Name: Clean build directory + * Program: ``$ModuleSdkPath$`` + * Parameters: ``setup.py clean`` * Working directory: ``$ProjectFileDir$`` - - Add Run/Debug Configuration, select "Python tests" and therein "Nosetests": + * If you want dependencies to auto-update on run if necessary (recommended): "Before Launch" > "+" > "Run external tool" > "+" - * Name: OctoPrint nosetests - * Target: Path, ``.`` + * Name: Update OctoPrint dependencies + * Program: ``$ModuleSdkPath$`` + * Parameters: ``-m pip install -e .[develop,plugins]`` + * Working directory: ``$ProjectFileDir$`` + + - Add Run/Debug Configuration, select "Python tests" and therein "pytest": + + * Name: OctoPrint pytest + * Target: Custom * Project: ``OctoPrint`` * Python interpreter: the ``venv`` local virtual environment * Working directory: the OctoPrint checkout folder (e.g. ``~/devel/OctoPrint`` or ``C:\Devel\OctoPrint``) * Just like with the run configuration for the server you can also have the dependencies auto-update on run of the tests, see above on how to set this up. + - Add Run/Debug Configuration, select "tox": + + * Name: OctoPrint tox + * Target: Custom + * Project: ``OctoPrint`` + * Python interpreter: the ``venv`` local virtual environment + - Add Run/Debug Configuration, select "Python docs" and therein "Sphinx task" * Name: OctoPrint docs