Skip to content

Commit

Permalink
Alpha (#1)
Browse files Browse the repository at this point in the history
* add tests for getting sections
* add tests for args
* add tests for attrs
* add tests for raises
* add tests for yields and returns
* add tests for parse
* add implementation for getting docstring information
* add check for missing docstring
* add check for arguments on function not defined in docstring
* add check for function with arguments without the args section
* add check for no function args but docstring has args section
* add check for arguments in docstring but not function
* add capturing all args section names
* add check for multiple args sections
* include checks for *args and **kwargs
* skip test functions
* add integration tests
* add support for positional only arguments
* add support for kyword only args
* add support for async function
* add support for skipping fixture
* add getting started
* add docs for checks that returns section is present
* add check for return value
* add support for checking for empty args section
* add check for returns section for function without return value
* add check for multiple returns sections
* add documentation for check that yield functions have the yield docstring section
* add checks for yields
* add documentation for raises section
* add checks for raises section
* add check for raise without any exceptions defined
* add capturing all attrs section
* add augmented and typed assignment
* add tests for multiple functions/ classes
  • Loading branch information
jdkandersson authored Jan 2, 2023
1 parent f41a2b9 commit c8c3eef
Show file tree
Hide file tree
Showing 28 changed files with 7,984 additions and 1 deletion.
11 changes: 11 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:0-3.11",
"features": {
"ghcr.io/devcontainers/features/python:1": {},
"ghcr.io/devcontainers-contrib/features/black:1": {},
"ghcr.io/devcontainers-contrib/features/tox:1": {},
"ghcr.io/devcontainers-contrib/features/isort:1": {},
"ghcr.io/devcontainers-contrib/features/poetry:1": {}
}
}
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 99
max-doc-length = 99
extend-ignore = E203,W503
per-file-ignores =
tests/*:D205,D400
flake8_docstrings_complete/*:N802
test-docs-pattern = given/when/then
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "monthly"
166 changes: 166 additions & 0 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
name: CI-CD

on:
push:
branches:
- main
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
pull_request:
branches:
- main

jobs:
constants:
name: Constants
runs-on: ubuntu-latest
outputs:
package_name: ${{ steps.output.outputs.package_name }}
package_version: ${{ steps.output.outputs.package_version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- id: output
run: |
echo package_name=$(python -c 'import tomllib;from pathlib import Path;print(tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))["tool"]["poetry"]["name"])') >> $GITHUB_OUTPUT
echo package_version=$(python -c 'import tomllib;from pathlib import Path;print(tomllib.loads(Path("pyproject.toml").read_text(encoding="utf-8"))["tool"]["poetry"]["version"])') >> $GITHUB_OUTPUT
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install tox
run: python -m pip install tox
- name: Run linting
run: tox -e lint
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: python -m pip install tox
- name: Run testing
run: tox -e test
release-test-pypi:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- test
- lint
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install poetry
run: python -m pip install poetry
- name: Publish
run: |
poetry config repositories.test-pypi https://test.pypi.org/legacy/
poetry publish --build -u __token__ -p ${{ secrets.test_pypi_password }} -r test-pypi
test-release-test-pypi:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- release-test-pypi
- constants
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run check
run: |
for i in 1 2 3 4 5; do python -m pip install flake8 ${{ needs.constants.outputs.package_name }}==${{ needs.constants.outputs.package_version }} --extra-index-url https://test.pypi.org/simple/ && break || sleep 10; done
echo '"""Docstring."""' > source.py
flake8 source.py
release-pypi:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- test-release-test-pypi
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install poetry
run: python -m pip install poetry
- name: Publish
run: poetry publish --build -u __token__ -p ${{ secrets.pypi_password }}
release-github:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- release-pypi
steps:
- name: Get version from tag
id: tag_name
run: |
echo current_version=${GITHUB_REF#refs/tags/v} >> $GITHUB_OUTPUT
shell: bash
- uses: actions/checkout@v3
- name: Get latest Changelog Entry
id: changelog_reader
uses: mindsers/changelog-reader-action@v2
with:
version: v${{ steps.tag_name.outputs.current_version }}
path: ./CHANGELOG.md
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.changelog_reader.outputs.version }}
release_name: Release ${{ steps.changelog_reader.outputs.version }}
body: ${{ steps.changelog_reader.outputs.changes }}
prerelease: ${{ steps.changelog_reader.outputs.status == 'prereleased' }}
draft: ${{ steps.changelog_reader.outputs.status == 'unreleased' }}
test-release-pypi:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs:
- release-pypi
- constants
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run check
run: |
for i in 1 2 3 4 5; do python -m pip install flake8 ${{ needs.constants.outputs.package_name }}==${{ needs.constants.outputs.package_version }} && break || sleep 10; done
echo '"""Docstring."""' > source.py
flake8 source.py
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"python.analysis.typeCheckingMode": "basic",
"python.linting.pylintEnabled": true,
"python.linting.enabled": true,
"python.formatting.provider": "black"
}
65 changes: 65 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Changelog

## [Unreleased]

## [v1.0.0] - 2023-01-02

### Added

#### Function/ Method Arguments

- Lint check that ensures all function/ method arguments are documented
- Lint check that ensures docstring doesn't describe arguments the function/
method doesn't have
- Lint check that ensures there is at most one arguments section in the
docstring
- Lint check that ensures there is no empty arguments section in the docstring
- Support for unused arguments for which descriptions are optional
- Support `*args` and `**kwargs`
- Support positional only arguments
- Support keyword only arguments
- Support ignoring `self` and `cls` arguments
- Support for skipping test functions in test files
- Support for skipping test fixtures in test and fixture files
- Support async functions/ methods

#### Function/ Method Return Value

- Lint check that ensures all functions/ methods that return a value have the
returns section in the docstring
- Lint check that ensures a function that does not return a value does not have
the returns section
- Lint check that ensures there is at most one returns section in the docstring

#### Function/ Method Yield Value

- Lint check that ensures all functions/ methods that yield a value have the
yields section in the docstring
- Lint check that ensures a function that does not yield a value does not have
the yields section
- Lint check that ensures there is at most one yields section in the docstring

#### Function/ Method Exception Handling

- Lint check that ensures all function/ method exceptions are documented
- Lint check that ensures docstring doesn't describe exceptions the function/
method doesn't raise
- Lint check that ensures there is at most one raises section in the docstring
- Lint check that ensures the raises section describes at least one exception

#### Class Attributes

- Lint check that ensures all class attributes are documented
- Lint check that ensures docstring doesn't describe attributes the class
doesn't have
- Lint check that ensures there is at most one attributes section in the
docstring
- Support for private attributes for which descriptions are optional
- Support for class attributes defined on the class and other `classmethod`
methods
- Support for instance attributes defined in `__init__` and other non-static and
non-`classmethod` methods
- Support async functions/ methods

[//]: # "Release links"
[v1.0.0]: https://github.com/jdkandersson/flake8-docstrings-complete/releases/v1.0.0
Loading

0 comments on commit c8c3eef

Please sign in to comment.