From 7ea9bd4a8a8c3399183d70c75b2571af930ff2fc Mon Sep 17 00:00:00 2001 From: Luke Weiler Date: Mon, 23 Jun 2025 20:44:38 -0400 Subject: [PATCH] Create mg.py --- CONTRIBUTING.md | 2 +- scripts/mg.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 scripts/mg.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4a592e1..a4e0206 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,6 +15,6 @@ If you have never contributed to open source before here is a quick explanation * Fork this repository on Github. This creates a copy of the current code that you can edit and make changes to. * Navigate to your fork and make your changes. This could be done by cloning and making changes locally on your computer. You can find many tutorials on this online. You could also edit directly on Github if you don't have access to a text editor but doing this, you will not be able to test your function. -* To test your changes, open a terminal and from the project root, run `pip install -e .` to install a locally editable version of the mathgenerator package. Then, run a python terminal with `python`, `import mathgenerato` and call the method you worked on. +* To test your changes, open a terminal and from the project root, run `pip install -e .` to install a locally editable version of the mathgenerator package. Then, run `mg.py` with your generator name to print a generated problem like `./scripts/mg.py addition` * Commit and create a pull request. Navigate to [the math generator repository pull request tab](https://github.com/Todarith/mathGenerator/pulls) and click New Pull Request. Then click compare accross forks. Select your fork and branch as the head branch and leave a description. Then click Create Pull Request. * If all goes well, your request will be approved and your generator added. Congratulations! diff --git a/scripts/mg.py b/scripts/mg.py new file mode 100755 index 0000000..bb64e0e --- /dev/null +++ b/scripts/mg.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +import mathgenerator +import sys + + +def main(): + """ + Run a mathgenerator function by name and print the output. + + Usage: python mg.py + Example: python mg.py addition + """ + if len(sys.argv) != 2: + print("Usage: python mg.py ") + print("Example: python mg.py addition") + sys.exit(1) + + function_name = sys.argv[1] + + try: + # Get the function from the mathgenerator module + func = getattr(mathgenerator, function_name) + + # Call the function and get the result + result = func() + + # Print the result + print(result) + + except AttributeError: + print(f"Error: Function '{function_name}' not found in mathgenerator module") + print("Available functions can be found by checking mathgenerator.get_gen_list()") + sys.exit(1) + except Exception as e: + print(f"Error calling function '{function_name}': {e}") + sys.exit(1) + + +if __name__ == "__main__": + main()