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/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 diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index f9e7ffe54..00bd0a03d 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -41,7 +41,16 @@ 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): 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. + """ if s_or_u is None: return s_or_u @@ -56,7 +65,16 @@ 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): 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. + """ if s_or_u is None: return s_or_u @@ -71,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: @@ -262,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):