-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Make static_site_generator.py a standalone script #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
**Description**: Enables better testing at CLI Enables re-runs of html generation given a provided source json file like `output.projects.json` **Related Issue(s)**: closes #80 Signed-off-by: Roger Barker <roger.barker@swirldslabs.com>
Signed-off-by: Roger Barker <roger.barker@swirldslabs.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request refactors static_site_generator.py to function as a standalone CLI script, enhancing its testing and rerun capabilities.
- Added CLI support with a main() function capturing JSON file input and handling file existence checks.
- Updated the generate_site() function with a return type annotation.
Comments suppressed due to low confidence (1)
src/static_site_generator.py:44
- [nitpick] Consider using the output_file parameter in the log message to ensure the log reflects the actual file path used when a different output file is provided.
logging.info("Static Site Generated @ ./_site/index.html")
ss_gen = StaticSiteGenerator() | ||
data_file:str = input("Enter the path to the json file with data: ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider using argparse for handling command line arguments to improve user experience and provide more flexibility than interactive input.
ss_gen = StaticSiteGenerator() | |
data_file:str = input("Enter the path to the json file with data: ") | |
import argparse | |
parser = argparse.ArgumentParser(description="Generate a static site from a JSON data file.") | |
parser.add_argument("--data-file", required=True, help="Path to the JSON file with data.") | |
args = parser.parse_args() | |
ss_gen = StaticSiteGenerator() | |
data_file = args.data_file |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont want to
with open(data_file, 'r') as f: | ||
data = json.load(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] It may be beneficial to wrap the JSON file loading in a try-except block to gracefully handle JSON decoding errors.
with open(data_file, 'r') as f: | |
data = json.load(f) | |
try: | |
with open(data_file, 'r') as f: | |
data = json.load(f) | |
except json.JSONDecodeError as e: | |
print(f"[bold red]Error: Failed to decode JSON from file {data_file}. Please check the file format.[/bold red]") | |
return |
Copilot uses AI. Check for mistakes.
Co-authored-by: Andrew Brandt <andrew.brandt@hashgraph.com> Signed-off-by: Roger Barker <roger.barker@swirldslabs.com>
Description:
Enables better testing at CLI
Enables re-runs of html generation given a provided source json file like
output.projects.json
Related Issue(s):
closes #80