summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2025-01-06 16:22:23 -0500
committerBen Sima <ben@bsima.me>2025-01-06 16:22:23 -0500
commitd2edf150cf2c876971383a4a484f289ce7e7f680 (patch)
tree1cd30c0efe2afa2f0d1ca935738fac22d5687659
parentd9fb7a85c920c9332fba34087fe8527d140b65f0 (diff)
Remove Python main idiom and add coding conventions to README.md
I realized I don't need this stupid `__main__` convention anymore because my build system always calls Python programs like `python -m main`, so I just need to have a function named `main()`. I also started adding some general coding conventions to the README and fixed a typo.
-rwxr-xr-xBiz/Dragons/main.py4
-rwxr-xr-xBiz/Que/Client.py4
-rwxr-xr-xBiz/Storybook.py4
-rwxr-xr-xOmni/Bild/Example.py4
-rwxr-xr-xOmni/Ide/MakeTags.py4
-rwxr-xr-xOmni/Llamacpp.py4
-rw-r--r--Omni/Log.py5
-rwxr-xr-xOmni/Repl.py4
-rw-r--r--README.md15
9 files changed, 17 insertions, 31 deletions
diff --git a/Biz/Dragons/main.py b/Biz/Dragons/main.py
index de84ff5..0cb4554 100755
--- a/Biz/Dragons/main.py
+++ b/Biz/Dragons/main.py
@@ -251,7 +251,3 @@ def main() -> None:
repo.print_blackholes(full=args.blackholes)
repo.print_liabilities(full=args.liabilities)
repo.print_stale(full=args.stale)
-
-
-if __name__ == "__main__":
- main()
diff --git a/Biz/Que/Client.py b/Biz/Que/Client.py
index 7b28e27..671b464 100755
--- a/Biz/Que/Client.py
+++ b/Biz/Que/Client.py
@@ -235,7 +235,3 @@ def main() -> None:
recv(argv)
except KeyboardInterrupt:
sys.exit(0)
-
-
-if __name__ == "__main__":
- main()
diff --git a/Biz/Storybook.py b/Biz/Storybook.py
index 0c96ee7..f151394 100755
--- a/Biz/Storybook.py
+++ b/Biz/Storybook.py
@@ -718,7 +718,3 @@ class Generate(ludic.web.Endpoint[StoryInputs]):
hx_trigger="submit",
),
)
-
-
-if __name__ == "__main__":
- main()
diff --git a/Omni/Bild/Example.py b/Omni/Bild/Example.py
index 462a497..58e941a 100755
--- a/Omni/Bild/Example.py
+++ b/Omni/Bild/Example.py
@@ -40,7 +40,3 @@ def main() -> None:
if "test" in sys.argv:
sys.stdout.write("testing success")
sys.stdout.write(cryptic_hello("world"))
-
-
-if __name__ == "__main__":
- main()
diff --git a/Omni/Ide/MakeTags.py b/Omni/Ide/MakeTags.py
index add07c0..7f09a4e 100755
--- a/Omni/Ide/MakeTags.py
+++ b/Omni/Ide/MakeTags.py
@@ -99,7 +99,3 @@ def ctags(args: list[str], cwd: pathlib.Path = pathlib.Path()) -> None:
]
subprocess.check_call(["ctags", *excludes, *args])
subprocess.check_call(["ctags", "-e", *excludes, *args])
-
-
-if __name__ == "__main__":
- main()
diff --git a/Omni/Llamacpp.py b/Omni/Llamacpp.py
index b8975f2..eac08fd 100755
--- a/Omni/Llamacpp.py
+++ b/Omni/Llamacpp.py
@@ -38,7 +38,3 @@ def main() -> None:
test()
else:
sys.exit(0)
-
-
-if __name__ == "__main__":
- main()
diff --git a/Omni/Log.py b/Omni/Log.py
index e644a1a..8d61139 100644
--- a/Omni/Log.py
+++ b/Omni/Log.py
@@ -14,7 +14,7 @@ class LowerFormatter(logging.Formatter):
def setup(level: int = logging.INFO) -> logging.Logger:
- """Run this in your __main__ function."""
+ """Run this in your `main()` function."""
logging.basicConfig(
level=level,
format="%(levelname)s: %(name)s: %(message)s",
@@ -30,6 +30,7 @@ def setup(level: int = logging.INFO) -> logging.Logger:
return logger
-if __name__ == "__main__":
+def main() -> None:
+ """Entrypoint to test that this kinda works."""
setup()
logging.debug("i am doing testing")
diff --git a/Omni/Repl.py b/Omni/Repl.py
index 8d191e2..cad04b5 100755
--- a/Omni/Repl.py
+++ b/Omni/Repl.py
@@ -260,7 +260,3 @@ def main() -> None:
test()
else:
move()
-
-
-if __name__ == "__main__":
- main()
diff --git a/README.md b/README.md
index 142c07a..f7756df 100644
--- a/README.md
+++ b/README.md
@@ -90,7 +90,7 @@ this command to run tests for a namespace.
is our cloud VM instance. The `--time 0` argument disables the timeout (which
defaults to 10 minutes), this is useful for longer builds.
-`bild --json Omni/Test.hs` this just does the analysis step, and prints a
+`bild --plan Omni/Test.hs` this just does the analysis step, and prints a
description of the build as JSON. It will not build anything.
### lint
@@ -120,6 +120,19 @@ loaded.
`repl.sh --bash Omni/Log.py` this creates a nix shell for `Omni/Log.py`, but
starts a bash shell for the namespace instead of a Python repl.
+## Coding Conventions
+
+There are some conventions we use for every program, across every language in
+use.
+
+1. At the command line interface, the program must take `test` as a first
+ argument, which will run the program's test suite. This is used as a standard
+ interface for running tests in CI.
+2. The entrypoint for every program shall be called `main.` In Python, the
+ convention `if __name__ == "__main__"` is not necessary because `bild` wraps
+ the program in a call like `python -m main`; the same is true of Guile
+ scheme.
+
## Setting up remote builds
The `Omni.Dev` machine acts as a remote build server and Nix cache. To use it from