Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ jobs:
run: python -m pytest -v --cov=cmake_pc_hooks --cov-report=xml --cov-report=term-missing --cov-branch

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Save coverage report
if: matrix.python == '3.11' && runner.os == 'Linux'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.xml
Expand Down Expand Up @@ -192,12 +192,12 @@ jobs:
fetch-depth: 0

- name: Fetch coverage report
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: coverage

- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand All @@ -208,7 +208,7 @@ jobs:
needs: unit-tests
steps:
- name: Fetch coverage report
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: coverage

Expand Down
17 changes: 8 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -25,46 +25,45 @@ repos:
- id: remove-tabs

- repo: https://github.com/PyCQA/doc8/
rev: v1.1.1
rev: v2.0.0
hooks:
- id: doc8
require_serial: false
additional_dependencies: [tomli]

- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
files: .*\.(py|txt|cmake|md|rst|sh|ps1|hpp|tpp|cpp|cc)$
args: [-I, .codespell.allow]

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
rev: v0.11.0.1
hooks:
- id: shellcheck
require_serial: false
args: [-x, --severity=info]

- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
rev: v1.37.1
hooks:
- id: yamllint

- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
rev: 1.19.1
hooks:
- id: blacken-docs
args: [-S, -l, '120']
additional_dependencies: [black==22.12.0]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.7
rev: v0.12.9
hooks:
- id: ruff-format
name: ruff (format)
args: [--preview]

- id: ruff
- id: ruff-check
name: ruff (fix)
alias: ruff-fix
args:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Repository

- Clarify where to put the settings in `pyproject.toml`
- Update GitHub Action `actions/download-artifact` to v4
- Update GitHub Action `actions/upload-artifact` to v4
- Update GitHub Action `codecov/codecov-action` from v4 to v5
- Use GitHub Action `SonarSource/sonarqube-scan-action` v5
- Update `github.com/pre-commit/pre-commit-hooks` hook to v6.0.0
- Update `https://github.com/PyCQA/doc8/` hook to v2.0.0
- Update `github.com/codespell-project/codespell` hook to v2.4.1
- Update `github.com/shellcheck-py/shellcheck-py` hook to v0.11.0.1
- Update `github.com/adrienverge/yamllint.git` hook to v1.37.1
- Update `github.com/asottile/blacken-docs` hook to 1.19.1
- Update `github.com/astral-sh/ruff-pre-commit` hook to v0.12.9

## [v1.9.6] - 2024-06-02

Expand Down
43 changes: 28 additions & 15 deletions cmake_pc_hooks/_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

import toml

log = logging.getLogger(__name__)

# ==============================================================================


Expand Down Expand Up @@ -110,7 +112,11 @@ def executable_path(path: str) -> Path:


def _load_data_from_toml(
path: Path, section: str, *, path_must_exist: bool = True, section_must_exist: bool = True
path: Path,
section: str,
*,
path_must_exist: bool = True,
section_must_exist: bool = True,
) -> dict:
"""
Load a TOML file and return the corresponding config dictionary.
Expand All @@ -127,23 +133,23 @@ def _load_data_from_toml(
section_must_exist: Whether a missing section in the TOML file is considered an error or not
"""
try:
with path.open(mode='r') as fd:
with path.open(mode='r', encoding='utf-8') as fd:
config = toml.load(fd)
if section:
for sub_section in section.split('.'):
config = config[sub_section]
logging.debug('Loading data from %s table of %s', section, path)
log.debug('Loading data from %s table of %s', section, path)
else:
config = {key: value for key, value in config.items() if not isinstance(value, dict)}
logging.debug('Loading data from root table of %s', path)
log.debug('Loading data from root table of %s', path)
except FileNotFoundError as err:
if path_must_exist:
raise TOMLFileNotFoundError(path) from err
logging.debug('TOML file %s does not exist (not an error)', str(path))
log.debug('TOML file %s does not exist (not an error)', str(path))
except KeyError as err:
if section_must_exist:
raise TOMLSectionKeyError(section, path) from err
logging.debug('TOML file %s does not have a %s section (not an error)', str(path), section)
log.debug('TOML file %s does not have a %s section (not an error)', str(path), section)
else:
return config
return {}
Expand Down Expand Up @@ -245,7 +251,9 @@ def parse_known_args(

if self._default_config_name is not None:
namespace = self._load_from_toml(
namespace=namespace, path=Path(self._default_config_name), path_must_exist=False
namespace=namespace,
path=Path(self._default_config_name),
path_must_exist=False,
)

namespace, args = super().parse_known_args(args=args, namespace=namespace)
Expand All @@ -265,11 +273,13 @@ def parse_known_args(
if namespace.dump_toml:
exclude_keys = {'positionals', 'dump_toml'}
print(
toml.dumps({
key: value
for key, value in vars(namespace).items()
if value != self._default_args[key] and key not in exclude_keys
})
toml.dumps(
{
key: value
for key, value in vars(namespace).items()
if value != self._default_args[key] and key not in exclude_keys
}
)
)
sys.exit(0)

Expand Down Expand Up @@ -297,7 +307,10 @@ def _load_from_toml( # noqa: PLR0913
overridable_keys: List of keys that can be overridden by values in the TOML file
"""
config = _load_data_from_toml(
path, section, path_must_exist=path_must_exist, section_must_exist=section_must_exist
path,
section,
path_must_exist=path_must_exist,
section_must_exist=section_must_exist,
)

for key, value in config.items():
Expand All @@ -309,9 +322,9 @@ def _load_from_toml( # noqa: PLR0913
if default_value is not None and not isinstance(value, type(default_value)):
raise TOMLTypeError(type(value), type(default_value), key)
if overridable_keys is not None and key not in overridable_keys:
logging.debug(' skipping non-overridable key: "%s"', key)
log.debug(' skipping non-overridable key: "%s"', key)
continue

logging.debug(' setting %s = %s', key, value)
log.debug(' setting %s = %s', key, value)
setattr(namespace, key, value)
return namespace
8 changes: 5 additions & 3 deletions cmake_pc_hooks/_call_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import attrs

log = logging.getLogger(__name__)


@attrs.define(slots=True)
class History: # pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -64,9 +66,9 @@ def call_process(args: list, **kwargs: any) -> History:
else:
ret = History(sp_child.stdout.decode(), sp_child.stderr.decode(), sp_child.returncode)

logging.debug('command `%s` exited with %d', ' '.join(args), ret.returncode)
log.debug('command `%s` exited with %d', ' '.join(args), ret.returncode)
for line in ret.stdout.split('\n'):
logging.debug('(stdout) %s', line)
log.debug('(stdout) %s', line)
for line in ret.stderr.split('\n'):
logging.debug('(stderr) %s', line)
log.debug('(stderr) %s', line)
return ret
Loading