diff --git a/.github/workflows/conventional_commit_checker.yml b/.github/workflows/conventional_commit_checker.yml new file mode 100644 index 0000000..4ad87d3 --- /dev/null +++ b/.github/workflows/conventional_commit_checker.yml @@ -0,0 +1,16 @@ +name: Conventional Commit Checker + +on: + pull_request: + types: [opened, edited, synchronize] + +jobs: + check-for-cc: + runs-on: ubuntu-latest + steps: + - name: Conventional Commit Checker + id: conventional-commit-checker + uses: agenthunt/conventional-commit-checker-action@v2.0.0 + with: + pr-title-regex: '^((build|ci|chore|docs|feat|fix|perf|refactor|revert|style|test)!?(\([a-z0-9-]+\))?: .+)$' + pr-body-regex: '^((?!null)|null.*)\S' diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..e148eb8 --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,15 @@ +name: format + +on: + workflow_dispatch: + pull_request: + push: + +jobs: + python-black: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: psf/black@stable + with: # see: https://black.readthedocs.io/en/stable/integrations/github_actions.html + version: "~= 24.0" diff --git a/.gitignore b/.gitignore index 68bc17f..43ac716 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# Packages +/clangd_tidy/_dist_ver.py + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/README.md b/README.md index 7d5e81d..ca2183d 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,12 @@ Unfortunately, there seems to be no plan within LLVM to accelerate the standalon - Python 3.8+ (may work on older versions, but not tested) - [tqdm](https://github.com/tqdm/tqdm) (optional) +## Installation + +```bash +pip install clangd-tidy +``` + ## Usage ``` diff --git a/clangd_tidy/__init__.py b/clangd_tidy/__init__.py new file mode 100644 index 0000000..eb89611 --- /dev/null +++ b/clangd_tidy/__init__.py @@ -0,0 +1,4 @@ +from .main_cli import main_cli +from .version import __version__ + +__all__ = ["main_cli", "__version__"] diff --git a/clangd_tidy/__main__.py b/clangd_tidy/__main__.py new file mode 100644 index 0000000..eb27aa0 --- /dev/null +++ b/clangd_tidy/__main__.py @@ -0,0 +1,3 @@ +from .main_cli import main_cli + +main_cli() diff --git a/diagnostic_formatter.py b/clangd_tidy/diagnostic_formatter.py similarity index 100% rename from diagnostic_formatter.py rename to clangd_tidy/diagnostic_formatter.py diff --git a/clangd-tidy b/clangd_tidy/main_cli.py old mode 100755 new mode 100644 similarity index 93% rename from clangd-tidy rename to clangd_tidy/main_cli.py index 89c06c5..8bb95ff --- a/clangd-tidy +++ b/clangd_tidy/main_cli.py @@ -8,13 +8,19 @@ import threading from typing import IO, Set, TextIO -import diagnostic_formatter -from pylspclient.json_rpc_endpoint import JsonRpcEndpoint -from pylspclient.lsp_endpoint import LspEndpoint -from pylspclient.lsp_client import LspClient -from pylspclient.lsp_structs import TextDocumentItem, LANGUAGE_IDENTIFIER +from .diagnostic_formatter import ( + DiagnosticFormatter, + CompactDiagnosticFormatter, + FancyDiagnosticFormatter, + GithubActionWorkflowCommandDiagnosticFormatter, +) +from .pylspclient.json_rpc_endpoint import JsonRpcEndpoint +from .pylspclient.lsp_endpoint import LspEndpoint +from .pylspclient.lsp_client import LspClient +from .pylspclient.lsp_structs import TextDocumentItem, LANGUAGE_IDENTIFIER +from .version import __version__ -__version__ = "0.2.1" +__all__ = ["main_cli"] class ReadPipe(threading.Thread): @@ -105,13 +111,11 @@ def check_failed(self, fail_on_severity: str) -> bool: return True return False - def format_diagnostics( - self, formatter: diagnostic_formatter.DiagnosticFormatter - ) -> str: + def format_diagnostics(self, formatter: DiagnosticFormatter) -> str: return formatter.format(sorted(self.diagnostics.items())).rstrip() -if __name__ == "__main__": +def main_cli(): DEFAULT_ALLOW_EXTENSIONS = [ "c", "h", @@ -299,7 +303,7 @@ def format_diagnostics( read_pipe.join() formatter = ( - diagnostic_formatter.FancyDiagnosticFormatter( + FancyDiagnosticFormatter( extra_context=args.context, enable_color=( _is_output_supports_color(args.output) @@ -308,15 +312,13 @@ def format_diagnostics( ), ) if not args.compact - else diagnostic_formatter.CompactDiagnosticFormatter() + else CompactDiagnosticFormatter() ) print(collector.format_diagnostics(formatter), file=args.output) if args.github: print( collector.format_diagnostics( - diagnostic_formatter.GithubActionWorkflowCommandDiagnosticFormatter( - args.git_root - ) + GithubActionWorkflowCommandDiagnosticFormatter(args.git_root) ), file=args.output, ) diff --git a/pylspclient/LICENSE b/clangd_tidy/pylspclient/LICENSE similarity index 97% rename from pylspclient/LICENSE rename to clangd_tidy/pylspclient/LICENSE index 0728ddb..179d7b8 100644 --- a/pylspclient/LICENSE +++ b/clangd_tidy/pylspclient/LICENSE @@ -1,5 +1,6 @@ MIT License +Copyright (c) 2023 lljbash Copyright (c) 2018 Avi Yeger Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/clangd_tidy/pylspclient/__init__.py b/clangd_tidy/pylspclient/__init__.py new file mode 100644 index 0000000..a6a26af --- /dev/null +++ b/clangd_tidy/pylspclient/__init__.py @@ -0,0 +1,6 @@ +from .json_rpc_endpoint import JsonRpcEndpoint +from .lsp_client import LspClient +from .lsp_endpoint import LspEndpoint +from . import lsp_structs + +__all__ = ["JsonRpcEndpoint", "LspClient", "LspEndpoint", "lsp_structs"] diff --git a/pylspclient/json_rpc_endpoint.py b/clangd_tidy/pylspclient/json_rpc_endpoint.py similarity index 98% rename from pylspclient/json_rpc_endpoint.py rename to clangd_tidy/pylspclient/json_rpc_endpoint.py index 3b1c040..181607d 100644 --- a/pylspclient/json_rpc_endpoint.py +++ b/clangd_tidy/pylspclient/json_rpc_endpoint.py @@ -1,9 +1,10 @@ from __future__ import print_function import json import re -from pylspclient import lsp_structs import threading +from . import lsp_structs + JSON_RPC_REQ_FORMAT = "Content-Length: {json_string_len}\r\n\r\n{json_string}" LEN_HEADER = "Content-Length: " TYPE_HEADER = "Content-Type: " diff --git a/pylspclient/lsp_client.py b/clangd_tidy/pylspclient/lsp_client.py similarity index 99% rename from pylspclient/lsp_client.py rename to clangd_tidy/pylspclient/lsp_client.py index e7dce79..61221fb 100644 --- a/pylspclient/lsp_client.py +++ b/clangd_tidy/pylspclient/lsp_client.py @@ -1,4 +1,4 @@ -from pylspclient import lsp_structs +from . import lsp_structs class LspClient(object): def __init__(self, lsp_endpoint): diff --git a/pylspclient/lsp_endpoint.py b/clangd_tidy/pylspclient/lsp_endpoint.py similarity index 99% rename from pylspclient/lsp_endpoint.py rename to clangd_tidy/pylspclient/lsp_endpoint.py index 9774477..b4ad6ec 100644 --- a/pylspclient/lsp_endpoint.py +++ b/clangd_tidy/pylspclient/lsp_endpoint.py @@ -1,7 +1,8 @@ from __future__ import print_function import threading import collections -from pylspclient import lsp_structs + +from . import lsp_structs class LspEndpoint(threading.Thread): diff --git a/pylspclient/lsp_structs.py b/clangd_tidy/pylspclient/lsp_structs.py similarity index 100% rename from pylspclient/lsp_structs.py rename to clangd_tidy/pylspclient/lsp_structs.py diff --git a/clangd_tidy/version.py b/clangd_tidy/version.py new file mode 100644 index 0000000..44d3c54 --- /dev/null +++ b/clangd_tidy/version.py @@ -0,0 +1,11 @@ +try: + from ._dist_ver import __version__ # type: ignore +except ImportError: + try: + from setuptools_scm import get_version # type: ignore + + __version__ = get_version(root="..", relative_to=__file__) + except (ImportError, LookupError): + __version__ = "UNKNOWN" + +__all__ = ["__version__"] diff --git a/pylspclient/__init__.py b/pylspclient/__init__.py deleted file mode 100644 index 1cb55c7..0000000 --- a/pylspclient/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -#from __future__ import absolute_import - -__all__ = [] - -from pylspclient.json_rpc_endpoint import JsonRpcEndpoint -from pylspclient.lsp_client import LspClient -from pylspclient.lsp_endpoint import LspEndpoint -from pylspclient import lsp_structs diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..200fedd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,37 @@ +[build-system] +requires = ["setuptools>=64", "setuptools-scm>=8"] +build-backend = "setuptools.build_meta" + +[project] +name = "clangd-tidy" +dynamic = ["version"] +dependencies = ["tqdm"] +requires-python = ">=3.8" +authors = [{ name = "lljbash", email = "lljbash@gmail.com" }] +description = "A faster alternative to clang-tidy" +readme = "README.md" +keywords = ["clang-tidy", "clangd", "static-analysis", "cpp"] +classifiers = [ + "Development Status :: 4 - Beta", + "Environment :: Console", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: POSIX", + "Programming Language :: Python :: 3 :: Only", + "Topic :: Software Development :: Quality Assurance", +] + +[project.scripts] +clangd-tidy = "clangd_tidy:main_cli" + +[project.urls] +"Homepage" = "https://github.com/lljbash/clangd-tidy" +"Bug Tracker" = "https://github.com/lljbash/clangd-tidy/issues" + +[tool.setuptools_scm] +write_to = "clangd_tidy/_dist_ver.py" + +[tool.black] +include = '\.pyi?$' +extend-exclude = 'pylspclient' +required-version = "24"