feat: remove nulls function
This commit is contained in:
		
							parent
							
								
									2521d571fd
								
							
						
					
					
						commit
						c36977c3fa
					
				|  | @ -1,10 +1,19 @@ | ||||||
| from typing import Tuple | from typing import Any, Dict, Tuple | ||||||
| 
 | 
 | ||||||
| import rtoml | import rtoml | ||||||
| 
 | 
 | ||||||
| from joj3_config_generator.models import joj1, repo, result, task | from joj3_config_generator.models import joj1, repo, result, task | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def remove_nulls(d: Dict[str, Any]) -> Dict[str, Any]: | ||||||
|  |     if isinstance(d, dict): | ||||||
|  |         return {k: remove_nulls(v) for k, v in d.items() if v is not None} | ||||||
|  |     elif isinstance(d, list): | ||||||
|  |         return [remove_nulls(item) for item in d] | ||||||
|  |     else: | ||||||
|  |         return d | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def get_conf_stage( | def get_conf_stage( | ||||||
|     task_stage: task.Stage, executor_with_config: result.ExecutorWith |     task_stage: task.Stage, executor_with_config: result.ExecutorWith | ||||||
| ) -> result.StageDetail: | ) -> result.StageDetail: | ||||||
|  |  | ||||||
|  | @ -9,6 +9,7 @@ import yaml | ||||||
| 
 | 
 | ||||||
| from joj3_config_generator.convert import convert as convert_conf | from joj3_config_generator.convert import convert as convert_conf | ||||||
| from joj3_config_generator.convert import convert_joj1 as convert_joj1_conf | from joj3_config_generator.convert import convert_joj1 as convert_joj1_conf | ||||||
|  | from joj3_config_generator.lib.task import remove_nulls | ||||||
| from joj3_config_generator.models import joj1, repo, result, task | from joj3_config_generator.models import joj1, repo, result, task | ||||||
| from joj3_config_generator.utils.logger import logger | from joj3_config_generator.utils.logger import logger | ||||||
| 
 | 
 | ||||||
|  | @ -63,6 +64,7 @@ def convert(root: Path = Path(".")) -> result.Config: | ||||||
|     task_obj = rtoml.loads(task_toml) |     task_obj = rtoml.loads(task_toml) | ||||||
|     result_model = convert_conf(repo.Config(**repo_obj), task.Config(**task_obj)) |     result_model = convert_conf(repo.Config(**repo_obj), task.Config(**task_obj)) | ||||||
|     result_dict = result_model.model_dump(by_alias=True) |     result_dict = result_model.model_dump(by_alias=True) | ||||||
|  |     result_dict = remove_nulls(result_dict) | ||||||
| 
 | 
 | ||||||
|     with open(result_json_path, "w") as result_file: |     with open(result_json_path, "w") as result_file: | ||||||
|         json.dump(result_dict, result_file, ensure_ascii=False, indent=4) |         json.dump(result_dict, result_file, ensure_ascii=False, indent=4) | ||||||
|  |  | ||||||
|  | @ -6,5 +6,5 @@ sandbox_token = "test" | ||||||
| [files] | [files] | ||||||
| whitelist_patterns = ["*.py", "*.txt", "*.md"] | whitelist_patterns = ["*.py", "*.txt", "*.md"] | ||||||
| whitelist_file = ".whitelist" | whitelist_file = ".whitelist" | ||||||
| required = ["main.py", "README.md"] | required = [ "Changelog.md", "Readme.md" ] | ||||||
| immutable = [] | immutable = [".gitignore", ".gitattributes", ".gitea/workflows/push.yaml", ".gitea/workflows/release.yaml" ] | ||||||
|  |  | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							|  | @ -1,22 +1,31 @@ | ||||||
| # general task configuration | # p2 repo config | ||||||
| task="Homework 1 exercise 2" # task name | 
 | ||||||
|  | task="p2 m3" # task name | ||||||
| 
 | 
 | ||||||
| release.deadline = 2024-10-12 23:59:00+08:00 | release.deadline = 2024-10-12 23:59:00+08:00 | ||||||
| release.stages = [ "compile" ] | release.stages = [ "compile" ] | ||||||
| 
 | 
 | ||||||
