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]
patched_manifest_path = "manifests-cache/patched-manifest.json"
patch_manifest(manifest_path, patched_manifest_path)
subprocess.run(["flatpak-builder", build_dir, patched_manifest_path,
"--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) check=True)
subprocess.run(["flatpak", "build", build_dir, "test-all"], check=True) print("Build successful:", build_dir)
subprocess.run(["flatpak", "build", build_dir, "eris", "--help"], check=True)
print("Build successful:", build_dir)
if __name__ == "__main__":
main(sys.argv)

View file

@ -441,12 +441,12 @@ 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")
@ -466,10 +466,14 @@ for dep in sorted(deps - DEPS_IN_RUNTIME) + ["eris"]:
print() print()
all_modules.extend(modules) all_modules.extend(modules)
save_manifest(make_manifest(modules, dep), manifest_path) save_manifest(make_manifest(modules, dep), manifest_path)
eris_module = all_modules[-1] eris_module = all_modules[-1]
eris_module["sources"][0]["commit"] = get_latest_commit() eris_module["sources"][0]["commit"] = get_latest_commit()
manifest = make_combined_manifest(all_modules) manifest = make_combined_manifest(all_modules)
manifest_path = "com.github.ahamilton.eris.json" manifest_path = "com.github.ahamilton.eris.json"
print() print()
print(f"Saving manifest file: ./{manifest_path}") print(f"Saving manifest file: ./{manifest_path}")
save_manifest(manifest, manifest_path) save_manifest(manifest, manifest_path)
if __name__ == "__main__":
main()

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():
all_tools = ([(["*"], tools.generic_tools() +
[tools.git_blame, tools.git_log])] + [tools.git_blame, tools.git_log])] +
tools.TOOLS_FOR_EXTENSIONS) tools.TOOLS_FOR_EXTENSIONS)
tool_set = set() tool_set = set()
extension_set = set() extension_set = set()
for extensions, tools_ in all_tools: for extensions, tools_ in all_tools:
tool_set.update(tools_) tool_set.update(tools_)
extension_set.update(extensions) extension_set.update(extensions)
print(f"""\ 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()