From d08c0904a66872609aa2879dc6c9ca347bd106e7 Mon Sep 17 00:00:00 2001 From: Felddy Date: Fri, 15 May 2020 08:42:11 -0400 Subject: [PATCH] Merge branch 'develop' of github.com:cisagov/skeleton-docker into develop --- .bandit.yml | 2 +- .github/lineage.yml | 6 +++++ .github/workflows/build.yml | 29 ++++++++++++++------- .github/workflows/release.yml | 2 +- .gitignore | 5 ++-- .isort.cfg | 12 +++++++++ .mdl_config.json | 3 +++ .pre-commit-config.yaml | 47 +++++++++++++++++++++++++++-------- CONTRIBUTING.md | 29 ++++++++++++++++++--- tests/conftest.py | 2 +- tests/container_test.py | 2 ++ 11 files changed, 111 insertions(+), 28 deletions(-) create mode 100644 .github/lineage.yml create mode 100644 .isort.cfg diff --git a/.bandit.yml b/.bandit.yml index 5ae161dc..2b618f68 100644 --- a/.bandit.yml +++ b/.bandit.yml @@ -10,4 +10,4 @@ tests: # - B102 skips: - - B101 # skip "assert used" check since assertions are required in pytests + - B101 # skip "assert used" check since assertions are required in pytests diff --git a/.github/lineage.yml b/.github/lineage.yml new file mode 100644 index 00000000..8dfc20b5 --- /dev/null +++ b/.github/lineage.yml @@ -0,0 +1,6 @@ +--- +version: "1" + +lineage: + skeleton: + remote-url: https://github.com/cisagov/skeleton-generic.git diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1cfdf6b6..a6fbd475 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,11 @@ --- name: build -on: [push] +on: + push: + pull_request: + repository_dispatch: + types: [apb] env: IMAGE_NAME: felddy/weewx @@ -12,35 +16,42 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: python-version: 3.8 + - name: Store installed Python version + run: | + echo "::set-env name=PY_VERSION::"\ + "$(python -c "import platform;print(platform.python_version())")" - name: Cache pip test requirements uses: actions/cache@v1 with: path: ${{ env.PIP_CACHE_DIR }} - key: "${{ runner.os }}-pip-test-\ + key: "${{ runner.os }}-pip-test-py${{ env.PY_VERSION }}-\ ${{ hashFiles('**/requirements-test.txt') }}" restore-keys: | + ${{ runner.os }}-pip-test-py${{ env.PY_VERSION }}- ${{ runner.os }}-pip-test- ${{ runner.os }}-pip- - name: Cache pre-commit hooks uses: actions/cache@v1 with: path: ${{ env.PRE_COMMIT_CACHE_DIR }} - key: "${{ runner.os }}-pre-commit-\ + key: "${{ runner.os }}-pre-commit-py${{ env.PY_VERSION }}-\ ${{ hashFiles('**/.pre-commit-config.yaml') }}" - name: Install dependencies run: | python -m pip install --upgrade pip - pip install --upgrade -r requirements-test.txt - - name: Run linters on all files + pip install --upgrade --requirement requirements-test.txt + - name: Set up pre-commit hook environments + run: pre-commit install-hooks + - name: Run pre-commit on all files run: pre-commit run --all-files build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Determine image version id: get_ver run: | @@ -77,7 +88,7 @@ jobs: runs-on: ubuntu-latest needs: [build] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: python-version: 3.8 @@ -93,7 +104,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install --upgrade -r requirements-test.txt + pip install --upgrade --requirement requirements-test.txt - name: Download docker image artifact uses: actions/download-artifact@v1 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fce9988e..a5caa649 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: release: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - uses: actions/setup-python@v1 with: python-version: 3.8 diff --git a/.gitignore b/.gitignore index 0ace7003..dc1a2bf0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -__pycache__ -.python-version +.mypy_cache .pytest_cache +.python-version +__pycache__ data/* diff --git a/.isort.cfg b/.isort.cfg new file mode 100644 index 00000000..ade9bd8d --- /dev/null +++ b/.isort.cfg @@ -0,0 +1,12 @@ +[settings] +combine_star=true +force_sort_within_sections=true + +import_heading_stdlib=Standard Python Libraries +import_heading_thirdparty=Third-Party Libraries +import_heading_firstparty=Local Libraries + +# Should be auto-populated by seed-isort-config hook +known_third_party=pytest +# These must be manually set to correctly separate them from third party libraries +known_first_party= diff --git a/.mdl_config.json b/.mdl_config.json index 492955ad..7a6f3f8e 100644 --- a/.mdl_config.json +++ b/.mdl_config.json @@ -3,5 +3,8 @@ "code_blocks": false, "tables": false }, + "MD024": { + "allow_different_nesting": true + }, "default": true } diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5661f71a..7a3268f5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ default_language_version: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.4.0 + rev: v2.5.0 hooks: - id: check-executables-have-shebangs - id: check-json @@ -28,13 +28,13 @@ repos: - id: requirements-txt-fixer - id: trailing-whitespace - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.19.0 + rev: v0.23.0 hooks: - id: markdownlint args: - --config=.mdl_config.json - repo: https://github.com/adrienverge/yamllint - rev: v1.18.0 + rev: v1.23.0 hooks: - id: yamllint - repo: https://github.com/detailyang/pre-commit-shell @@ -42,13 +42,13 @@ repos: hooks: - id: shell-lint - repo: https://gitlab.com/pycqa/flake8 - rev: 3.7.9 + rev: 3.8.1 hooks: - id: flake8 additional_dependencies: - flake8-docstrings - repo: https://github.com/asottile/pyupgrade - rev: v1.25.1 + rev: v2.4.1 hooks: - id: pyupgrade # Run bandit on "tests" tree with a configuration @@ -71,20 +71,47 @@ repos: rev: 19.10b0 hooks: - id: black + - repo: https://github.com/asottile/seed-isort-config + rev: v2.1.1 + hooks: + - id: seed-isort-config + - repo: https://github.com/timothycrosley/isort + rev: 4.3.21 + hooks: + - id: isort - repo: https://github.com/ansible/ansible-lint.git - rev: v4.1.1a5 + rev: v4.3.0a0 hooks: - id: ansible-lint - repo: https://github.com/antonbabenko/pre-commit-terraform.git - rev: v1.12.0 + rev: v1.30.0 hooks: - id: terraform_fmt - - id: terraform_validate_no_variables + # There are ongoing issues with how this command works. This issue + # documents the core issue: + # https://github.com/hashicorp/terraform/issues/21408 + # We have seen issues primarily with proxy providers and Terraform code + # that uses remote state. The PR + # https://github.com/hashicorp/terraform/pull/24887 + # has been approved and is part of the 0.13 release to resolve the issue + # with remote states. + # The PR + # https://github.com/hashicorp/terraform/pull/24896 + # is a proprosed fix to deal with `terraform validate` with proxy + # providers (among other configurations). + # We have decided to disable the terraform_validate hook until the issues + # above have been resolved, which we hope will be with the release of + # Terraform 0.13. + # - id: terraform_validate - repo: https://github.com/IamTheFij/docker-pre-commit - rev: v1.0.0 + rev: v1.0.1 hooks: - id: docker-compose-check - repo: https://github.com/prettier/prettier - rev: 1.19.1 + rev: 2.0.5 hooks: - id: prettier + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.770 + hooks: + - id: mypy diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d6684ea6..ae3c5f9c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,10 +56,31 @@ eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)" ``` -For Linux (or on the Mac, if you don't want to use `brew`) you can use +For Linux, Windows Subsystem for Linux (WSL), or on the Mac (if you +don't want to use `brew`) you can use [pyenv/pyenv-installer](https://github.com/pyenv/pyenv-installer) to -install the necessary tools. When you are finished you will need to -add the same two lines above to your profile. +install the necessary tools. Before running this ensure that you have +installed the prerequisites for your platform according to the +[`pyenv` wiki +page](https://github.com/pyenv/pyenv/wiki/common-build-problems). + +On WSL you should treat your platform as whatever Linux distribution +you've chosen to install. + +Once you have installed `pyenv` you will need to add the following +lines to your `.bashrc`: + +```bash +export PATH="$PATH:$HOME/.pyenv/bin" +eval "$(pyenv init -)" +eval "$(pyenv virtualenv-init -)" +``` + +If you are using a shell other than `bash` you should follow the +instructions that the `pyenv-installer` script outputs. + +You will need to reload your shell for these changes to take effect so +you can begin to use `pyenv`. For a list of Python versions that are already installed and ready to use with `pyenv`, use the command `pyenv versions`. To see a list of @@ -81,7 +102,7 @@ commands: cd weewx-docker pyenv virtualenv weewx-docker pyenv local weewx-docker -pip install -r requirements-dev.txt +pip install --requirement requirements-dev.txt ``` #### Installing the pre-commit hook #### diff --git a/tests/conftest.py b/tests/conftest.py index 12091e5b..abce83c8 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,9 +2,9 @@ https://docs.pytest.org/en/latest/writing_plugins.html#conftest-py-plugins """ +# Third-Party Libraries import pytest - MAIN_SERVICE_NAME = "weewx" VERSION_SERVICE_NAME = f"{MAIN_SERVICE_NAME}-version" diff --git a/tests/container_test.py b/tests/container_test.py index b37f88f7..7f90ef91 100644 --- a/tests/container_test.py +++ b/tests/container_test.py @@ -1,9 +1,11 @@ #!/usr/bin/env pytest -vs """Tests for example container.""" +# Standard Python Libraries import os import time +# Third-Party Libraries import pytest READY_MESSAGE = "engine: Starting main packet loop"