Skip to content

Commit

Permalink
feat: ready for packaging and distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
lljbash committed Sep 3, 2024
1 parent c827cc0 commit 2b33e07
Show file tree
Hide file tree
Showing 16 changed files with 110 additions and 26 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/conventional_commit_checker.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
pr-title-regex: '^((build|ci|chore|docs|feat|fix|perf|refactor|revert|style|test)!?(\([a-z0-9-]+\))?: .+)$'
pr-body-regex: '^((?!null)|null.*)\S'
15 changes: 15 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Packages
/clangd_tidy/_version.py

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
4 changes: 4 additions & 0 deletions clangd_tidy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .main_cli import main_cli
from .version import __version__

__all__ = ["main_cli", "__version__"]
3 changes: 3 additions & 0 deletions clangd_tidy/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .main_cli import main_cli

main_cli()
File renamed without changes.
32 changes: 17 additions & 15 deletions clangd-tidy → clangd_tidy/main_cli.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand All @@ -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,
)
Expand Down
1 change: 1 addition & 0 deletions pylspclient/LICENSE → clangd_tidy/pylspclient/LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions clangd_tidy/pylspclient/__init__.py
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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: "
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pylspclient import lsp_structs
from . import lsp_structs

class LspClient(object):
def __init__(self, lsp_endpoint):
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions clangd_tidy/version.py
Original file line number Diff line number Diff line change
@@ -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__"]
8 changes: 0 additions & 8 deletions pylspclient/__init__.py

This file was deleted.

29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools>=64", "setuptools-scm>=8"]
build-backend = "setuptools.build_meta"

[project]
name = "clangd-tidy"
dynamic = ["version"]
authors = [{name="lljbash", email="[email protected]" }]
description = "A faster alternative to clang-tidy"
readme = "README.md"
dependencies = ["tqdm"]
requires-python = ">=3.8"
keywords = ["clang-tidy", "clangd", "static-analysis", "cpp"]

[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"
# write_to_template = "__version__ = '{version}'\n"

[tool.black]
include = '\.pyi?$'
extend-exclude = 'pylspclient'
required-version = "24"

0 comments on commit 2b33e07

Please sign in to comment.