|  | [files] | ||||||
|  | immutable = [".gitignore", ".gitattributes", ".gitea/workflows/push.yaml", ".gitea/workflows/release.yaml" ] | ||||||
|  | required = [ "Changelog.md", "Readme.md" ] | ||||||
|  | 
 | ||||||
|  | [[stages]] | ||||||
|  | name = "Abuse of strings detected" | ||||||
|  | command = "./strdetect src/" | ||||||
|  | files.import = [ "tools/strdetec" ] | ||||||
|  | 
 | ||||||
|  | parsers = [ "result-status" ] | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
| name = "Compilation" | name = "Compilation" | ||||||
| command = "make.sh" # eg. script running cmake commands | command = "compile" | ||||||
| files.import = [ "tools/make.sh", "src/main.c", "src/task.h", "srcCMakelist.txt" ] | files.import = [ "tools/compile" ] | ||||||
| files.export = [ "driver", "p2", "p2-msan" ] | files.export = [ "build/onecard", "build/asan", "build/ubsan", "build/msan", "build/compile_commands.json" ] | ||||||
| limit.cpu = 180 # p2 takes long to compile |  | ||||||
| limit.stderr = 128 |  | ||||||
| 
 | 
 | ||||||
| # compile parsers |  | ||||||
| parsers = [ "result-detail", "dummy", "result-status" ] | parsers = [ "result-detail", "dummy", "result-status" ] | ||||||
| result-status.comment = "Congratulations! Your code compiled successfully." | result-status.comment = "Congratulations! Your code compiled successfully." | ||||||
| result-status.score = 1 | result-status.score = 1 | ||||||
| result-status.forcequit = false |  | ||||||
| dummy.comment = "\n\n### Details\n" | dummy.comment = "\n\n### Details\n" | ||||||
| result-detail.exitstatus = true | result-detail.exitstatus = true | ||||||
| result-detail.stderr = true | result-detail.stderr = true | ||||||
|  | @ -24,29 +33,13 @@ result-detail.time = false | ||||||
| result-detail.mem = false | result-detail.mem = false | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
| name = "File length check" | name = "[cq] Filelength" | ||||||
| command = "./file-length 500 400 *.c *.h"  # command to run | command = "./file-length 400 300 *.c *.h" | ||||||
| files.import = [ "tools/file-length" ] | files.import = [ "tools/filelength" ] | ||||||
| 
 | 
 | ||||||
| parsers = [ "keyword", "dummy", "result-detail" ] | parsers = [ "keyword", "dummy", "result-detail" ] | ||||||
| keyword.keyword = [ "max", "recommend"] # keywords caught by corresponding JOJ plugin | keyword.keyword = [ "max", "recommended"] | ||||||
| keyword.weight = [ 50, 20 ] # weight of each keyword | keyword.weight = [ 20, 10 ] | ||||||
| result-detail.exitstatus = true |  | ||||||
| result-detail.stderr = true |  | ||||||
| result-detail.time = false |  | ||||||
| result-detail.mem = false |  | ||||||
| result-status.comment = "Manuel Charlemagne" |  | ||||||
| result-status.score = 10000 |  | ||||||
| result-status.forcequit = true |  | ||||||
| 
 |  | ||||||
| [[stages]] |  | ||||||
| name = "Clang-tidy checks" |  | ||||||
| command = "run-clang-tidy-18 -header-filter=.* -quiet -load=/usr/local/lib/libcodequality.so -p build" |  | ||||||
| limit.stdout = 65 |  | ||||||
| 
 |  | ||||||
| parsers = [ "clangtidy", "dummy", "result-detail" ] |  | ||||||
| clangtidy.keyword = [ "codequality-no-global-variables", "codequality-no-header-guard", "readability-function-size", "readability-duplicate-include", "readability-identifier-naming", "readability-redundant", "readability-misleading-indentation", "readability-misplaced-array-index", "cppcoreguidelines-init-variables", "bugprone-suspicious-string-compare", "google-global-names-in-headers", "clang-diagnostic", "clang-analyzer", "misc performance" ] |  | ||||||
| clangtidy.weight = [10, 10, 50, 10, 5, 5, 10, 5, 5, 8, 5, 5, 5, 5] |  | ||||||
| dummy.comment = "\n\n### Details\n" | dummy.comment = "\n\n### Details\n" | ||||||
| result-detail.exitstatus = true | result-detail.exitstatus = true | ||||||
| result-detail.stdout = true | result-detail.stdout = true | ||||||
|  | @ -54,13 +47,28 @@ result-detail.time = false | ||||||
| result-detail.mem = false | result-detail.mem = false | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
| name = "Cppcheck check" | name = "[cq] Clang-tidy" | ||||||
| command = "cppcheck --template='{\"file\":\"{file}\",\"line\":{line}, \"column\":{column}, \"severity\":\"{severity}\", \"message\":\"{message}\", \"id\":\"{id}\"}' --force --enable=all --quiet ./" | command = "run-clang-tidy-18 -header-filter=.* -quiet -load=/usr/local/lib/libcodequality.so -p build" | ||||||
|  | files.import = [ "projects/p2/.clang-tidy", "build/compile_commands.json" ] | ||||||
|  | limit.stdout = 65 | ||||||
|  | 
 | ||||||
