From 604a3bca50b326fb06f8d7a61d9df88e3ad915ff Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Mon, 25 Apr 2022 10:11:59 +0900 Subject: [PATCH 01/13] Init sphinx --- .gitignore | 2 ++ docs/Makefile | 20 +++++++++++ docs/make.bat | 35 +++++++++++++++++++ docs/source/conf.py | 51 ++++++++++++++++++++++++++++ docs/source/index.rst | 21 ++++++++++++ docs/source/reference/ext/black.rst | 7 ++++ docs/source/reference/ext/flake8.rst | 6 ++++ docs/source/reference/ext/isort.rst | 6 ++++ docs/source/reference/ext/mypy.rst | 6 ++++ docs/source/reference/setting.rst | 11 ++++++ 10 files changed, 165 insertions(+) create mode 100644 docs/Makefile create mode 100644 docs/make.bat create mode 100644 docs/source/conf.py create mode 100644 docs/source/index.rst create mode 100644 docs/source/reference/ext/black.rst create mode 100644 docs/source/reference/ext/flake8.rst create mode 100644 docs/source/reference/ext/isort.rst create mode 100644 docs/source/reference/ext/mypy.rst create mode 100644 docs/source/reference/setting.rst diff --git a/.gitignore b/.gitignore index 42db774..9225177 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ pip-wheel-metadata # editors .vscode + +docs/_build diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..92dd33a --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line, and also +# from the environment for the first two. +SPHINXOPTS ?= +SPHINXBUILD ?= sphinx-build +SOURCEDIR = source +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/make.bat b/docs/make.bat new file mode 100644 index 0000000..32bb245 --- /dev/null +++ b/docs/make.bat @@ -0,0 +1,35 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://www.sphinx-doc.org/ + exit /b 1 +) + +if "%1" == "" goto help + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% + +:end +popd diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..c7ed079 --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,51 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- Project information ----------------------------------------------------- + +project = 'pysen' +copyright = '2022, Preferred Networks, inc.' +author = 'Preferred Networks, inc.' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = ['sphinx.ext.autodoc'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'venv'] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..1d2b20d --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,21 @@ +.. pysen documentation master file, created by + sphinx-quickstart on Mon Apr 25 09:37:35 2022. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to pysen's documentation! +================================= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + reference/setting + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/docs/source/reference/ext/black.rst b/docs/source/reference/ext/black.rst new file mode 100644 index 0000000..4fab17e --- /dev/null +++ b/docs/source/reference/ext/black.rst @@ -0,0 +1,7 @@ +.. module:: pysen.ext.black_wrapper + +black +===== + + +.. autoclass:: BlackSetting diff --git a/docs/source/reference/ext/flake8.rst b/docs/source/reference/ext/flake8.rst new file mode 100644 index 0000000..3c07469 --- /dev/null +++ b/docs/source/reference/ext/flake8.rst @@ -0,0 +1,6 @@ +.. module:: pysen.ext.flake8_wrapper + +flake8 +====== + +.. autoclass:: Flake8Setting diff --git a/docs/source/reference/ext/isort.rst b/docs/source/reference/ext/isort.rst new file mode 100644 index 0000000..0ff22ae --- /dev/null +++ b/docs/source/reference/ext/isort.rst @@ -0,0 +1,6 @@ +.. module:: pysen.ext.isort_wrapper + +isort +===== + +.. autoclass:: IsortSetting diff --git a/docs/source/reference/ext/mypy.rst b/docs/source/reference/ext/mypy.rst new file mode 100644 index 0000000..c03d2c4 --- /dev/null +++ b/docs/source/reference/ext/mypy.rst @@ -0,0 +1,6 @@ +.. module:: pysen.ext.mypy_wrapper + +mypy +==== + +.. autoclass:: MypySetting diff --git a/docs/source/reference/setting.rst b/docs/source/reference/setting.rst new file mode 100644 index 0000000..65b81bc --- /dev/null +++ b/docs/source/reference/setting.rst @@ -0,0 +1,11 @@ +Settings +======== + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + ext/black + ext/flake8 + ext/isort + ext/mypy From b492545f7a86aa844f171a533e3037c9617e8b0e Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Thu, 28 Apr 2022 14:15:01 +0900 Subject: [PATCH 02/13] Added sources --- docs/requirements.txt | 2 ++ docs/source/conf.py | 12 ++++++-- docs/source/index.rst | 34 +++++++++++++++++++++-- docs/source/reference/ext/index.rst | 11 ++++++++ docs/source/reference/ext/isort.rst | 2 ++ docs/source/reference/ext/mypy.rst | 4 +++ docs/source/reference/factory.rst | 6 ++++ docs/source/reference/mypy.rst | 6 ++++ docs/source/reference/py_version.rst | 6 ++++ docs/source/reference/pyproject_model.rst | 15 ++++++++++ docs/source/reference/setting.rst | 11 -------- docs/source/reference/source.rst | 6 ++++ 12 files changed, 100 insertions(+), 15 deletions(-) create mode 100644 docs/requirements.txt create mode 100644 docs/source/reference/ext/index.rst create mode 100644 docs/source/reference/factory.rst create mode 100644 docs/source/reference/mypy.rst create mode 100644 docs/source/reference/py_version.rst create mode 100644 docs/source/reference/pyproject_model.rst delete mode 100644 docs/source/reference/setting.rst create mode 100644 docs/source/reference/source.rst diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..dfab548 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,2 @@ +sphinx +pydata-sphinx-theme diff --git a/docs/source/conf.py b/docs/source/conf.py index c7ed079..7bbc50b 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -27,7 +27,11 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. -extensions = ['sphinx.ext.autodoc'] +extensions = [ + 'sphinx.ext.napoleon', + 'sphinx.ext.autodoc', + 'sphinx_autodoc_typehints', +] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] @@ -43,9 +47,13 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = 'pydata_sphinx_theme' # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] + + +# sphinx.ext.autodoc +autodoc_typehints = "description" diff --git a/docs/source/index.rst b/docs/source/index.rst index 1d2b20d..62a6b33 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -6,11 +6,41 @@ Welcome to pysen's documentation! ================================= +.. code-block:: toml + + [tool.pysen] + version = "0.10" + + [tool.pysen.lint] + enable_black = true + enable_flake8 = true + enable_isort = true + enable_mypy = true + mypy_preset = "strict" + line_length = 88 + py_version = "py37" + + [[tool.pysen.lint.mypy_targets]] + paths = ["."] + + +- For ``[tool.pysen]``, you can specify entries available in :class:`~pysen.pyproject_model.Config` +- For ``[tool.pysen.lint]``, :class:`~pysen.pyproject_model.LintConfig` +- You can instead specify ``[[tool.pysen.lint.{entry_name}]]``. + + +reference +========= + .. toctree:: :maxdepth: 2 - :caption: Contents: - reference/setting + reference/ext/index + reference/factory + reference/mypy + reference/py_version + reference/pyproject_model + reference/source Indices and tables diff --git a/docs/source/reference/ext/index.rst b/docs/source/reference/ext/index.rst new file mode 100644 index 0000000..a0d2e0b --- /dev/null +++ b/docs/source/reference/ext/index.rst @@ -0,0 +1,11 @@ +pysen.ext +========= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + black + flake8 + isort + mypy diff --git a/docs/source/reference/ext/isort.rst b/docs/source/reference/ext/isort.rst index 0ff22ae..1933286 100644 --- a/docs/source/reference/ext/isort.rst +++ b/docs/source/reference/ext/isort.rst @@ -4,3 +4,5 @@ isort ===== .. autoclass:: IsortSetting + +.. autoclass:: IsortSectionName diff --git a/docs/source/reference/ext/mypy.rst b/docs/source/reference/ext/mypy.rst index c03d2c4..cbcf4c8 100644 --- a/docs/source/reference/ext/mypy.rst +++ b/docs/source/reference/ext/mypy.rst @@ -4,3 +4,7 @@ mypy ==== .. autoclass:: MypySetting + +.. autoclass:: MypyPlugin + +.. autoclass:: MypyTarget diff --git a/docs/source/reference/factory.rst b/docs/source/reference/factory.rst new file mode 100644 index 0000000..ee3a3f7 --- /dev/null +++ b/docs/source/reference/factory.rst @@ -0,0 +1,6 @@ +.. module:: pysen.factory + +pysen.factory +============= + +.. autoclass:: MypyModuleOption diff --git a/docs/source/reference/mypy.rst b/docs/source/reference/mypy.rst new file mode 100644 index 0000000..fa3c0d6 --- /dev/null +++ b/docs/source/reference/mypy.rst @@ -0,0 +1,6 @@ +.. module:: pysen.mypy + +pysen.mypy +========== + +.. autoclass:: MypyPreset diff --git a/docs/source/reference/py_version.rst b/docs/source/reference/py_version.rst new file mode 100644 index 0000000..0af52e2 --- /dev/null +++ b/docs/source/reference/py_version.rst @@ -0,0 +1,6 @@ +.. module:: pysen.py_version + +pysen.py_version +================ + +.. autoclass:: VersionRepresentation diff --git a/docs/source/reference/pyproject_model.rst b/docs/source/reference/pyproject_model.rst new file mode 100644 index 0000000..2159e47 --- /dev/null +++ b/docs/source/reference/pyproject_model.rst @@ -0,0 +1,15 @@ +.. module:: pysen.pyproject_model + +pysen.pyproject_model +===================== + + +.. autoclass:: pysen.pyproject_model.Config + +:class:`~pysen.pyproject_model.LintConfig` + +.. autoclass:: pysen.pyproject_model.LintConfig + +:class:`~pysen.pyproject_model.PluginConfig` + +.. autoclass:: pysen.pyproject_model.PluginConfig diff --git a/docs/source/reference/setting.rst b/docs/source/reference/setting.rst deleted file mode 100644 index 65b81bc..0000000 --- a/docs/source/reference/setting.rst +++ /dev/null @@ -1,11 +0,0 @@ -Settings -======== - -.. toctree:: - :maxdepth: 2 - :caption: Contents: - - ext/black - ext/flake8 - ext/isort - ext/mypy diff --git a/docs/source/reference/source.rst b/docs/source/reference/source.rst new file mode 100644 index 0000000..1faebb7 --- /dev/null +++ b/docs/source/reference/source.rst @@ -0,0 +1,6 @@ +.. module:: pysen.source + +pysen.source +============ + +.. autoclass:: Source From 74f5a669c72182e9968424933464e9ebe2f39582 Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Thu, 28 Apr 2022 14:17:09 +0900 Subject: [PATCH 03/13] Add sphinx_autodoc_typehints --- docs/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/requirements.txt b/docs/requirements.txt index dfab548..4d20d14 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,3 @@ sphinx +sphinx_autodoc_typehints pydata-sphinx-theme From cf292a520daaa0f16db37eaa111d844ef08e5c2b Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Thu, 28 Apr 2022 15:22:09 +0900 Subject: [PATCH 04/13] Update how to configure --- docs/source/index.rst | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 62a6b33..3bc9c50 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -10,6 +10,7 @@ Welcome to pysen's documentation! [tool.pysen] version = "0.10" + builder = "lint.py" [tool.pysen.lint] enable_black = true @@ -24,9 +25,23 @@ Welcome to pysen's documentation! paths = ["."] -- For ``[tool.pysen]``, you can specify entries available in :class:`~pysen.pyproject_model.Config` -- For ``[tool.pysen.lint]``, :class:`~pysen.pyproject_model.LintConfig` -- You can instead specify ``[[tool.pysen.lint.{entry_name}]]``. +- ``tool.pysen`` corresponds to :class:`pysen.pyproject_model.Config` + - For example, ``builder`` under ``[tool.pysen]`` passes to :class:`pysen.pyproject_model.Config` + +- ``tool.pysen.lint`` corresponds to :class:`pysen.pyproject_model.LintConfig` + - If you specify ``line_length`` to ``88``, it is passed to :class:`pysen.pyproject_model.LintConfig` + +- ``tool.pysen.plugin`` corresponds to :class:`pysen.pyproject_model.PluginConfig` + +You can know what you can change a configuration by checking :class:`~pysen.pyproject_model.Config`, +:class:`~pysen.pyproject_model.LintConfig`, and :class:`~pysen.pyproject_model.PluginConfig`. + +If a entry is not an instance of Python built-in class, it cannot be directly specified. +For example, ``mypy_targets`` corresponds to :class:`pysen.ext.mypy_wrapper.MypyTarget`, which is not a Python built-in (or equivarent to built-in) class. +To configure such option, you need to create a section ``[[tool.pysen.lint.mypy_targets]]``. +:class:`~pysen.ext.mypy_wrapper.MypyPlugin` has parameters ``paths`` and ``namespace_packages``. +Since ``paths`` is equivarent to ``str`` and ``namespace_packages`` is ``bool``, you can set them in the section. +Note that ``namespace_packages`` is omitted since it is :obj:`False` by default. reference From 1db6d7fa6ad856c7d2538c70a3ee54a7ab4de533 Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Thu, 28 Apr 2022 15:23:25 +0900 Subject: [PATCH 05/13] Fix wording --- docs/source/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 3bc9c50..1b5be47 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -3,8 +3,8 @@ You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -Welcome to pysen's documentation! -================================= +How to configure pysen +====================== .. code-block:: toml From 6c7eb60c2db0531d630361e8cca34d5ac9aa1447 Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Thu, 28 Apr 2022 15:24:10 +0900 Subject: [PATCH 06/13] Change maxdepth of toctree --- docs/source/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 1b5be47..49cd8aa 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -48,7 +48,7 @@ reference ========= .. toctree:: - :maxdepth: 2 + :maxdepth: 1 reference/ext/index reference/factory From af23737541ed7c674a0fd20b7a2568aa03227ddd Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Fri, 6 May 2022 17:09:47 +0900 Subject: [PATCH 07/13] Update docs --- docs/source/index.rst | 45 ++++---------------- docs/source/overview.rst | 61 ++++++++++++++++++++++++++++ docs/source/reference/ext/isort.rst | 2 + docs/source/reference/py_version.rst | 2 + 4 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 docs/source/overview.rst diff --git a/docs/source/index.rst b/docs/source/index.rst index 49cd8aa..a0a35a5 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -3,49 +3,18 @@ You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -How to configure pysen -====================== -.. code-block:: toml - - [tool.pysen] - version = "0.10" - builder = "lint.py" - - [tool.pysen.lint] - enable_black = true - enable_flake8 = true - enable_isort = true - enable_mypy = true - mypy_preset = "strict" - line_length = 88 - py_version = "py37" - - [[tool.pysen.lint.mypy_targets]] - paths = ["."] - - -- ``tool.pysen`` corresponds to :class:`pysen.pyproject_model.Config` - - For example, ``builder`` under ``[tool.pysen]`` passes to :class:`pysen.pyproject_model.Config` - -- ``tool.pysen.lint`` corresponds to :class:`pysen.pyproject_model.LintConfig` - - If you specify ``line_length`` to ``88``, it is passed to :class:`pysen.pyproject_model.LintConfig` - -- ``tool.pysen.plugin`` corresponds to :class:`pysen.pyproject_model.PluginConfig` +Tutorials +========= -You can know what you can change a configuration by checking :class:`~pysen.pyproject_model.Config`, -:class:`~pysen.pyproject_model.LintConfig`, and :class:`~pysen.pyproject_model.PluginConfig`. +.. toctree:: + :maxdepth: 1 -If a entry is not an instance of Python built-in class, it cannot be directly specified. -For example, ``mypy_targets`` corresponds to :class:`pysen.ext.mypy_wrapper.MypyTarget`, which is not a Python built-in (or equivarent to built-in) class. -To configure such option, you need to create a section ``[[tool.pysen.lint.mypy_targets]]``. -:class:`~pysen.ext.mypy_wrapper.MypyPlugin` has parameters ``paths`` and ``namespace_packages``. -Since ``paths`` is equivarent to ``str`` and ``namespace_packages`` is ``bool``, you can set them in the section. -Note that ``namespace_packages`` is omitted since it is :obj:`False` by default. + overview -reference -========= +API Reference +============= .. toctree:: :maxdepth: 1 diff --git a/docs/source/overview.rst b/docs/source/overview.rst new file mode 100644 index 0000000..87e5174 --- /dev/null +++ b/docs/source/overview.rst @@ -0,0 +1,61 @@ +.. _Overview: + +How to configure pysen +====================== + +Overview +-------- + +.. code-block:: toml + + [tool.pysen] + version = "0.10" + builder = "lint.py" + + [tool.pysen.lint] + enable_black = true + enable_flake8 = true + enable_isort = true + enable_mypy = true + mypy_preset = "strict" + line_length = 88 + py_version = "py37" + + [[tool.pysen.lint.mypy_targets]] + paths = ["."] + + +- ``tool.pysen`` corresponds to :class:`pysen.pyproject_model.Config` + - For example, ``builder`` under ``[tool.pysen]`` passes to :class:`pysen.pyproject_model.Config` + +- ``tool.pysen.lint`` corresponds to :class:`pysen.pyproject_model.LintConfig` + - If you specify ``line_length`` to ``88``, it is passed to :class:`pysen.pyproject_model.LintConfig` + +- ``tool.pysen.plugin``, corresponds to :class:`pysen.pyproject_model.PluginConfig` + +You can know what you can change a configuration by checking :class:`~pysen.pyproject_model.Config`, +:class:`~pysen.pyproject_model.LintConfig`, and :class:`~pysen.pyproject_model.PluginConfig`. + +If a entry is not an instance of Python built-in class, it cannot be directly specified. +For example, ``mypy_targets`` corresponds to :class:`pysen.ext.mypy_wrapper.MypyTarget`, which is not a Python built-in (or equivarent to built-in) class. +To configure such option, you need to create a section ``[[tool.pysen.lint.mypy_targets]]``. +:class:`~pysen.ext.mypy_wrapper.MypyPlugin` has parameters ``paths`` and ``namespace_packages``. +Since ``paths`` is equivarent to ``str`` and ``namespace_packages`` is ``bool``, you can set them in the section. +Note that ``namespace_packages`` is omitted since it is :obj:`False` by default. + + +Exception +^^^^^^^^^ + +``version`` in ``[tool.pysen]`` and ``py_version`` in ``[tool.pysen.lint]`` are single strings +although they are :class:`~pysen.py_version.VersionRepresentation` and +:class:`~pysen.py_version.PythonVersion`, which have ``major``, ``minor``, +``patch``, and ``pre_release`` as their attributes. + +:class:`~pysen.py_version.VersionRepresentation` + +Specify a pysen version (e.g. ``0.10.2``). + +:class:`~pysen.py_version.PythonVersion` + +Specify one of ``py27``, ``py36``, ``py37``, ``py38``, ``py39``, or ``py310``. diff --git a/docs/source/reference/ext/isort.rst b/docs/source/reference/ext/isort.rst index 1933286..11935dc 100644 --- a/docs/source/reference/ext/isort.rst +++ b/docs/source/reference/ext/isort.rst @@ -6,3 +6,5 @@ isort .. autoclass:: IsortSetting .. autoclass:: IsortSectionName + :members: + :undoc-members: diff --git a/docs/source/reference/py_version.rst b/docs/source/reference/py_version.rst index 0af52e2..af01696 100644 --- a/docs/source/reference/py_version.rst +++ b/docs/source/reference/py_version.rst @@ -4,3 +4,5 @@ pysen.py_version ================ .. autoclass:: VersionRepresentation + +.. autoclass:: PythonVersion From 2c304ddca9f4e4875be298a829590e55d71881ff Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Fri, 6 May 2022 17:10:05 +0900 Subject: [PATCH 08/13] Add CI --- .github/workflows/sphinx.yml | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/sphinx.yml diff --git a/.github/workflows/sphinx.yml b/.github/workflows/sphinx.yml new file mode 100644 index 0000000..6cea105 --- /dev/null +++ b/.github/workflows/sphinx.yml @@ -0,0 +1,55 @@ +name: GitHub Pages + +on: + push: + branches: + - main + pull_request: + +jobs: + deploy: + runs-on: ubuntu-20.04 + concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + steps: + - uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v3 + with: + python-version: '3.8' + + - name: Upgrade pip + run: | + # install pip=>20.1 to use "pip cache dir" + python3 -m pip install --upgrade pip + python3 -m pip install . + + - name: Get pip cache dir + id: pip-cache + run: echo "::set-output name=dir::$(pip cache dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: python3 -m pip install -r ./docs/requirements.txt + + - run: touch .nojekyll + + - run: | + cd docs + touch _gh-pages/.nojekyll + make html + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + if: ${{ github.ref == 'refs/heads/main' }} + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/_build/html From d00e7f44ea6d4cf3c516b6572ce4cb1ef28a8a37 Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Fri, 6 May 2022 17:13:24 +0900 Subject: [PATCH 09/13] Fix workflow --- .github/workflows/sphinx.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sphinx.yml b/.github/workflows/sphinx.yml index 6cea105..5fe73e9 100644 --- a/.github/workflows/sphinx.yml +++ b/.github/workflows/sphinx.yml @@ -43,9 +43,8 @@ jobs: - run: touch .nojekyll - run: | - cd docs - touch _gh-pages/.nojekyll - make html + touch ./docs/.nojekyll + cd docs && make html - name: Deploy uses: peaceiris/actions-gh-pages@v3 From ccd0996fb3fd30761993bddf9fac8ac72c2289a9 Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Sun, 15 May 2022 19:04:31 +0900 Subject: [PATCH 10/13] Make version and py_version str --- pysen/factory.py | 18 +++++++++++++++--- pysen/pyproject_model.py | 2 +- tests/test_pyproject_model.py | 8 ++++---- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/pysen/factory.py b/pysen/factory.py index f8de1e5..795f82b 100644 --- a/pysen/factory.py +++ b/pysen/factory.py @@ -1,6 +1,6 @@ import dataclasses import pathlib -from typing import Dict, List, Optional +from typing import Any, Dict, List, Optional from .black import Black, BlackSetting from .component import ComponentBase @@ -17,6 +17,18 @@ from .py_version import PythonVersion from .source import Source +import dacite + + +def _parse_python_version(s: Any) -> PythonVersion: + if not isinstance(s, str): + raise dacite.WrongTypeError(str, s) + + try: + return PythonVersion.parse_short_representation(s) + except KeyError as e: + raise dacite.DaciteError(str(e)) + @dataclasses.dataclass class MypyModuleOption: @@ -51,7 +63,7 @@ class ConfigureLintOptions: mypy_modules: Optional[Dict[str, MypyModuleOption]] = None source: Optional[Source] = None line_length: Optional[int] = None - py_version: Optional[PythonVersion] = None + py_version: Optional[str] = None isort_known_third_party: Optional[List[str]] = None isort_known_first_party: Optional[List[str]] = None isort_default_section: Optional[IsortSectionName] = None @@ -65,7 +77,7 @@ def configure_lint(options: ConfigureLintOptions) -> List[ComponentBase]: python_version: PythonVersion if options.py_version is not None: - python_version = options.py_version + python_version = _parse_python_version(options.py_version) else: python_version = PythonVersion(3, 7) diff --git a/pysen/pyproject_model.py b/pysen/pyproject_model.py index 0772480..09f2607 100644 --- a/pysen/pyproject_model.py +++ b/pysen/pyproject_model.py @@ -53,7 +53,7 @@ class PluginConfig: @dataclasses.dataclass class Config: - version: Optional[VersionRepresentation] = None + version: Optional[str] = None lint: Optional[LintConfig] = None builder: Optional[pathlib.Path] = None plugin: Optional[List[PluginConfig]] = None diff --git a/tests/test_pyproject_model.py b/tests/test_pyproject_model.py index f080652..0e7a7d5 100644 --- a/tests/test_pyproject_model.py +++ b/tests/test_pyproject_model.py @@ -291,7 +291,7 @@ def test_example() -> None: assert lint.enable_mypy assert lint.line_length == 88 assert isinstance(lint.line_length, int) - assert lint.py_version == PythonVersion(3, 7) + assert lint.py_version == "py37" assert lint.isort_known_first_party == ["alpha"] assert lint.isort_known_third_party == ["beta", "gamma"] assert lint.isort_default_section == IsortSectionName.THIRDPARTY @@ -337,7 +337,7 @@ def test_simple_source() -> None: lint = config.lint assert lint.enable_mypy assert lint.line_length == 80 - assert lint.py_version == PythonVersion(2, 7) + assert lint.py_version == "py27" assert lint.source is not None source = lint.source assert source.includes == { @@ -395,7 +395,7 @@ def test_lint_config_update() -> None: enable_black=False, enable_flake8=True, isort_known_first_party=["foo"], - py_version=PythonVersion(3, 8), + py_version="py38", ) lhs.update(rhs) @@ -408,7 +408,7 @@ def test_lint_config_update() -> None: assert lhs.line_length == 80 assert lhs.isort_known_first_party == ["foo"] assert lhs.isort_known_third_party == ["piyo"] - assert lhs.py_version == PythonVersion(3, 8) + assert lhs.py_version == "py38" def test_has_tool_section() -> None: From 52737ffb640de6a0002ef5a61582991ea85f7cac Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Sun, 15 May 2022 19:05:17 +0900 Subject: [PATCH 11/13] Remove exception --- docs/source/overview.rst | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/docs/source/overview.rst b/docs/source/overview.rst index 87e5174..38837cf 100644 --- a/docs/source/overview.rst +++ b/docs/source/overview.rst @@ -42,20 +42,3 @@ To configure such option, you need to create a section ``[[tool.pysen.lint.mypy_ :class:`~pysen.ext.mypy_wrapper.MypyPlugin` has parameters ``paths`` and ``namespace_packages``. Since ``paths`` is equivarent to ``str`` and ``namespace_packages`` is ``bool``, you can set them in the section. Note that ``namespace_packages`` is omitted since it is :obj:`False` by default. - - -Exception -^^^^^^^^^ - -``version`` in ``[tool.pysen]`` and ``py_version`` in ``[tool.pysen.lint]`` are single strings -although they are :class:`~pysen.py_version.VersionRepresentation` and -:class:`~pysen.py_version.PythonVersion`, which have ``major``, ``minor``, -``patch``, and ``pre_release`` as their attributes. - -:class:`~pysen.py_version.VersionRepresentation` - -Specify a pysen version (e.g. ``0.10.2``). - -:class:`~pysen.py_version.PythonVersion` - -Specify one of ``py27``, ``py36``, ``py37``, ``py38``, ``py39``, or ``py310``. From 584249e73f04f1f6cc08a96591ee3b370c27d766 Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Sun, 15 May 2022 19:24:56 +0900 Subject: [PATCH 12/13] Run black for docs/source/conf.py --- docs/source/conf.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 7bbc50b..2378e33 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -17,9 +17,9 @@ # -- Project information ----------------------------------------------------- -project = 'pysen' -copyright = '2022, Preferred Networks, inc.' -author = 'Preferred Networks, inc.' +project = "pysen" +copyright = "2022, Preferred Networks, inc." +author = "Preferred Networks, inc." # -- General configuration --------------------------------------------------- @@ -28,18 +28,18 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.napoleon', - 'sphinx.ext.autodoc', - 'sphinx_autodoc_typehints', + "sphinx.ext.napoleon", + "sphinx.ext.autodoc", + "sphinx_autodoc_typehints", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'venv'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "venv"] # -- Options for HTML output ------------------------------------------------- @@ -47,12 +47,12 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'pydata_sphinx_theme' +html_theme = "pydata_sphinx_theme" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # sphinx.ext.autodoc From c7c1dab1b52acd737f750aa36d72f4c23cad788f Mon Sep 17 00:00:00 2001 From: Makoto Hiramatsu Date: Sun, 15 May 2022 19:25:37 +0900 Subject: [PATCH 13/13] Fix sort --- pysen/factory.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pysen/factory.py b/pysen/factory.py index 795f82b..fb12769 100644 --- a/pysen/factory.py +++ b/pysen/factory.py @@ -2,6 +2,8 @@ import pathlib from typing import Any, Dict, List, Optional +import dacite + from .black import Black, BlackSetting from .component import ComponentBase from .flake8 import Flake8, Flake8Setting @@ -17,8 +19,6 @@ from .py_version import PythonVersion from .source import Source -import dacite - def _parse_python_version(s: Any) -> PythonVersion: if not isinstance(s, str):