Coding style.

- pydoc expects scripts that do little when imported.
  So all python scripts really need 'if __name__ == "__main__":'
This commit is contained in:
Andrew Hamilton 2019-07-22 10:49:40 +10:00
parent aea93874cc
commit 07a73e006c
3 changed files with 69 additions and 56 deletions

View file

@ -20,11 +20,6 @@ The script should only be run from the root of the local eris repository.
""" """
if len(sys.argv) != 4:
print(USAGE)
sys.exit(1)
def patch_manifest(manifest_path, patched_manifest_path): def patch_manifest(manifest_path, patched_manifest_path):
with open(manifest_path) as manifest_file: with open(manifest_path) as manifest_file:
manifest = json.load(manifest_file) manifest = json.load(manifest_file)
@ -34,12 +29,21 @@ def patch_manifest(manifest_path, patched_manifest_path):
json.dump(manifest, patched_manifest_file, indent=2) json.dump(manifest, patched_manifest_file, indent=2)
manifest_path, build_dir, state_dir = sys.argv[1:4] def main(argv):
patched_manifest_path = "manifests-cache/patched-manifest.json" if len(argv) != 4:
patch_manifest(manifest_path, patched_manifest_path) print(USAGE)
subprocess.run(["flatpak-builder", build_dir, patched_manifest_path, sys.exit(1)
"--force-clean", "--state-dir", state_dir, "--disable-updates"], manifest_path, build_dir, state_dir = argv[1:4]
check=True) patched_manifest_path = "manifests-cache/patched-manifest.json"
subprocess.run(["flatpak", "build", build_dir, "test-all"], check=True) patch_manifest(manifest_path, patched_manifest_path)
subprocess.run(["flatpak", "build", build_dir, "eris", "--help"], check=True) subprocess.run(["flatpak-builder", build_dir, patched_manifest_path,
print("Build successful:", build_dir) "--force-clean", "--state-dir", state_dir,
"--disable-updates"], check=True)
subprocess.run(["flatpak", "build", build_dir, "test-all"], check=True)
subprocess.run(["flatpak", "build", build_dir, "eris", "--help"],
check=True)
print("Build successful:", build_dir)
if __name__ == "__main__":
main(sys.argv)

View file

@ -441,35 +441,39 @@ def make_combined_manifest(all_modules):
SUBSTITUTIONS = {"shellcheck": "haskell/ShellCheck", SUBSTITUTIONS = {"shellcheck": "haskell/ShellCheck",
"pandoc": "haskell/pandoc"} "pandoc": "haskell/pandoc"}
def main():
manifests_dir = os.path.join(os.getcwd(), "manifests-cache") manifests_dir = os.path.join(os.getcwd(), "manifests-cache")
os.makedirs(manifests_dir, exist_ok=True) os.makedirs(manifests_dir, exist_ok=True)
deps = {SUBSTITUTIONS.get(dep, dep) for dep in eris.tools.dependencies()} deps = {SUBSTITUTIONS.get(dep, dep) for dep in eris.tools.dependencies()}
all_modules = [] all_modules = []
for dep in sorted(deps - DEPS_IN_RUNTIME) + ["eris"]: for dep in sorted(deps - DEPS_IN_RUNTIME) + ["eris"]:
build_func, package = get_build_func(dep) build_func, package = get_build_func(dep)
dep_name = os.path.basename(package) dep_name = os.path.basename(package)
manifest_path = os.path.join(manifests_dir, dep_name+".json") manifest_path = os.path.join(manifests_dir, dep_name+".json")
print(f"Making manifest for {dep}".ljust(70), end="", flush=True) print(f"Making manifest for {dep}".ljust(70), end="", flush=True)
if os.path.exists(manifest_path): if os.path.exists(manifest_path):
print(" (cached)") print(" (cached)")
with open(manifest_path) as json_file: with open(manifest_path) as json_file:
modules = json.load(json_file)["modules"] modules = json.load(json_file)["modules"]
all_modules.extend(modules)
continue
elif dep == "eris":
modules = eris_modules()
elif dep == "nodejs":
modules = nodejs_modules()
else:
modules = build_func(package)
print()
all_modules.extend(modules) all_modules.extend(modules)
continue save_manifest(make_manifest(modules, dep), manifest_path)
elif dep == "eris": eris_module = all_modules[-1]
modules = eris_modules() eris_module["sources"][0]["commit"] = get_latest_commit()
elif dep == "nodejs": manifest = make_combined_manifest(all_modules)
modules = nodejs_modules() manifest_path = "com.github.ahamilton.eris.json"
else:
modules = build_func(package)
print() print()
all_modules.extend(modules) print(f"Saving manifest file: ./{manifest_path}")
save_manifest(make_manifest(modules, dep), manifest_path) save_manifest(manifest, manifest_path)
eris_module = all_modules[-1]
eris_module["sources"][0]["commit"] = get_latest_commit()
manifest = make_combined_manifest(all_modules) if __name__ == "__main__":
manifest_path = "com.github.ahamilton.eris.json" main()
print()
print(f"Saving manifest file: ./{manifest_path}")
save_manifest(manifest, manifest_path)

View file

@ -13,15 +13,16 @@ def tool_markup(tool):
return (tool.__name__ if url is None else f"[{tool.__name__}]({url})") return (tool.__name__ if url is None else f"[{tool.__name__}]({url})")
all_tools = ([(["*"], tools.generic_tools() + def main():
[tools.git_blame, tools.git_log])] + all_tools = ([(["*"], tools.generic_tools() +
tools.TOOLS_FOR_EXTENSIONS) [tools.git_blame, tools.git_log])] +
tool_set = set() tools.TOOLS_FOR_EXTENSIONS)
extension_set = set() tool_set = set()
for extensions, tools_ in all_tools: extension_set = set()
tool_set.update(tools_) for extensions, tools_ in all_tools:
extension_set.update(extensions) tool_set.update(tools_)
print(f"""\ extension_set.update(extensions)
print(f"""\
# Eris Codebase Monitor # Eris Codebase Monitor
### Summary ### Summary
@ -49,6 +50,10 @@ then to run:
Extensions({len(extension_set)-1}) | Tools({len(tool_set)}) Extensions({len(extension_set)-1}) | Tools({len(tool_set)})
----------:| -----""") ----------:| -----""")
for extensions, tools_ in all_tools: for extensions, tools_ in all_tools:
print("%s | %s" % (" ".join("." + extension for extension in extensions), print("%s | %s" % (" ".join("." + extension for extension in extensions),
"".join(tool_markup(tool) for tool in tools_))) "".join(tool_markup(tool) for tool in tools_)))
if __name__ == "__main__":
main()