|  | parsers = [ "clangtidy", "dummy", "result-detail" ] | ||||||
|  | clangtidy.keyword = [ "codequality-unchecked-malloc-result", "codequality-no-global-variables", "codequality-no-header-guard", "codequality-no-fflush-stdin", "readability-function-size", "readability-duplicate-include", "readability-identifier-naming", "readability-redundant", "readability-misleading-indentation", "readability-misplaced-array-index", "cppcoreguidelines-init-variables", "bugprone-suspicious-string-compare", "google-global-names-in-headers", "clang-diagnostic", "clang-analyzer", "misc", "performance", "portability" ] | ||||||
|  | clangtidy.weight = [ 5, 20, 20, 20, 10, 5, 5, 5, 15, 5, 5, 5, 5, 5, 5, 5, 5, 5] | ||||||
|  | dummy.comment = "\n\n### Details\n" | ||||||
|  | result-detail.exitstatus = true | ||||||
|  | result-detail.stdout = true | ||||||
|  | result-detail.time = false | ||||||
|  | result-detail.mem = false | ||||||
|  | 
 | ||||||
|  | [[stages]] | ||||||
|  | name = "[cq] Cppcheck" | ||||||
|  | command = "cppcheck --template='{\"file\":\"{file}\",\"line\":{line}, \"column\":{column}, \"severity\":\"{severity}\", \"message\":\"{message}\", \"id\":\"{id}\"}' --force --enable=all --suppress=missingIncludeSystem  --quiet ./" | ||||||
| limit.stderr = 65 | limit.stderr = 65 | ||||||
| 
 | 
 | ||||||
| parsers = [ "cppcheck", "dummy", "result-detail" ] | parsers = [ "cppcheck", "dummy", "result-detail" ] | ||||||
| cppcheck.keyword = ["error", "warning", "portability", "performance", "style"] | cppcheck.keyword = ["error", "warning", "portability", "performance", "style"] | ||||||
| cppcheck.weight = [20, 10, 15, 15, 10] | cppcheck.weight = [15, 5, 5, 5, 5] | ||||||
| dummy.comment = "\n\n### Details\n" | dummy.comment = "\n\n### Details\n" | ||||||
| result-detail.exitstatus = true | result-detail.exitstatus = true | ||||||
| result-detail.stderr = true | result-detail.stderr = true | ||||||
|  | @ -68,57 +76,62 @@ result-detail.time = false | ||||||
| result-detail.mem = false | result-detail.mem = false | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
| name = "Cpplint check" | name = "[cq] Cpplint" | ||||||
| command = "cpplint --linelength=120 --filter=-legal,-readability/casting,-whitespace,-runtime/printf,-runtime/threadsafe_fn,-readability/todo,-build/include_subdir,-build/header_guard --recursive --exclude=build ." | command = "cpplint --linelength=120 --filter=-legal,-readability/casting,-whitespace,-runtime/printf,-runtime/threadsafe_fn,-readability/todo,-build/include_subdir,-build/header_guard --recursive --exclude=build ." | ||||||
| limit.stdout = 65 | limit.stdout = 65 | ||||||
| 
 | 
 | ||||||
