From 82e03978b89938219958032efb1448cc76baa181 Mon Sep 17 00:00:00 2001 From: Saumit Date: Sat, 27 Sep 2025 02:14:26 +0530 Subject: Initial snapshot - OpenTelemetry demo 2.1.3 -f --- internal/tools/go.mod | 5 +++ internal/tools/go.sum | 2 + internal/tools/sanitycheck.py | 93 +++++++++++++++++++++++++++++++++++++++++++ internal/tools/tools.go | 15 +++++++ 4 files changed, 115 insertions(+) create mode 100644 internal/tools/go.mod create mode 100644 internal/tools/go.sum create mode 100644 internal/tools/sanitycheck.py create mode 100644 internal/tools/tools.go (limited to 'internal') diff --git a/internal/tools/go.mod b/internal/tools/go.mod new file mode 100644 index 0000000..aeac23a --- /dev/null +++ b/internal/tools/go.mod @@ -0,0 +1,5 @@ +module github.com/open-telemetry/opentelemetry-specification/internal/tools + +go 1.12 + +require github.com/client9/misspell v0.3.4 diff --git a/internal/tools/go.sum b/internal/tools/go.sum new file mode 100644 index 0000000..ee59480 --- /dev/null +++ b/internal/tools/go.sum @@ -0,0 +1,2 @@ +github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= diff --git a/internal/tools/sanitycheck.py b/internal/tools/sanitycheck.py new file mode 100644 index 0000000..f02da3d --- /dev/null +++ b/internal/tools/sanitycheck.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 + + + +import glob +import os +import sys + +CR = b'\r' +CRLF = b'\r\n' +LF = b'\n' + +def sanitycheck(pattern, allow_utf8 = False, allow_eol = (CRLF, LF), indent = 1): + error_count = 0 + + for filename in glob.glob(pattern, recursive=True): + if not os.path.isfile(filename): + continue + with open(filename, 'rb') as file: + content = file.read() + error = [] + eol = None + lineno = 1 + if not content: + error.append(' Empty file found') + elif content[-1] != 10: # LF + error.append(' Missing a blank line before EOF') + for line in content.splitlines(True): + if allow_utf8 and lineno == 1 and line.startswith(b'\xef\xbb\xbf'): + line = line[3:] + if any(b == 7 for b in line): + error.append(' TAB found at Ln:{} {}'.format(lineno, line)) + if any(b > 127 for b in line): + error.append(' Non-ASCII character found at Ln:{} {}'.format(lineno, line)) + if line[-2:] == CRLF: + if not eol: + eol = CRLF + elif eol != CRLF: + error.append(' Inconsistent line ending found at Ln:{} {}'.format(lineno, line)) + line = line[:-2] + elif line[-1:] == LF: + if not eol: + eol = LF + elif eol != LF: + error.append(' Inconsistent line ending found at Ln:{} {}'.format(lineno, line)) + line = line[:-1] + elif line[-1:] == CR: + error.append(' CR found at Ln:{} {}'.format(lineno, line)) + line = line[:-1] + if eol: + if eol not in allow_eol: + error.append(' Line ending {} not allowed at Ln:{}'.format(eol, lineno)) + break + if line.startswith(b' '): + spc_count = 0 + for c in line: + if c != 32: + break + spc_count += 1 + if not indent or (spc_count % indent and os.path.basename(filename) != 'rebar.config'): + error.append(' {} SPC found at Ln:{} {}'.format(spc_count, lineno, line)) + if line[-1:] == b' ' or line[-1:] == b'\t': + error.append(' Trailing space found at Ln:{} {}'.format(lineno, line)) + lineno += 1 + if error: + error_count += 1 + print('{} [FAIL]'.format(filename), file=sys.stderr) + for msg in error: + print(msg, file=sys.stderr) + else: + # print('{} [PASS]'.format(filename)) + pass + + return error_count + +retval = 0 +retval += sanitycheck('**/Dockerfile', allow_eol = (LF,), indent = 2) +retval += sanitycheck('**/*.cmd', allow_eol = (CRLF,), indent = 2) +retval += sanitycheck('**/*.config', allow_eol = (LF,), indent = 2) +retval += sanitycheck('**/*.cs', allow_eol = (LF,)) +retval += sanitycheck('**/*.csproj', allow_eol = (LF,), indent = 2) +retval += sanitycheck('**/*.htm', allow_eol = (LF,), indent = 4) +retval += sanitycheck('**/*.html', allow_eol = (LF,), indent = 4) +retval += sanitycheck('**/*.md', allow_eol = (LF,)) +retval += sanitycheck('**/*.proj', allow_eol = (LF,), indent = 2) +retval += sanitycheck('**/*.props', allow_eol = (LF,), indent = 2) +retval += sanitycheck('**/[!demo_pb2]*.py', allow_eol = (LF,), indent = 4) +retval += sanitycheck('**/*.sln', allow_utf8 = True, indent = 4) +retval += sanitycheck('**/*.targets', allow_eol = (LF,), indent = 2) +retval += sanitycheck('**/*.xml', allow_eol = (LF,), indent = 2) +retval += sanitycheck('**/*.yml', allow_eol = (LF,), indent = 2) + +sys.exit(retval) diff --git a/internal/tools/tools.go b/internal/tools/tools.go new file mode 100644 index 0000000..ef72fbe --- /dev/null +++ b/internal/tools/tools.go @@ -0,0 +1,15 @@ +// + +//go:build tools +// +build tools + +package tools + +// This file follows the recommendation at +// https://go.dev/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module +// on how to pin tooling dependencies to a go.mod file. +// This ensures that all systems use the same version of tools in addition to regular dependencies. + +import ( + _ "github.com/client9/misspell/cmd/misspell" +) -- cgit v1.2.3