diff --git a/.github/actions/run-backend-tests/action.yml b/.github/actions/run-backend-tests/action.yml index 84a63487a7..c5cf1237bd 100644 --- a/.github/actions/run-backend-tests/action.yml +++ b/.github/actions/run-backend-tests/action.yml @@ -63,7 +63,7 @@ runs: id: hogql-parser-diff run: | git fetch --no-tags --prune --depth=1 origin master - changed=$(git diff --quiet HEAD origin/master -- hogql_parser/ && echo "false" || echo "true") + changed=$(git diff --quiet HEAD origin/master -- common/hogql_parser/ && echo "false" || echo "true") echo "changed=$changed" >> $GITHUB_OUTPUT - name: Install SAML (python3-saml) dependencies @@ -122,7 +122,7 @@ runs: sudo cp out/usr/local/lib/libantlr4-runtime.so* /usr/lib/ sudo ldconfig cd .. - uv pip install --system ./hogql_parser + uv pip install --system ./common/hogql_parser - name: Set up needed files shell: bash diff --git a/.github/workflows/build-hogql-parser.yml b/.github/workflows/build-hogql-parser.yml index 6667b165da..005b7d9fa5 100644 --- a/.github/workflows/build-hogql-parser.yml +++ b/.github/workflows/build-hogql-parser.yml @@ -3,7 +3,7 @@ name: Release hogql-parser on: pull_request: paths: - - hogql_parser/** + - common/hogql_parser/** - .github/workflows/build-hogql-parser.yml concurrency: @@ -21,14 +21,14 @@ jobs: with: fetch-depth: 0 # Fetching all for comparison since last push (not just last commit) - - name: Check if hogql_parser/ has changed + - name: Check if common/hogql_parser/ has changed id: changed-files uses: tj-actions/changed-files@v43 with: since_last_remote_commit: true files_yaml: | parser: - - hogql_parser/** + - common/hogql_parser/** - name: Check if version was bumped shell: bash @@ -37,7 +37,7 @@ jobs: parser_release_needed='false' if [[ ${{ steps.changed-files.outputs.parser_any_changed }} == 'true' ]]; then published=$(curl -fSsl https://pypi.org/pypi/hogql-parser/json | jq -r '.info.version') - local=$(python hogql_parser/setup.py --version) + local=$(python common/hogql_parser/setup.py --version) if [[ "$published" != "$local" ]]; then parser_release_needed='true' else @@ -86,13 +86,13 @@ jobs: - name: Build sdist if: matrix.os == 'ubuntu-22.04' # Only build the sdist once - run: cd hogql_parser && python setup.py sdist + run: cd common/hogql_parser && python setup.py sdist - name: Install cibuildwheel run: pip install cibuildwheel==2.16.* - name: Build wheels - run: cd hogql_parser && python -m cibuildwheel --output-dir dist + run: cd common/hogql_parser && python -m cibuildwheel --output-dir dist env: MACOSX_DEPLOYMENT_TARGET: '13' # A modern target allows us to use C++20 @@ -101,8 +101,8 @@ jobs: with: name: wheels-${{ matrix.os }} path: | - hogql_parser/dist/*.whl - hogql_parser/dist/*.tar.gz + common/hogql_parser/dist/*.whl + common/hogql_parser/dist/*.tar.gz if-no-files-found: error publish: @@ -142,7 +142,7 @@ jobs: - name: Update hogql-parser in requirements shell: bash run: | - local=$(python hogql_parser/setup.py --version) + local=$(python common/hogql_parser/setup.py --version) sed -i "s/hogql-parser==.*/hogql-parser==${local}/g" requirements.in sed -i "s/hogql-parser==.*/hogql-parser==${local}/g" requirements.txt diff --git a/.github/workflows/ci-hog.yml b/.github/workflows/ci-hog.yml index 53b7995ba5..89bed9a729 100644 --- a/.github/workflows/ci-hog.yml +++ b/.github/workflows/ci-hog.yml @@ -111,7 +111,7 @@ jobs: npm run grammar:build && git diff --exit-code env: # Installing a version of ANTLR compatible with what's in Homebrew as of August 2024 (version 4.13.2), - # as apt-get is quite out of date. The same version must be set in hogql_parser/pyproject.toml + # as apt-get is quite out of date. The same version must be set in common/hogql_parser/pyproject.toml ANTLR_VERSION: '4.13.2' - name: Check if STL bytecode is up to date diff --git a/hogql_parser/.clang-format b/common/hogql_parser/.clang-format similarity index 100% rename from hogql_parser/.clang-format rename to common/hogql_parser/.clang-format diff --git a/hogql_parser/.gitignore b/common/hogql_parser/.gitignore similarity index 100% rename from hogql_parser/.gitignore rename to common/hogql_parser/.gitignore diff --git a/hogql_parser/CONTRIBUTING.md b/common/hogql_parser/CONTRIBUTING.md similarity index 99% rename from hogql_parser/CONTRIBUTING.md rename to common/hogql_parser/CONTRIBUTING.md index 93248e78c3..a75ee2c650 100644 --- a/hogql_parser/CONTRIBUTING.md +++ b/common/hogql_parser/CONTRIBUTING.md @@ -55,7 +55,7 @@ The three pages below are must-reads though. They're key to writing production-r 1. Install `hogql_parser` by building from local sources: ```bash - pip install ./hogql_parser + pip install ./common/hogql_parser ``` > If you're getting compilation errors like this on macOS Sonoma: diff --git a/hogql_parser/HogQLLexer.cpp b/common/hogql_parser/HogQLLexer.cpp similarity index 100% rename from hogql_parser/HogQLLexer.cpp rename to common/hogql_parser/HogQLLexer.cpp diff --git a/hogql_parser/HogQLLexer.h b/common/hogql_parser/HogQLLexer.h similarity index 100% rename from hogql_parser/HogQLLexer.h rename to common/hogql_parser/HogQLLexer.h diff --git a/hogql_parser/HogQLLexer.interp b/common/hogql_parser/HogQLLexer.interp similarity index 100% rename from hogql_parser/HogQLLexer.interp rename to common/hogql_parser/HogQLLexer.interp diff --git a/hogql_parser/HogQLLexer.tokens b/common/hogql_parser/HogQLLexer.tokens similarity index 100% rename from hogql_parser/HogQLLexer.tokens rename to common/hogql_parser/HogQLLexer.tokens diff --git a/hogql_parser/HogQLParser.cpp b/common/hogql_parser/HogQLParser.cpp similarity index 100% rename from hogql_parser/HogQLParser.cpp rename to common/hogql_parser/HogQLParser.cpp diff --git a/hogql_parser/HogQLParser.h b/common/hogql_parser/HogQLParser.h similarity index 100% rename from hogql_parser/HogQLParser.h rename to common/hogql_parser/HogQLParser.h diff --git a/hogql_parser/HogQLParser.interp b/common/hogql_parser/HogQLParser.interp similarity index 100% rename from hogql_parser/HogQLParser.interp rename to common/hogql_parser/HogQLParser.interp diff --git a/hogql_parser/HogQLParser.tokens b/common/hogql_parser/HogQLParser.tokens similarity index 100% rename from hogql_parser/HogQLParser.tokens rename to common/hogql_parser/HogQLParser.tokens diff --git a/hogql_parser/HogQLParserBaseVisitor.cpp b/common/hogql_parser/HogQLParserBaseVisitor.cpp similarity index 100% rename from hogql_parser/HogQLParserBaseVisitor.cpp rename to common/hogql_parser/HogQLParserBaseVisitor.cpp diff --git a/hogql_parser/HogQLParserBaseVisitor.h b/common/hogql_parser/HogQLParserBaseVisitor.h similarity index 100% rename from hogql_parser/HogQLParserBaseVisitor.h rename to common/hogql_parser/HogQLParserBaseVisitor.h diff --git a/hogql_parser/HogQLParserVisitor.cpp b/common/hogql_parser/HogQLParserVisitor.cpp similarity index 100% rename from hogql_parser/HogQLParserVisitor.cpp rename to common/hogql_parser/HogQLParserVisitor.cpp diff --git a/hogql_parser/HogQLParserVisitor.h b/common/hogql_parser/HogQLParserVisitor.h similarity index 100% rename from hogql_parser/HogQLParserVisitor.h rename to common/hogql_parser/HogQLParserVisitor.h diff --git a/hogql_parser/README.md b/common/hogql_parser/README.md similarity index 100% rename from hogql_parser/README.md rename to common/hogql_parser/README.md diff --git a/hogql_parser/__init__.pyi b/common/hogql_parser/__init__.pyi similarity index 100% rename from hogql_parser/__init__.pyi rename to common/hogql_parser/__init__.pyi diff --git a/hogql_parser/error.cpp b/common/hogql_parser/error.cpp similarity index 100% rename from hogql_parser/error.cpp rename to common/hogql_parser/error.cpp diff --git a/hogql_parser/error.h b/common/hogql_parser/error.h similarity index 100% rename from hogql_parser/error.h rename to common/hogql_parser/error.h diff --git a/hogql_parser/parser.cpp b/common/hogql_parser/parser.cpp similarity index 100% rename from hogql_parser/parser.cpp rename to common/hogql_parser/parser.cpp diff --git a/hogql_parser/parser.h b/common/hogql_parser/parser.h similarity index 100% rename from hogql_parser/parser.h rename to common/hogql_parser/parser.h diff --git a/hogql_parser/py.typed b/common/hogql_parser/py.typed similarity index 100% rename from hogql_parser/py.typed rename to common/hogql_parser/py.typed diff --git a/hogql_parser/pyproject.toml b/common/hogql_parser/pyproject.toml similarity index 100% rename from hogql_parser/pyproject.toml rename to common/hogql_parser/pyproject.toml diff --git a/hogql_parser/setup.py b/common/hogql_parser/setup.py similarity index 98% rename from hogql_parser/setup.py rename to common/hogql_parser/setup.py index 53d2a8c9da..9db7837edd 100644 --- a/hogql_parser/setup.py +++ b/common/hogql_parser/setup.py @@ -32,7 +32,7 @@ module = Extension( setup( name="hogql_parser", - version="1.0.49", + version="1.0.50", url="https://github.com/PostHog/posthog/tree/master/hogql_parser", author="PostHog Inc.", author_email="hey@posthog.com", diff --git a/hogql_parser/string.cpp b/common/hogql_parser/string.cpp similarity index 100% rename from hogql_parser/string.cpp rename to common/hogql_parser/string.cpp diff --git a/hogql_parser/string.h b/common/hogql_parser/string.h similarity index 100% rename from hogql_parser/string.h rename to common/hogql_parser/string.h diff --git a/common/hogvm/typescript/src/execute.ts b/common/hogvm/typescript/src/execute.ts index bb2cd91230..bdb807b58e 100644 --- a/common/hogvm/typescript/src/execute.ts +++ b/common/hogvm/typescript/src/execute.ts @@ -282,7 +282,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions): if (!options?.external?.regex?.match) { throw new HogVMException('Set options.external.regex.match for RegEx support') } - return (regex: string, value: string): boolean => regex && value ? !!options.external?.regex?.match(regex, value) : false + return (regex: string, value: string): boolean => + regex && value ? !!options.external?.regex?.match(regex, value) : false } const logTelemetry = (): void => { @@ -306,7 +307,7 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions): frame.ip, typeof chunkBytecode[frame.ip] === 'number' ? String(chunkBytecode[frame.ip]) + - (operations[chunkBytecode[frame.ip]] ? `/${operations[chunkBytecode[frame.ip]]}` : '') + (operations[chunkBytecode[frame.ip]] ? `/${operations[chunkBytecode[frame.ip]]}` : '') : '???', debug, ]) @@ -316,18 +317,18 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions): const nextOp = options?.telemetry ? () => { - ops += 1 - logTelemetry() - if ((ops & 31) === 0) { - checkTimeout() - } - } + ops += 1 + logTelemetry() + if ((ops & 31) === 0) { + checkTimeout() + } + } : () => { - ops += 1 - if ((ops & 31) === 0) { - checkTimeout() - } - } + ops += 1 + if ((ops & 31) === 0) { + checkTimeout() + } + } try { while (true) { @@ -595,7 +596,7 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions): case Operation.TUPLE: temp = next() tempArray = spliceStack2(stack.length - temp, temp) - ; (tempArray as any).__isHogTuple = true + ;(tempArray as any).__isHogTuple = true pushStack(tempArray) break case Operation.JUMP: @@ -738,8 +739,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions): const args = version === 0 ? Array(temp) - .fill(null) - .map(() => popStack()) + .fill(null) + .map(() => popStack()) : stackKeepFirstElements(stack.length - temp) if (args.length !== 1) { throw new HogVMException(`Function ${name} requires exactly 1 argument`) @@ -771,8 +772,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions): const args = version === 0 ? Array(temp) - .fill(null) - .map(() => popStack()) + .fill(null) + .map(() => popStack()) : stackKeepFirstElements(stack.length - temp) pushStack(convertJSToHog(options.functions[name](...args.map((v) => convertHogToJS(v))))) } else if ( @@ -789,8 +790,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions): const args = version === 0 ? Array(temp) - .fill(null) - .map(() => popStack()) + .fill(null) + .map(() => popStack()) : stackKeepFirstElements(stack.length - temp) frame.ip += 1 // resume at the next address after async returns @@ -809,8 +810,8 @@ export function exec(input: any[] | VMState | Bytecodes, options?: ExecOptions): const args = version === 0 ? Array(temp) - .fill(null) - .map(() => popStack()) + .fill(null) + .map(() => popStack()) : stackKeepFirstElements(stack.length - temp) pushStack(STL[name].fn(args, name, options)) } else if (name in BYTECODE_STL) { diff --git a/common/hogvm/typescript/src/stl/crypto.ts b/common/hogvm/typescript/src/stl/crypto.ts index 3d9b1e92e4..33b5a5a64f 100644 --- a/common/hogvm/typescript/src/stl/crypto.ts +++ b/common/hogvm/typescript/src/stl/crypto.ts @@ -1,7 +1,9 @@ import { ExecOptions } from '../types' export function sha256Hex(data: string | null, options?: ExecOptions): string | null { - if (data === null) { return null } + if (data === null) { + return null + } const crypto = options?.external?.crypto if (!crypto) { throw new Error('The crypto module is required for "sha256Hex" to work.') @@ -10,7 +12,9 @@ export function sha256Hex(data: string | null, options?: ExecOptions): string | } export function md5Hex(data: string | null, options?: ExecOptions): string | null { - if (data === null) { return null } + if (data === null) { + return null + } const crypto = options?.external?.crypto if (!crypto) { throw new Error('The crypto module is required for "md5Hex" to work.') diff --git a/package.json b/package.json index b8f5d64180..48d4ebd552 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "schema:build:python": "bash bin/build-schema-python.sh", "grammar:build": "npm run grammar:build:python && npm run grammar:build:cpp", "grammar:build:python": "cd posthog/hogql/grammar && antlr -Dlanguage=Python3 HogQLLexer.g4 && antlr -visitor -no-listener -Dlanguage=Python3 HogQLParser.g4", - "grammar:build:cpp": "cd posthog/hogql/grammar && antlr -o ../../../hogql_parser -Dlanguage=Cpp HogQLLexer.g4 && antlr -o ../../../hogql_parser -visitor -no-listener -Dlanguage=Cpp HogQLParser.g4", + "grammar:build:cpp": "cd posthog/hogql/grammar && antlr -o ../../../common/hogql_parser -Dlanguage=Cpp HogQLLexer.g4 && antlr -o ../../../common/hogql_parser -visitor -no-listener -Dlanguage=Cpp HogQLParser.g4", "packages:build": "pnpm packages:build:lemon-ui", "packages:build:lemon-ui": "cd frontend/@posthog/lemon-ui && pnpm i && pnpm build", "editor:update-tsd": "pnpm packages:build && node frontend/editor-update-tsd.mjs", diff --git a/tach.toml b/tach.toml index e08881c44e..1ca28b1314 100644 --- a/tach.toml +++ b/tach.toml @@ -23,7 +23,7 @@ depends_on = [ ] [[modules]] -path = "hogql_parser" +path = "common.hogql_parser" depends_on = [] [[modules]] @@ -37,7 +37,7 @@ path = "posthog" depends_on = [ "", "ee", - "hogql_parser", + "common.hogql_parser", "common.hogvm.python", "products.early_access_features", ]