Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
andreoliwa committed May 29, 2023
2 parents 86f830c + dbd9ac7 commit c39a973
Show file tree
Hide file tree
Showing 56 changed files with 505 additions and 516 deletions.
14 changes: 14 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# These are supported funding model platforms
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/displaying-a-sponsor-button-in-your-repository

github: [andreoliwa] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
# patreon: # Replace with a single Patreon username
# open_collective: andreoliwa # Replace with a single Open Collective username
ko_fi: andreoliwa # Replace with a single Ko-fi username
# tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
# community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: andreoliwa # Replace with a single Liberapay username
# issuehunt: # Replace with a single IssueHunt username
# otechie: # Replace with a single Otechie username
# lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: ["https://www.paypal.me/andreoliwa", "https://www.buymeacoffee.com/andreoliwa"] # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
18 changes: 17 additions & 1 deletion .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@

name: Python

on: [push]
on: [push, pull_request]

jobs:
# Adapted from https://github.com/marketplace/actions/skip-duplicate-actions
pre_job:
# continue-on-error: true # TODO: Uncomment once integration is finished
runs-on: ubuntu-latest
# Map a step output to a job output
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5
with:
# https://github.com/marketplace/actions/skip-duplicate-actions#skip-concurrent-workflow-runs
concurrent_skipping: "same_content_newer"

build:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
name: "${{ matrix.python-version }} ${{ matrix.os }}"
strategy:
fail-fast: false
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,6 @@ ENV/

# macOS
.DS_Store

# pytest-testmon
.testmondata*
64 changes: 8 additions & 56 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,18 @@ repos:
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.269
hooks:
- id: pyupgrade
args: [--py37-plus]
- id: ruff
args: [--fix]
- repo: https://github.com/aio-libs/sort-all # TODO: style(pre-commit): add sort-all
rev: v1.2.0
hooks:
- id: sort-all
language_version: python3.8
- repo: https://github.com/PyCQA/autoflake
rev: v2.0.2
hooks:
- id: autoflake
args:
[
--in-place,
--remove-all-unused-imports,
--remove-unused-variables,
--remove-duplicate-keys,
--ignore-init-module-imports,
--exclude,
compat.py,
]
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
args: [--safe, --quiet]
Expand All @@ -73,46 +59,18 @@ repos:
hooks:
- id: blacken-docs
additional_dependencies: [black==22.1.0]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
# To avoid ERROR: Package 'isort' requires a different Python: 3.7.12 not in '>=3.8.0'
language_version: python3.8
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: python-check-blanket-noqa
- id: python-check-mock-methods
- id: python-no-eval
- id: python-no-log-warn
- id: rst-backticks
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0-alpha.6
rev: v3.0.0-alpha.9-for-vscode
hooks:
- id: prettier
stages: [commit]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
language_version: python3.8
additional_dependencies:
[
flake8-blind-except,
flake8-bugbear,
flake8-comprehensions,
flake8-debugger,
flake8-docstrings,
flake8-isort,
flake8-polyfill,
flake8-pytest,
flake8-quotes,
flake8-typing-imports,
yesqa,
]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
rev: v1.3.0
hooks:
- id: mypy
# https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-show-error-codes
Expand Down Expand Up @@ -140,12 +98,6 @@ repos:
language: system
types: [python]
exclude: tests/
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
hooks:
- id: bandit
args: [--ini, setup.cfg]
exclude: tests/
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2
hooks:
Expand All @@ -157,7 +109,7 @@ repos:
# https://docs.openstack.org/bashate/latest/man/bashate.html#options
args: [-i, E006]
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.42.1
rev: 3.2.2
hooks:
- id: commitizen
stages: [commit-msg]
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
poetry 1.4.1
pre-commit 3.2.0
poetry 1.5.0
pre-commit 3.3.2
35 changes: 18 additions & 17 deletions docs/autofix_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
It doesn't recognise the "styles" dir anywhere (on the root, under "docs", under "_static"...).
Not even changing ``html_static_path`` on ``conf.py`` worked.
"""
from __future__ import annotations

import sys
from collections import defaultdict
from importlib import import_module
from pathlib import Path
from subprocess import check_output # nosec
from textwrap import dedent, indent
from typing import Optional, Dict, List, Set, Tuple, Union

import attr
import click
Expand Down Expand Up @@ -55,15 +56,16 @@ class FileType:

text: str
url: str
check: Union[bool, int]
autofix: Union[bool, int]
check: bool | int
autofix: bool | int

def __post_init__(self):
"""Warn about text that might render incorrectly."""
if "`" in self.text:
raise RuntimeError(f"Remove all backticks from the text: {self.text}")
msg = f"Remove all backticks from the text: {self.text}"
raise RuntimeError(msg)

def __lt__(self, other: "FileType") -> bool:
def __lt__(self, other: FileType) -> bool:
"""Sort instances.
From the `docs <https://docs.python.org/3/howto/sorting.html#odd-and-ends>`_:
Expand Down Expand Up @@ -103,12 +105,12 @@ def autofix_str(self) -> str:
return self._pretty("autofix")

