From 29e5bebbec7f5b819c5cfc7e98c2441a4e0e0b28 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 2 Apr 2026 12:44:25 +0200 Subject: [PATCH] Just: port python to new language test definition Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- misc/just/language_tests.py | 12 +++++++++++- python/justfile | 32 ++++++++++++++++++++++++++++++++ python/ql/justfile | 12 ++++++++++++ python/ql/test/justfile | 9 +++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 python/justfile create mode 100644 python/ql/justfile create mode 100644 python/ql/test/justfile diff --git a/misc/just/language_tests.py b/misc/just/language_tests.py index 4b9d12ab45e..e3a750a8fab 100644 --- a/misc/just/language_tests.py +++ b/misc/just/language_tests.py @@ -29,10 +29,20 @@ def main(): ] just = os.environ.get("JUST_EXECUTABLE", "just") + + # Find the nearest justfile at or above the first root + justfile_dir = Path(roots[0]) + while not (justfile_dir / "justfile").exists(): + parent = justfile_dir.parent + if parent == justfile_dir: + print(f"No justfile found above {roots[0]}", file=sys.stderr) + return 1 + justfile_dir = parent + invocation = [ just, "--justfile", - str(Path(roots[0]) / "justfile"), + str(justfile_dir / "justfile"), "test", "--all-checks", "--codeql=built", diff --git a/python/justfile b/python/justfile new file mode 100644 index 00000000000..3dfa9c30541 --- /dev/null +++ b/python/justfile @@ -0,0 +1,32 @@ +import '../lib.just' +import 'ql/justfile' + +[group('build')] +build: (_build_dist "python") + +# Long filename needed for extractor tests (too long for Git on Windows) +[no-cd] +@_ensure_long_filename: + #!/usr/bin/env bash + longfile="$SEMMLE_CODE/ql/python/ql/test/extractor-tests/long_path/really_rather_too_long_for_windows_path_length/with_unecessarily_longwinded_and_verbose_sub_folder/extremely_long_module_name_with_lots_of_digits_at_the_end_000000000000000000000000000000000000000000000000000000000000000000/test0000000000000000000000000000000000000000000000000000000.py" + mkdir -p "$(dirname "$longfile")" + touch "$longfile" + +[group('test')] +language-tests-2 *EXTRA_ARGS: _ensure_long_filename (_language_tests ( + _v2_env + ' ' + EXTRA_ARGS) source_dir() + 'ql/test/library-tests' + 'ql/test/query-tests' + 'ql/test/extractor-tests' + 'ql/test/experimental' + 'ql/test/2') + +[group('test')] +language-tests-3 *EXTRA_ARGS: _ensure_long_filename (_language_tests ( + _v3_env + ' ' + EXTRA_ARGS) source_dir() + 'ql/test/library-tests' + 'ql/test/query-tests' + 'ql/test/extractor-tests' + 'ql/test/experimental' + 'ql/test/modelling' + 'ql/test/3') diff --git a/python/ql/justfile b/python/ql/justfile new file mode 100644 index 00000000000..9279a49a374 --- /dev/null +++ b/python/ql/justfile @@ -0,0 +1,12 @@ +import "../../lib.just" + +[no-cd] +format *ARGS=".": (_format_ql ARGS) + +consistency_queries := source_dir() / "consistency-queries" + +python_version := "3" + +_v2_env := "CODEQL_EXTRACTOR_PYTHON_ANALYSIS_VERSION=2 CODEQL_PYTHON_LEGACY_TEST_EXTRACTION_VERSION=2" +_v3_env := "CODEQL_PYTHON_LEGACY_TEST_EXTRACTION_VERSION=3" +_python_env := if python_version == "2" { _v2_env } else { _v3_env } diff --git a/python/ql/test/justfile b/python/ql/test/justfile new file mode 100644 index 00000000000..eae85301f00 --- /dev/null +++ b/python/ql/test/justfile @@ -0,0 +1,9 @@ +import "../justfile" + +base_flags := _python_env + +all_checks := default_db_checks + """\ + --consistency-queries=""" + consistency_queries + +[no-cd] +test *ARGS=".": (_codeql_test "python" base_flags all_checks ARGS)