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

refactor test #2

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
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
30 changes: 22 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,43 @@ concurrency:
jobs:
build-test:
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
PYTHONIOENCODING: utf-8
PIP_DOWNLOAD_CACHE: ${{ github.workspace }}/../.pip_download_cache
strategy:
matrix:
# Python 3.8 is the last non-EOL version. Also adapt tox.ini
python-version: ['3.8', 'pypy3.10', '3.12']
os: [ubuntu-latest, windows-latest]
fail-fast: false
matrix:
os: [macos-15, macos-latest, ubuntu-latest, ubuntu-22.04, ubuntu-24.04-arm, windows-latest, windows-2025]
python-version: [3.9, '3.10', '3.11', '3.12', '3.13']

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
allow-prereleases: true
cache: 'pip'
cache-dependency-path: '**/test-requirements'
env:
SETUPTOOLS_USE_DISTUTILS: ${{ startsWith(matrix.os, 'macos') || matrix.os == 'ubuntu-24.04-arm' && matrix.python-version == '3.9' && 'stdlib' || 'local' }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[dev]
python -m pip install 'tox-gh-actions<4.0.0'
pip install tox tox-gh-actions

- name: Test with tox
run: tox
run: |
tox
env:
PLATFORM: ${{ matrix.os }}
117 changes: 117 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Release

on:
push:
# release on tag push
tags:
- '*'

jobs:
wheels:

runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
env:
PYTHONIOENCODING: utf-8
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [3.9, '3.10', '3.11', '3.12', '3.13']

steps:
- name: Set git crlf/eol
run: |
git config --global core.autocrlf false
git config --global core.eol lf

- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: 'pip'
cache-dependency-path: '**/test-requirements'
env:
SETUPTOOLS_USE_DISTUTILS: ${{ matrix.os == 'macos-latest' && matrix.python-version == '3.9' && 'stdlib' || 'local' }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel
pip install tox

- name: Build dist pkgs
run: |
tox -e build,check

- name: Upload artifacts
if: matrix.python-version == 3.9 && runner.os == 'Linux'
uses: actions/upload-artifact@v4
with:
name: packages
path: dist

create_release:
name: Create Release
needs: [wheels]
runs-on: ubuntu-22.04

steps:
- name: Get version
id: get_version
run: |
echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
echo ${{ env.VERSION }}

- uses: actions/checkout@v4
with:
fetch-depth: 0

# download all artifacts to project dir
- uses: actions/download-artifact@v4

- name: Generate changes file
uses: sarnold/gitchangelog-action@915234f151ceffb7a8c4f76de77e4ae321087b8f # 1.1.1
with:
github_token: ${{ secrets.GITHUB_TOKEN}}

- name: Create release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
name: Release v${{ env.VERSION }}
body_path: CHANGES.md
draft: false
prerelease: false
files: |
packages/cpplint*

# When a GitHub release is made, upload the artifacts to PyPI
upload:
name: Upload to PyPI
runs-on: ubuntu-22.04
needs: [wheels]

steps:
- uses: actions/setup-python@v5

- uses: actions/download-artifact@v4

- name: check artifacts
run: find packages/ -maxdepth 2 -name cpplint-\* -type f

# - name: Publish bdist and sdist packages
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# password: ${{ secrets.PYPI_API_TOKEN }}
# packages_dir: packages/
# print_hash: true
6 changes: 1 addition & 5 deletions setup.cfg → .pytest.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
[aliases]
test = pytest

[tool:pytest]
[pytest]
python_files = *test.py
testpaths = .
required_plugins = pytest-cov pytest-timeout
timeout = 60
# fail if coverage is under 90%
addopts = --color=yes --cov-fail-under=90 --cov=cpplint
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog
Yet another overdue... hotfix. Sorry this took so long.

* The false positive for indented function parameters in namespaces was eradicated.
* build/include-what-you-use now recognizes c-style headers, such as <stdio.h> for symbols from <cstdio>. (https://github.com/cpplint/cpplint/pull/306)

2.0 (2024-10-06)
================
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Thanks for your interest in contributing to cpplint.
Any kinds of contributions are welcome: Bug reports, Documentation, Patches. However, here are some contributions you probably shouldn't make:

* Drastic reorganization
* Making the code conform to Google's Python style guidelines
* Making the code conform to Google's Python style guidelines
* Features that could be regarded as a security vulnerability

If you need some ideas, you may check out some of the tasks in our `issue tracker <https://github.com/cpplint/cpplint/issues>`_.
Expand All @@ -22,9 +22,9 @@ For many tasks, it is okay to just develop using a single installed python versi
1. (Optional) Install `pyenv <https://github.com/pyenv/pyenv-installer>`_ to manage python versions
2. (Optional) Using pyenv, install the python versions used in testing::

pyenv install 3.12.6
pyenv install 3.<version>
# ...
pyenv local 3.12.6 ...
pyenv local 3.<version> ...

It may be okay to run and test python against locally installed libraries, but if you need to have a consistent build, it is recommended to manage your environment using virtualenv: `virtualenv <https://virtualenv.pypa.io/en/latest/>`_, `virtualenvwrapper <https://pypi.org/project/virtualenvwrapper/>`_::

Expand Down
23 changes: 11 additions & 12 deletions cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,21 +1111,18 @@ def ProcessCategory(category):
error(filename, linenum, 'readability/nolint', 5,
f'Unknown NOLINT error category: {category}')

def ProcessGlobalSuppresions(lines):
"""Deprecated; use ProcessGlobalSuppressions."""
ProcessGlobalSuppressions(lines)

def ProcessGlobalSuppressions(lines):
def ProcessGlobalSuppressions(filename, lines):
"""Updates the list of global error suppressions.

Parses any lint directives in the file that have global effect.

Args:
filename: str, the name of the input file.
lines: An array of strings, each representing a line of the file, with the
last element being empty if the file is terminated with a newline.
"""
for line in lines:
if _SEARCH_C_FILE.search(line):
if _SEARCH_C_FILE.search(line) or filename.endswith(('.c', '.cu', '.C')):
for category in _DEFAULT_C_SUPPRESSED_CATEGORIES:
_error_suppressions.AddGlobalSuppression(category)
if _SEARCH_KERNEL_FILE.search(line):
Expand Down Expand Up @@ -6226,12 +6223,14 @@ def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error,
for item in sublist])

# All the lines have been processed, report the errors found.
for required_header_unstripped in sorted(required, key=required.__getitem__):
template = required[required_header_unstripped][1]
if required_header_unstripped.strip('<>"') not in include_dict:
error(filename, required[required_header_unstripped][0],
for header in sorted(required, key=required.__getitem__):
template = required[header][1]
if (header.strip('<>"') not in include_dict
and not (header.strip('<>"')[0] == 'c'
and (header.strip('<>"')[1:] + '.h') in include_dict)):
error(filename, required[header][0],
'build/include_what_you_use', 4,
'Add #include ' + required_header_unstripped + ' for ' + template)
'Add #include ' + header + ' for ' + template)


_RE_PATTERN_EXPLICIT_MAKEPAIR = re.compile(r'\bmake_pair\s*<')
Expand Down Expand Up @@ -6522,7 +6521,7 @@ def ProcessFileData(filename, file_extension, lines, error,
ResetNolintSuppressions()

CheckForCopyright(filename, lines, error)
ProcessGlobalSuppressions(lines)
ProcessGlobalSuppressions(filename, lines)
RemoveMultiLineComments(filename, lines, error)
clean_lines = CleansedLines(lines)

Expand Down
Loading
Loading