| parsers = [ "cpplint", "dummy", "result-detail" ] | parsers = [ "cpplint", "dummy", "result-detail" ] | ||||||
| cpplint.keyword = [ "runtime", "readability", "build" ] | cpplint.keyword = [ "runtime", "readability", "build" ] | ||||||
| cpplint.weight = [ 10, 20, 15] | cpplint.weight = [ 5, 20, 10] | ||||||
| dummy.comment = "\n\n### Details\n" | dummy.comment = "\n\n### Details\n" | ||||||
| result-detail.exitstatus = true | result-detail.exitstatus = true | ||||||
| result-detail.stdout = true | result-detail.stderr = true | ||||||
| result-detail.time = false | result-detail.time = false | ||||||
| result-detail.mem = false | result-detail.mem = false | ||||||
| 
 | 
 | ||||||
| [[stages]] | [[stages]] | ||||||
| name = "judge-base" | name = "[run] onecard" | ||||||
| command="./driver ./mumsh" | group = "run" | ||||||
| limit.cpu = 3 | command="./onecard -a" | ||||||
| limit.mem = 75 | files.import = [ "build/onecard" ] | ||||||
| score = 10 |  | ||||||
| 
 | 
 | ||||||
| parsers = ["diff", "dummy", "result-detail"] | parsers = [ "result-status", "result-detail" ] | ||||||
| dummy.comment = "\n\n### Details\n" | result-status.score = 1 | ||||||
|  | result-status.forcequit = false | ||||||
| result-detail.exitstatus = true | result-detail.exitstatus = true | ||||||
| result-detail.stderr = true | result-detail.stderr = true | ||||||
| 
 | 
 | ||||||
| case4.score = 15 |  | ||||||
| case4.limit.cpu = 30 |  | ||||||
| case4.limit.mem = 10 |  | ||||||
| case4.limit.stdout = 8 |  | ||||||
| 
 |  | ||||||
| case5.score = 25 |  | ||||||
| 
 |  | ||||||
| case8.limit.stderr = 128 |  | ||||||
| 
 |  | ||||||
| [[stages]] | [[stages]] | ||||||
| name = "judge-msan" | name = "[run] address sanitizer" | ||||||
| command="./driver ./mumsh-msan" | group = "run" | ||||||
| limit.cpu = 10 # default cpu limit (in sec) for each test case | command="./asan -a" | ||||||
| limit.mem = 500 # set default mem limit (in MB) for all OJ test cases | files.import = [ "build/asan" ] | ||||||
| score = 10 |  | ||||||
| skip = ["case0", "case11"] |  | ||||||
| 
 | 
 | ||||||
| parsers = ["diff", "dummy", "result-detail"] | parsers = [ "result-status", "result-detail" ] | ||||||
| dummy.comment = "\n\n### Details\n" | result-status.score = 1 | ||||||
|  | result-status.forcequit = false | ||||||
| result-detail.exitstatus = true | result-detail.exitstatus = true | ||||||
| result-detail.stderr = true | result-detail.stderr = true | ||||||
| 
 | 
 | ||||||
| case4.score = 15 | [[stages]] | ||||||
| case4.limit.cpu = 30 | name = "[run] memory sanitizer" | ||||||
| case4.limit.mem = 10 | group = "run" | ||||||
|  | command="./msan -a" | ||||||
|  | files.import = [ "build/msan" ] | ||||||
| 
 | 
 | ||||||
| case5.diff.output.ignorespaces = false | parsers = [ "result-status", "result-detail" ] | ||||||
|  | result-status.score = 1 | ||||||
|  | result-status.forcequit = false | ||||||
|  | result-detail.exitstatus = true | ||||||
|  | result-detail.stderr = true | ||||||
| 
 | 
 | ||||||
| case6.diff.output.hide = true | [[stages]] | ||||||
|  | name = "[run] undefined behavior sanitizer" | ||||||
|  | command="./ubsan -a" | ||||||
|  | files.import = [ "build/ubsan" ] | ||||||
|  | 
 | ||||||
|  | parsers = [ "result-status", "result-detail" ] | ||||||
|  | result-status.score = 1 | ||||||
|  | result-status.forcequit = false | ||||||
|  | result-detail.exitstatus = true | ||||||
|  | result-detail.stderr = true | ||||||
|  |  | ||||||
|  | @ -3,5 +3,3 @@ from tests.convert.utils import load_case | ||||||
| 
 | 
 | ||||||
| def test_basic() -> None: | def test_basic() -> None: | ||||||
|     load_case("basic") |     load_case("basic") | ||||||
| 
 |  | ||||||
| test_basic() |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user