@property
def row(self) -> Tuple[str, str, str]:
def row(self) -> tuple[str, str, str]:
"""Tuple for a table row."""
return self.text_with_url, self.check_str, self.autofix_str


IMPLEMENTED_FILE_TYPES: Set[FileType] = {
IMPLEMENTED_FILE_TYPES: set[FileType] = {
FileType("Any INI file", f"{READ_THE_DOCS_URL}plugins.html#ini-files", True, True),
FileType("Any JSON file", f"{READ_THE_DOCS_URL}plugins.html#json-files", True, True),
FileType("Any plain text file", f"{READ_THE_DOCS_URL}plugins.html#text-files", True, False),
Expand All @@ -118,7 +120,7 @@ def row(self) -> Tuple[str, str, str]:
FileType(PYLINTRC, f"{READ_THE_DOCS_URL}plugins.html#ini-files", True, True),
FileType(SETUP_CFG, f"{READ_THE_DOCS_URL}plugins.html#ini-files", True, True),
}
PLANNED_FILE_TYPES: Set[FileType] = {
PLANNED_FILE_TYPES: set[FileType] = {
FileType("Any Markdown file", "", 280, 0),
FileType("Any Terraform file", "", 318, 0),
FileType(".dockerignore", "", 8, 8),
Expand All @@ -145,7 +147,7 @@ def __init__(self, filename: str) -> None:
self.divider_end = RST_DIVIDER_END
self.divider_from_here = RST_DIVIDER_FROM_HERE

def write(self, lines: List[str], divider: Optional[str] = None) -> int:
def write(self, lines: list[str], divider: str | None = None) -> int:
"""Write content to the file."""
old_content = self.file.read_text()
if divider:
Expand Down Expand Up @@ -193,7 +195,6 @@ def write_plugins() -> int:
):
header = plugin_class.filename
if not header:
# module_name = file_class.__module__
module = import_module(plugin_class.__module__)
header = (module.__doc__ or "").strip(" .")

Expand Down Expand Up @@ -234,7 +235,7 @@ def write_cli() -> int:
parts.append(command)
parts.append("--help")
print(" ".join(parts))
output = check_output(parts).decode().strip() # nosec
output = check_output(parts).decode().strip() # noqa: S603
blocks.append(
clean_template.format(
anchor=anchor, header=header, dashes="-" * len(header), long=dedent(long), help=indent(output, " ")
Expand All @@ -252,20 +253,20 @@ def write_config() -> int:
return DocFile("configuration.rst").write(blocks, divider="config-file")


def rst_table(header: Tuple[str, ...], rows: List[Tuple[str, ...]]) -> List[str]:
def rst_table(header: tuple[str, ...], rows: list[tuple[str, ...]]) -> list[str]:
"""Create a ReST table from header and rows."""
blocks = [".. list-table::\n :header-rows: 1\n"]
num_columns = len(header)
for row in [header] + rows:
for row in [header, *rows]:
template = ("*" + " - {}\n " * num_columns).rstrip()
blocks.append(indent(template.format(*row), " "))
return blocks


def write_readme(file_types: Set[FileType], divider: str) -> int:
def write_readme(file_types: set[FileType], divider: str) -> int:
"""Write the README."""
# TODO: chore: quickstart.rst has some parts of README.rst as a copy/paste/change
rows: List[Tuple[str, ...]] = []
rows: list[tuple[str, ...]] = []
for file_type in sorted(file_types):
rows.append(file_type.row)

Expand All @@ -281,9 +282,9 @@ class StyleLibraryRow: # pylint: disable=too-few-public-methods
name: str


def _build_library(gitref: bool = True) -> List[str]:
def _build_library(gitref: bool = True) -> list[str]:
# pylint: disable=no-member
library: Dict[str, List[Tuple]] = defaultdict(list)
library: dict[str, list[tuple]] = defaultdict(list)
pre, post = (":gitref:", "") if gitref else ("", "_")
for path in sorted(builtin_styles()): # type: Path
style = BuiltinStyle.from_path(path)
Expand Down
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
Configuration file for the Sphinx documentation builder.
"""Configuration file for the Sphinx documentation builder.
This file does only contain a selection of the most common options. For a
full list see the documentation:
Expand All @@ -15,7 +14,7 @@

# -- Project information -----------------------------------------------------
project = "nitpick"
copyright = "2019, W. Augusto Andreoli" # pylint: disable=redefined-builtin
copyright = "2019, W. Augusto Andreoli" # pylint: disable=redefined-builtin # noqa: A001
author = "W. Augusto Andreoli"

# The short X.Y version
Expand Down
3 changes: 2 additions & 1 deletion docs/ideas/lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def convert(path_from_root: str):
if "yaml" in tags:
which_doc = YamlDoc(path=path_from_root)
else:
raise NotImplementedError(f"No conversion for these types: {tags}")
msg = f"No conversion for these types: {tags}"
raise NotImplementedError(msg)

toml_doc = TomlDoc(obj={path_from_root: which_doc.as_object}, use_tomlkit=True)
print(toml_doc.reformatted)
Expand Down
Loading

0 comments on commit c39a973

Please sign in to comment.