From 1f76ff58c757e14a4d035aa968dc1564b5b30e35 Mon Sep 17 00:00:00 2001 From: Austin Appleby Date: Thu, 24 Oct 2024 19:17:21 -0700 Subject: [PATCH] loaded_modules -> loaded_files so we don't have extra refs to the modules --- build.hancho | 4 ---- docs/README.md | 2 +- .../random_deps/build.hancho | 4 ++-- hancho.py | 6 ++--- tests/subrepo_tests/repo1/repo1_test1.hancho | 2 +- tutorial/tut00.hancho | 2 ++ tutorial/tut01.hancho | 2 ++ tutorial/tut02.hancho | 2 ++ tutorial/tut03.hancho | 2 ++ tutorial/tut04.hancho | 2 ++ tutorial/tut10.hancho | 6 ++--- tutorial/tut11.hancho | 22 +++++++++---------- tutorial/tut12.hancho | 10 ++++----- tutorial/tut13.hancho | 10 ++++----- tutorial/tut14.hancho | 10 ++++----- tutorial/tutorial.hancho | 10 ++++----- 16 files changed, 51 insertions(+), 45 deletions(-) diff --git a/build.hancho b/build.hancho index adad1a8..9f420e3 100644 --- a/build.hancho +++ b/build.hancho @@ -3,10 +3,6 @@ if 'base_rules' not in hancho: hancho.base_rules = hancho.load("base_rules.hancho") -#print(hancho) -#print(hancho.config) -#print(hancho.base_rules) - hancho.load("tutorial/tutorial.hancho") hancho.load("examples/examples.hancho") hancho.load("tests/tests.hancho") diff --git a/docs/README.md b/docs/README.md index b5aebd3..7fd3aad 100644 --- a/docs/README.md +++ b/docs/README.md @@ -84,7 +84,7 @@ main_app = link(in_objs = main_o, out_bin = "app") - ```jobs``` (Default: ```os.cpu_count()```) - The number of console commands Hancho will run in parallel. -# Helper methods defined in hancho.config: +# Helper methods defined in hancho.Config: - ```len([list])``` - Same as Python's ```len()``` diff --git a/examples/dynamic_dependencies/random_deps/build.hancho b/examples/dynamic_dependencies/random_deps/build.hancho index 90c55e1..e96fde3 100644 --- a/examples/dynamic_dependencies/random_deps/build.hancho +++ b/examples/dynamic_dependencies/random_deps/build.hancho @@ -5,14 +5,14 @@ import random """ all_deps = [f"src/text{d}.txt" for d in range(0, 9)] -hancho.task( +hancho.Task( command = "touch {build_files}", source_files = [], build_files = random.sample(all_deps, 3), build_path = hancho.source_path, ) -hancho.task( +hancho.Task( command = "cat {rel_source_files} > {rel_build_files}", source_files = random.sample(all_deps, 3), build_files = "result.txt", diff --git a/hancho.py b/hancho.py index 269cbff..f910976 100755 --- a/hancho.py +++ b/hancho.py @@ -674,7 +674,7 @@ def __init__(self, *args, **kwargs): self._state = TaskState.DECLARED self._reason = None self._promise = None - self._loaded_files = [m.hancho.config.mod_path for m in app.loaded_modules] + self._loaded_files = list(app.loaded_files) self._stdout = "" self._stderr = "" self._returncode = -1 @@ -1128,7 +1128,7 @@ def _load_module(self): log(color(128,255,128) + f"Loading {self.config.mod_path}" + color()) temp_module = Module(hancho = self) - app.loaded_modules.append(temp_module) + app.loaded_files.append(self.config.mod_path) app.modstack.append(temp_module) # We must chdir()s into the .hancho file directory before running it so that @@ -1231,7 +1231,7 @@ def __init__(self): self.jobs = os.cpu_count() self.target = None - self.loaded_modules = [] + self.loaded_files = [] self.dirstack = [os.getcwd()] self.modstack = [] diff --git a/tests/subrepo_tests/repo1/repo1_test1.hancho b/tests/subrepo_tests/repo1/repo1_test1.hancho index 1fd9897..c0dd706 100644 --- a/tests/subrepo_tests/repo1/repo1_test1.hancho +++ b/tests/subrepo_tests/repo1/repo1_test1.hancho @@ -1,4 +1,4 @@ -hancho.task( +hancho.Task( command = "touch {rel_build_files}", source_files = [], build_files = "repo1.txt", diff --git a/tutorial/tut00.hancho b/tutorial/tut00.hancho index af7f03c..f03e6fc 100644 --- a/tutorial/tut00.hancho +++ b/tutorial/tut00.hancho @@ -1,5 +1,7 @@ # tutorial/tut00.hancho +hancho.config.repo_name = "tut00" + hancho( desc = "Compile {in_src} -> {out_bin}", command = "g++ {in_src} -o {out_bin}", diff --git a/tutorial/tut01.hancho b/tutorial/tut01.hancho index 63a499d..a24d9ce 100644 --- a/tutorial/tut01.hancho +++ b/tutorial/tut01.hancho @@ -1,5 +1,7 @@ # tutorial/tut01.hancho +hancho.config.repo_name = "tut01" + main_o = hancho( desc = "Compile {in_src} -> {out_obj}", command = "g++ -MMD -c {in_src} -o {out_obj}", diff --git a/tutorial/tut02.hancho b/tutorial/tut02.hancho index c0bb134..0e06615 100644 --- a/tutorial/tut02.hancho +++ b/tutorial/tut02.hancho @@ -1,5 +1,7 @@ # tutorial/tut02.hancho +hancho.config.repo_name = "tut02" + main_o = hancho( desc = "Compile {in_src} -> {out_obj}", command = "g++ -MMD -c {in_src} -o {out_obj}", diff --git a/tutorial/tut03.hancho b/tutorial/tut03.hancho index d889f00..4f467b2 100644 --- a/tutorial/tut03.hancho +++ b/tutorial/tut03.hancho @@ -1,5 +1,7 @@ # tutorial/tut03.hancho +hancho.config.repo_name = "tut03" + def compile_cpp(source): obj = source.replace('.cpp', '.o') dep = source.replace('.cpp', '.d') diff --git a/tutorial/tut04.hancho b/tutorial/tut04.hancho index bedda67..9132115 100644 --- a/tutorial/tut04.hancho +++ b/tutorial/tut04.hancho @@ -1,5 +1,7 @@ # tutorial/tut04.hancho +hancho.config.repo_name = "tut04" + tut04_rules = hancho.load("tut04_rules.hancho") main_o = hancho( diff --git a/tutorial/tut10.hancho b/tutorial/tut10.hancho index d10caa7..7a73652 100644 --- a/tutorial/tut10.hancho +++ b/tutorial/tut10.hancho @@ -1,6 +1,6 @@ # tutorial/tut10.hancho - branches off from tut02.hancho -main_o = hancho.task( +main_o = hancho.Task( desc = "Compile {in_src}", command = "g++ -MMD -c {in_src} -o {out_obj}", in_src = "src/main.cpp", @@ -8,7 +8,7 @@ main_o = hancho.task( c_deps = "build/tut10/src/main.d", ) -util_o = hancho.task( +util_o = hancho.Task( desc = "Compile {in_src}", command = "g++ -MMD -c {in_src} -o {out_obj}", in_src = "src/util.cpp", @@ -16,7 +16,7 @@ util_o = hancho.task( c_deps = "build/tut10/src/util.d", ) -app = hancho.task( +app = hancho.Task( desc = "Link {in_objs} into {out_bin}", command = "g++ {in_objs} -o {out_bin}", in_objs = [main_o, util_o], diff --git a/tutorial/tut11.hancho b/tutorial/tut11.hancho index 901ba5b..feef812 100644 --- a/tutorial/tut11.hancho +++ b/tutorial/tut11.hancho @@ -1,38 +1,38 @@ # tutorial/tut11.hancho -common = hancho.config( +common = hancho.Config( task_dir = ".", build_dir = "build/tut11", ) -compile = hancho.config( +compile_cpp = hancho.Config( + common, desc = "Compile {in_src}", command = "g++ -MMD -c {in_src} -o {out_obj}", - **common, ) -main_o = hancho.task( - **compile, +main_o = hancho.Task( + compile_cpp, in_src = "src/main.cpp", out_obj = "src/main.o", c_deps = "src/main.d", ) -util_o = hancho.task( - **compile, +util_o = hancho.Task( + compile_cpp, in_src = "src/util.cpp", out_obj = "src/util.o", c_deps = "src/util.d", ) -link = hancho.config( - **common, +link_cpp = hancho.Config( + common, desc = "Link {in_objs} into {out_bin}", command = "g++ {in_objs} -o {out_bin}", ) -app = hancho.task( - **link, +app = hancho.Task( + link_cpp, in_objs = [main_o, util_o], out_bin = "app", ) diff --git a/tutorial/tut12.hancho b/tutorial/tut12.hancho index cffea0d..dc7ec58 100644 --- a/tutorial/tut12.hancho +++ b/tutorial/tut12.hancho @@ -1,17 +1,17 @@ # tutorial/tut12.hancho -cpp_compile = hancho.config( +cpp_compile = hancho.Config( desc = "Compile {in_src}", command = "g++ -MMD -c {in_src} -o {out_obj}", out_obj = "build/tut12/{swap_ext(in_src, '.o')}", c_deps = "build/tut12/{swap_ext(in_src, '.d')}", ) -cpp_link = hancho.config( +cpp_link = hancho.Config( desc = "Link {in_objs} into {out_bin}", command = "g++ {in_objs} -o {out_bin}", ) -main_o = hancho.task(cpp_compile, in_src = "src/main.cpp") -util_o = hancho.task(cpp_compile, in_src = "src/util.cpp") -app = hancho.task(cpp_link, in_objs = [main_o, util_o], out_bin = "build/tut12/app") +main_o = hancho.Task(cpp_compile, in_src = "src/main.cpp") +util_o = hancho.Task(cpp_compile, in_src = "src/util.cpp") +app = hancho.Task(cpp_link, in_objs = [main_o, util_o], out_bin = "build/tut12/app") diff --git a/tutorial/tut13.hancho b/tutorial/tut13.hancho index 1192730..6fc14a0 100644 --- a/tutorial/tut13.hancho +++ b/tutorial/tut13.hancho @@ -1,17 +1,17 @@ # tutorial/tut13.hancho -cpp_compile = hancho.config( +cpp_compile = hancho.Config( desc = "Compile {in_src}", command = "g++ -MMD -c {in_src} -o {out_obj}", out_obj = "build/tut13/{swap_ext(in_src, '.o')}", c_deps = "build/tut13/{swap_ext(in_src, '.d')}", ) -cpp_link = hancho.config( +cpp_link = hancho.Config( desc = "Link {in_objs} into {out_bin}", command = "g++ {in_objs} -o {out_bin}", ) -main_o = hancho.task(cpp_compile, in_src = "src/main.cpp") -util_o = hancho.task(cpp_compile, in_src = "src/util.cpp") -app = hancho.task(cpp_link, in_objs = [main_o, util_o], out_bin = "build/tut13/app") +main_o = hancho.Task(cpp_compile, in_src = "src/main.cpp") +util_o = hancho.Task(cpp_compile, in_src = "src/util.cpp") +app = hancho.Task(cpp_link, in_objs = [main_o, util_o], out_bin = "build/tut13/app") diff --git a/tutorial/tut14.hancho b/tutorial/tut14.hancho index df83100..17b8a1c 100644 --- a/tutorial/tut14.hancho +++ b/tutorial/tut14.hancho @@ -1,17 +1,17 @@ # tutorial/tut13.hancho -cpp_compile = hancho.config( +cpp_compile = hancho.Config( desc = "Compile {rel(in_src)}", command = "g++ -MMD -c {rel(in_src)} -o {rel(out_obj)}", out_obj = "build/tut14/{swap_ext(in_src, '.o')}", c_deps = "build/tut14/{swap_ext(in_src, '.d')}", ) -cpp_link = hancho.config( +cpp_link = hancho.Config( desc = "Link {rel(in_objs)} into {rel(out_bin)}", command = "g++ {rel(in_objs)} -o {rel(out_bin)}", ) -main_o = hancho.task(**cpp_compile, in_src = "src/main.cpp") -util_o = hancho.task(**cpp_compile, in_src = "src/util.cpp") -app = hancho.task(**cpp_link, in_objs = [main_o, util_o], out_bin = "build/tut14/app") +main_o = hancho.Task(**cpp_compile, in_src = "src/main.cpp") +util_o = hancho.Task(**cpp_compile, in_src = "src/util.cpp") +app = hancho.Task(**cpp_link, in_objs = [main_o, util_o], out_bin = "build/tut14/app") diff --git a/tutorial/tutorial.hancho b/tutorial/tutorial.hancho index 439fee7..553f0a3 100644 --- a/tutorial/tutorial.hancho +++ b/tutorial/tutorial.hancho @@ -3,11 +3,11 @@ import shutil shutil.rmtree("build", ignore_errors=True) -hancho.load("tut00.hancho", repo_name = "tut00") -hancho.load("tut01.hancho", repo_name = "tut01") -hancho.load("tut02.hancho", repo_name = "tut02") -hancho.load("tut03.hancho", repo_name = "tut03") -hancho.load("tut04.hancho", repo_name = "tut04") +hancho.load("tut00.hancho") +hancho.load("tut01.hancho") +hancho.load("tut02.hancho") +hancho.load("tut03.hancho") +hancho.load("tut04.hancho") #hancho.load("tut11.hancho") #hancho.load("tut12.hancho")