From b17c1942eecabbed494c6350894177514d30e7c4 Mon Sep 17 00:00:00 2001 From: Jonathan Sick Date: Fri, 26 Feb 2021 14:53:26 -0500 Subject: [PATCH 1/2] Set up roman-lander-plugin package Covers basic packaging, testing/tox and code quality (pre-commit). --- .pre-commit-config.yaml | 38 ++++++++++++++++++ CHANGELOG.rst | 7 ++++ LICENSE | 21 ++++++++++ Makefile | 11 ++++++ README.rst | 17 ++++++++ pyproject.toml | 56 +++++++++++++++++++++++++++ setup.cfg | 77 +++++++++++++++++++++++++++++++++++++ setup.py | 3 ++ src/romanlander/__init__.py | 22 +++++++++++ tests/init_test.py | 7 ++++ tox.ini | 34 ++++++++++++++++ 11 files changed, 293 insertions(+) create mode 100644 .pre-commit-config.yaml create mode 100644 CHANGELOG.rst create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.rst create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 src/romanlander/__init__.py create mode 100644 tests/init_test.py create mode 100644 tox.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..749cf5c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,38 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 + hooks: + - id: check-yaml + - id: check-toml + - id: check-json + - id: trailing-whitespace + +- repo: https://github.com/Lucas-C/pre-commit-hooks-markup + rev: v1.0.1 + hooks: + - id: rst-linter + files: (README\.rst)|(CHANGELOG\.rst) + +- repo: https://github.com/PyCQA/isort + rev: 5.7.0 + hooks: + - id: isort + additional_dependencies: + - toml + +- repo: https://github.com/psf/black + rev: 20.8b1 + hooks: + - id: black + +- repo: https://github.com/asottile/blacken-docs + rev: v1.9.1 + hooks: + - id: blacken-docs + additional_dependencies: [black==20.8b0] + args: [-l, "79", -t, py38] + +- repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.4 + hooks: + - id: flake8 diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..a91a744 --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,7 @@ +Change log +========== + +Unreleased +---------- + +First release of roman-lander-plugin. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7cf2345 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 California Institute of Technology + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..89c1397 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +.PHONY: help +help: + @echo "Make command reference" + @echo " make init ........ (initialize for development)" + +.PHONY: init +init: + pip install -e ".[dev]" + pip install tox tox-pyenv pre-commit + pre-commit install + rm -rf .tox diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..a5c6906 --- /dev/null +++ b/README.rst @@ -0,0 +1,17 @@ +################### +roman-lander-plugin +################### + +This plugin configures Lander, the PDF landing page static site generator, for Roman Observatory documents. + +Development workflow +==================== + +Using a virtual environment is best practice. +To install the plugin within the virtual environment, along with development dependencies, run:: + + make init + +To run the full suite of test and linting commands (assuming Python 3.8 is available):: + + tox diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..36e021b --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,56 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "setuptools_scm[toml]>=3.4" +] +build-backend = 'setuptools.build_meta' + +[tool.setuptools_scm] + +[tool.black] +line-length = 79 +target-version = ['py38'] +exclude = ''' +/( + \.eggs + | \.git + | \.mypy_cache + | \.tox + | \.venv + | _build + | build + | dist + | node_modules +)/ +''' +# Use single-quoted strings so TOML treats the string like a Python r-string +# Multi-line strings are implicitly treated by black as regular expressions + +[tool.isort] +include_trailing_comma = true +multi_line_output = 3 +known_first_party = "romanlander" +skip = ["docs/conf.py"] + +[tool.coverage.run] +parallel = true +branch = true +source = ["romanlander"] + +[tool.coverage.paths] +source = ["src", ".tox/*/site-packages"] + +[tool.coverage.report] +show_missing = true +exclude_lines = [ + "pragma: no cover", + "def __repr__", + "if self.debug:", + "if settings.DEBUG", + "raise AssertionError", + "raise NotImplementedError", + "if 0:", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:" +] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..e5ac001 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,77 @@ +[metadata] +name = roman-lander-plugin +description = Roman Observatory plugin for the Lander PDF landing page tool. +author = J.Sick Codes Inc. +author_email = hi@jsick.codes +long_description = file: README.rst, CHANGELOG.rst, LICENSE +long_description_content_type = text/x-rst +url = https://github.com/jsickcodes/roman-lander-plugin +project_urls = + Change log = https://github.com/jsickcodes/roman-lander-plugin/blob/master/CHANGELOG.rst + Source code = https://github.com/jsickcodes/roman-lander-plugin + Issue tracker = https://github.com/jsickcodes/roman-lander-plugin/issues +classifiers = + Development Status :: 4 - Beta + License :: OSI Approved :: MIT License + Programming Language :: Python + Programming Language :: Python :: 3 + Topic :: Documentation + Intended Audience :: Science/Research + Natural Language :: English + Operating System :: POSIX + Typing :: Typed +keywords = + roman + lander + +[options] +zip_safe = False +include_package_data = True +package_dir = + = src +packages = find: +python_requires = >=3.7 +setup_requires = + setuptools_scm +install_requires = + importlib_metadata; python_version < "3.8" + lander >= 2.0.0a6 + +[options.packages.find] +where = src + +[options.package_data] +romanlander = + themes/roman/templates/*.jinja + themes/roman/site/*.js + themes/roman/site/*.css + themes/roman/site/*.png + themes/roman/site/*.jpg + themes/roman/site/*.svg + themes/roman/site/*.txt + themes/roman/site/*.jinja + +[options.extras_require] +dev = + pytest + coverage[toml] + beautifulsoup4 + +[flake8] +max-line-length = 79 +# E203: whitespace before :, flake8 disagrees with PEP 8 +# W503: line break after binary operator, flake8 disagrees with PEP 8 +ignore = E203, W503 + +[tool:pytest] +norecursedirs = node_modules + +[mypy] +disallow_untyped_defs = True +disallow_incomplete_defs = True +ignore_missing_imports = True +show_error_codes = True +strict_equality = True +warn_redundant_casts = True +warn_unreachable = True +warn_unused_ignores = True diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d5d43d7 --- /dev/null +++ b/setup.py @@ -0,0 +1,3 @@ +from setuptools import setup + +setup(use_scm_version=True) diff --git a/src/romanlander/__init__.py b/src/romanlander/__init__.py new file mode 100644 index 0000000..ae2049b --- /dev/null +++ b/src/romanlander/__init__.py @@ -0,0 +1,22 @@ +"""The Roman Observatory plugin for Lander, the PDF landing page static site +generator. +""" + +__all__ = ["__version__"] + +import sys + +if sys.version_info < (3, 8): + from importlib_metadata import PackageNotFoundError, version +else: + from importlib.metadata import PackageNotFoundError, version + + +__version__: str +"""The package version string (PEP 440 / SemVer compatible).""" + +try: + __version__ = version(__name__) +except PackageNotFoundError: + # package is not installed + __version__ = "0.0.0" diff --git a/tests/init_test.py b/tests/init_test.py new file mode 100644 index 0000000..58bbf2f --- /dev/null +++ b/tests/init_test.py @@ -0,0 +1,7 @@ +"""Test the romanlander __init__ module.""" + +from romanlander import __version__ + + +def test_version() -> None: + assert isinstance(__version__, str) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..c415196 --- /dev/null +++ b/tox.ini @@ -0,0 +1,34 @@ +[tox] +envlist = py38,coverage-report,lint,typing +isolated_build = True + +[testenv] +description = Run pytest against {envname}. +extras = + dev +commands= + coverage run -m pytest {posargs} + +[testenv:coverage-report] +description = Compile coverage from each test run. +skip_install = true +deps = coverage[toml]>=5.0.2 +depends = + py38 +commands = + coverage combine + coverage report + +[testenv:lint] +description = Lint codebase by running pre-commit (Black, isort, Flake8). +skip_install = true +deps = + pre-commit +commands = pre-commit run --all-files + +[testenv:typing] +description = Run mypy. +deps = + mypy +commands = + mypy src/romanlander tests setup.py From b825eebfaa2a1f903dd09e2f0a641b297b2ea3f0 Mon Sep 17 00:00:00 2001 From: Jonathan Sick Date: Fri, 26 Feb 2021 15:16:42 -0500 Subject: [PATCH 2/2] Add GitHub Actions workflow for CI --- .github/workflows/ci.yaml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..ac77fa8 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,30 @@ +name: CI + +"on": [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: [3.7, 3.8, 3.9] + + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 # full history for setuptools_scm + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Python install + run: | + python -m pip install --upgrade pip + python -m pip install .[dev] + python -m pip install tox + + - name: Run tests + run: tox -e py,lint,typing