Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernization - May 2024 #16

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", 3.11]
python-version: [3.8, 3.9, "3.10", 3.11, 3.12]

steps:
- uses: actions/checkout@v4
Expand All @@ -28,10 +28,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
76 changes: 0 additions & 76 deletions .pylintrc

This file was deleted.

7 changes: 7 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
1.0.0 (unreleased)
------------------

- Add support of Python 3.12.

- |backward-incompatible| Remove support of Git 2.18 and earlier
version. You must now have Git 2.19 (or a more recent version).

- |backward-incompatible| Remove support of Python 3.7.

- |backward-incompatible| Remove ``--xunit-file`` argument from all
commands. It can be replaced by a new ``--format=xunit`` argument
and redirecting the standard output to a file, like this::
Expand Down
6 changes: 2 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ could be extended to work with other code hosting platforms.
Requirements and installation
=============================

You must have Python 3.7 or later, and a relatively recent version of
Git. Git 2.1.4 (shipped with Debian Jessie) is known to work. More
recent versions should work and are supported.
You must have Python 3.8 or later, and Git 2.19.0 or later.

Install with ``pip``, preferably in a virtual environment:

Expand All @@ -74,7 +72,7 @@ Install with ``pip``, preferably in a virtual environment:
$ python3 -m venv /path/to/your/virtualenv
$ source /path/to/your/virtualenv/bin/activate

$ pip install "check-oldies[toml]"
$ pip install check-oldies


Features, configuration and more
Expand Down
22 changes: 2 additions & 20 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
Installation
============

You must have Python 3.7 or later, and a relatively recent version of
Git. Git 2.1.4 (shipped with Debian Jessie) is known to work. More
recent versions should work and are supported.
You must have Python 3.8 or later, and Git 2.19.0 or later.

Install with ``pip``, preferably in a `virtual environment`_:

.. code-block:: bash

$ python3 -m venv /path/to/your/virtualenv
$ source /path/to/your/virtualenv/bin/activate
$ pip install "check-oldies[toml]"


.. note::

If you do not need to read TOML configuration files, you may omit the
optional dependency and install like this:

.. code-block:: bash

$ pip install check-oldies

Configuration files are not required, but some options are only
available through configuration files. If you are not sure, do not
use the latter command. Instead, use ``pip install check-oldies[toml]``
as indicated above.

$ pip install check-oldies

.. _virtual environment: https://packaging.python.org/tutorials/installing-packages/#creating-virtual-environments
41 changes: 41 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,44 @@ known_tests = ["tests"]
skip = [
"docs/conf.py",
]


[tool.pylint.MASTER]
load-plugins = [
"pylint_strict_informational",
]

[tool.pylint.FORMAT]
max-line-length = 120

[tool.pylint."MESSAGES CONTROL"]
enable = [
"use-symbolic-message-instead",
"useless-suppression",
]

disable = [
"attribute-defined-outside-init",
"cyclic-import",
"duplicate-code",
"fixme",
"file-ignored",
"import-outside-toplevel",
"invalid-name",
"locally-disabled",
"missing-docstring",
"no-member",
"protected-access",
"too-few-public-methods",
"too-many-ancestors",
"too-many-arguments",
"too-many-branches",
"too-many-instance-attributes",
"too-many-lines",
"too-many-locals",
"too-many-public-methods",
"too-many-statements",
"ungrouped-imports",
"unused-argument",
"wrong-import-order", # we `isort` with a custom config
]
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-e .[toml]
-e .

# Testing
pytest
Expand All @@ -10,7 +10,7 @@ sphinx_rtd_theme

# Quality
check-manifest
isort[pyproject]
isort
pylint
pylint_strict_informational
twine
Expand Down
9 changes: 4 additions & 5 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
keywords = fixme todo quality
platform = any
project_urls =
Expand All @@ -30,7 +30,9 @@ project_urls =
Bug Tracker = https://github.com/Polyconseil/check-oldies/issues

[options]
python_requires = >=3.7
python_requires = >=3.8
install_requires =
toml; python_version<"3.11"
package_dir=
=src
packages=find:
Expand All @@ -42,9 +44,6 @@ console-scripts =
check-future-tags = check_oldies.check_future_tags:main
forget-me-not = check_oldies.forget_me_not:main

[options.extras_require]
toml = toml

[options.packages.find]
where = src

Expand Down
81 changes: 20 additions & 61 deletions src/check_oldies/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
import dataclasses
import datetime
import re
import subprocess
import typing

import pkg_resources

from . import commands
from . import output

Expand Down Expand Up @@ -230,66 +227,28 @@ def get_known_future_tags(directory, annotation_regex, future_tag_regex, whiteli
return set(lines)


def git_supports_only_matching():
out = subprocess.check_output(["git", "--version"]).decode("utf-8")
# output looks like "git version 2.26.0"
git_version = pkg_resources.parse_version(out.split()[2])
# `git grep --only-matching` appeared in Git 2.19.0
# https://github.com/git/git/blob/v2.19.0/Documentation/RelNotes/2.19.0.txt#L41
minimal_version = pkg_resources.parse_version("2.19.0")
return git_version >= minimal_version


def get_all_futures(directory, future_tag_regex, whitelist):
"""Get all occurrences of FUTURE tags."""
# Old versions of Git (such as Git 2.1.4 that is shipped by Debian
# Jessie) do not support the `--only-matching` option. Pipe to
# `sed` instead.
if git_supports_only_matching():
grep = [
"git",
"grep",
"-I", # ignore binary files
"--line-number",
"--extended-regexp",
"--only-matching",
"-e",
future_tag_regex,
"--and",
"--not",
"-e",
IGNORE_PRAGMA,
]
grep.extend([f":(exclude){glob}" for glob in whitelist])
lines = commands.get_output(
grep,
cwd=directory,
valid_return_codes=(0, 1), # 0 if there are matches, 1 otherwise
)
else:
grep = [
"git",
"grep",
"-I", # ignore binary files
"--line-number",
"--extended-regexp",
"-e",
future_tag_regex,
"--and",
"--not",
"-e",
IGNORE_PRAGMA,
"--", # needed on old versions...
".", # ... of git
]
grep.extend([f":(exclude){glob}" for glob in whitelist])
sed = f'sed --regexp-extended "s/(.*?):.*?({future_tag_regex}).*?/\\1:\\2/g"'
lines = commands.get_pipe_command_output(
grep,
piped_to=sed,
cwd=directory,
valid_return_codes=(0, 1), # 0 if there are matches, 1 otherwise
)
grep = [
"git",
"grep",
"-I", # ignore binary files
"--line-number",
"--extended-regexp",
"--only-matching",
"-e",
future_tag_regex,
"--and",
"--not",
"-e",
IGNORE_PRAGMA,
]
grep.extend([f":(exclude){glob}" for glob in whitelist])
lines = commands.get_output(
grep,
cwd=directory,
valid_return_codes=(0, 1), # 0 if there are matches, 1 otherwise
)

occurrences = collections.defaultdict(list)
for line in lines:
Expand Down
17 changes: 17 additions & 0 deletions src/check_oldies/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import pathlib


__all__ = ["StrEnum"]
Expand Down Expand Up @@ -36,3 +37,19 @@ def __new__(cls, *values):
def _generate_next_value_(name, start, count, last_values):
return name.lower()
# fmt: on


try:
import tomllib

def load_toml(path: pathlib.Path) -> dict:
with open(path, "rb") as fp:
return tomllib.load(fp)
except ImportError: # Python < 3.11
try:
import toml

def load_toml(path: pathlib.Path) -> dict:
return toml.load(path)
except ImportError:
load_toml = None
Loading