diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 7735a52..9c3d21f 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,7 +1,10 @@ # Each line is a file pattern followed by one or more owners. -# These owners will be the default owners for everything in -# the repo. Unless a later match takes precedence, -# these owners will be requested for review when someone -# opens a pull request. +# These owners will be the default owners for everything in the +# repo. Unless a later match takes precedence, these owners will be +# requested for review when someone opens a pull request. * @dav3r @felddy @hillaryj @jsf9k @mcdonnnj + +# These folks own any files in the .github directory at the root of +# the repository and any of its subdirectories. +/.github/ @dav3r @felddy @hillaryj @jsf9k @mcdonnnj diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0d62046..0899a15 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,26 +16,25 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - id: setup-python + uses: actions/setup-python@v2 with: python-version: 3.9 - - name: Store installed Python version - run: | - echo "PY_VERSION="\ - "$(python -c "import platform;print(platform.python_version())")" \ - >> $GITHUB_ENV - name: Cache linting environments uses: actions/cache@v2 with: path: | ${{ env.PIP_CACHE_DIR }} ${{ env.PRE_COMMIT_CACHE_DIR }} - key: "lint-${{ runner.os }}-py${{ env.PY_VERSION }}-\ + key: | + lint-${{ runner.os }}-\ + py${{ steps.setup-python.outputs.python-version }}-\ ${{ hashFiles('**/requirements-test.txt') }}-\ ${{ hashFiles('**/requirements.txt') }}-\ ${{ hashFiles('**/.pre-commit-config.yaml') }}" restore-keys: | - lint-${{ runner.os }}-py${{ env.PY_VERSION }}- + lint-${{ runner.os }}-\ + py${{ steps.setup-python.outputs.python-version }}- lint-${{ runner.os }}- - name: Install dependencies run: | @@ -59,11 +58,13 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.PIP_CACHE_DIR }} - key: "test-${{ runner.os }}-py${{ matrix.python-version }}-\ + key: "test-${{ runner.os }}-\ + py${{ matrix.python-version }}-\ ${{ hashFiles('**/requirements-test.txt') }}-\ ${{ hashFiles('**/requirements.txt') }}" restore-keys: | - test-${{ runner.os }}-py${{ matrix.python-version }}- + test-${{ runner.os }}-\ + py${{ matrix.python-version }}- test-${{ runner.os }}- - name: Install dependencies run: | @@ -93,10 +94,12 @@ jobs: uses: actions/cache@v2 with: path: ${{ env.PIP_CACHE_DIR }} - key: "build-${{ runner.os }}-py${{ matrix.python-version }}-\ + key: "build-${{ runner.os }}-\ + py${{ matrix.python-version }}-\ ${{ hashFiles('**/requirements.txt') }}" restore-keys: | - build-${{ runner.os }}-py${{ matrix.python-version }}- + build-${{ runner.os }}-\ + py${{ matrix.python-version }}- build-${{ runner.os }}- - name: Install dependencies run: | @@ -114,21 +117,20 @@ jobs: needs: build steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - id: setup-python + uses: actions/setup-python@v2 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 lambda building environments uses: actions/cache@v2 with: path: ${{ env.PIP_CACHE_DIR }} - key: "build_lambda-${{ runner.os }}-py${{ env.PY_VERSION }}-\ + key: "build_lambda-${{ runner.os }}-\ + py${{ steps.setup-python.outputs.python-version }}-\ ${{ hashFiles('**/requirements.txt') }}" restore-keys: | - build_lambda-${{ runner.os }}-py${{ env.PY_VERSION }}- + build_lambda-${{ runner.os }}-\ + py${{ steps.setup-python.outputs.python-version }}- build_lambda-${{ runner.os }}- - name: Install dependencies run: | @@ -150,5 +152,6 @@ jobs: - name: Upload artifacts uses: actions/upload-artifact@v2 with: - name: skeleton-aws-lambda-py${{ env.PY_VERSION }} + name: "skeleton-aws-lambda-\ + py${{ steps.setup-python.outputs.python-version }}" path: lambda_zip_contents/ diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ca7b8d..339898a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,21 +14,20 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - id: setup-python + uses: actions/setup-python@v2 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 lambda building environments uses: actions/cache@v2 with: path: ${{ env.PIP_CACHE_DIR }} - key: "release-${{ runner.os }}-py${{ env.PY_VERSION }}-\ + key: "release-${{ runner.os }}-\ + py${{ steps.setup-python.outputs.python-version }}-\ ${{ hashFiles('**/requirements.txt') }}" restore-keys: | - release-${{ runner.os }}-py${{ env.PY_VERSION }}- + release-${{ runner.os }}-\ + py${{ steps.setup-python.outputs.python-version }}- release-${{ runner.os }}- - name: Install dependencies run: | diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13396b3..13f519b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,30 +26,30 @@ repos: - --autofix - id: requirements-txt-fixer - id: trailing-whitespace + + # Text file hooks - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.24.0 hooks: - id: markdownlint args: - --config=.mdl_config.json + - repo: https://github.com/prettier/pre-commit + rev: v2.1.2 + hooks: + - id: prettier - repo: https://github.com/adrienverge/yamllint rev: v1.25.0 hooks: - id: yamllint + + # Shell script hooks - repo: https://github.com/detailyang/pre-commit-shell rev: 1.0.5 hooks: - id: shell-lint - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.8.4 - hooks: - - id: flake8 - additional_dependencies: - - flake8-docstrings - - repo: https://github.com/asottile/pyupgrade - rev: v2.7.2 - hooks: - - id: pyupgrade + + # Python hooks # Run bandit on "tests" tree with a configuration - repo: https://github.com/PyCQA/bandit rev: 1.6.2 @@ -70,15 +70,33 @@ repos: rev: 20.8b1 hooks: - id: black + - repo: https://gitlab.com/pycqa/flake8 + rev: 3.8.4 + hooks: + - id: flake8 + additional_dependencies: + - flake8-docstrings - repo: https://github.com/timothycrosley/isort rev: 5.6.4 hooks: - id: isort + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.790 + hooks: + - id: mypy + - repo: https://github.com/asottile/pyupgrade + rev: v2.7.2 + hooks: + - id: pyupgrade + + # Ansible hooks - repo: https://github.com/ansible/ansible-lint.git rev: v4.3.5 hooks: - id: ansible-lint # files: molecule/default/playbook.yml + + # Terraform hooks - repo: https://github.com/antonbabenko/pre-commit-terraform.git rev: v1.43.0 hooks: @@ -99,15 +117,9 @@ repos: # above have been resolved, which we hope will be with the release of # Terraform 0.13. # - id: terraform_validate + + # Docker hooks - repo: https://github.com/IamTheFij/docker-pre-commit rev: v2.0.0 hooks: - id: docker-compose-check - - repo: https://github.com/prettier/pre-commit - rev: v2.1.2 - hooks: - - id: prettier - - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.790 - hooks: - - id: mypy diff --git a/docker-compose.yml b/docker-compose.yml index 6c67abb..bb4d3c3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,4 @@ +--- version: '3.2' services: diff --git a/eal/__init__.py b/eal/__init__.py index 7699f8d..2e71774 100644 --- a/eal/__init__.py +++ b/eal/__init__.py @@ -1,3 +1,6 @@ """This package contains the skeleton-aws-lambda code.""" - -__version__ = "1.0.0" +# We disable a Flake8 check for "Module imported but unused (F401)" here because +# although this import is not directly used, it populates the value +# package_name.__version__, which is used to get version information about this +# Python package. +from ._version import __version__ # noqa: F401 diff --git a/setup.py b/setup.py index 1004cbf..34b48b7 100644 --- a/setup.py +++ b/setup.py @@ -9,8 +9,9 @@ """ # Standard Python Libraries +import codecs from glob import glob -from os.path import basename, splitext +from os.path import abspath, basename, dirname, join, splitext # Third-Party Libraries from setuptools import find_packages, setup @@ -22,18 +23,28 @@ def readme(): return f.read() -def package_vars(version_file): - """Read in and return the variables defined by the version_file.""" - pkg_vars = {} - with open(version_file) as f: - exec(f.read(), pkg_vars) # nosec - return pkg_vars +# Below two methods were pulled from: +# https://packaging.python.org/guides/single-sourcing-package-version/ +def read(rel_path): + """Open a file for reading from a given relative path.""" + here = abspath(dirname(__file__)) + with codecs.open(join(here, rel_path), "r") as fp: + return fp.read() + + +def get_version(version_file): + """Extract a version number from the given file path.""" + for line in read(version_file).splitlines(): + if line.startswith("__version__"): + delim = '"' if '"' in line else "'" + return line.split(delim)[1] + raise RuntimeError("Unable to find version string.") setup( name="example-aws-lambda", # Versions should comply with PEP440 - version=package_vars("eal/_version.py")["__version__"], + version=get_version("eal/_version.py"), description="A skeleton with an example AWS lambda to build from.", long_description=readme(), long_description_content_type="text/markdown", @@ -69,10 +80,10 @@ def package_vars(version_file): keywords="skeleton", packages=find_packages(where="."), py_modules=[splitext(basename(path))[0] for path in glob("eal/*.py")], - install_requires=["docopt", "setuptools"], + install_requires=["docopt", "setuptools >= 24.2.0"], extras_require={ "test": [ - "pre-commit", + "coverage", # coveralls 1.11.0 added a service number for calls from # GitHub Actions. This caused a regression which resulted in a 422 # response from the coveralls API with the message: @@ -80,7 +91,7 @@ def package_vars(version_file): # 1.11.1 fixed this issue, but to ensure expected behavior we'll pin # to never grab the regression version. "coveralls != 1.11.0", - "coverage", + "pre-commit", "pytest-cov", "pytest", ]