-
Notifications
You must be signed in to change notification settings - Fork 0
Create solution runner #4
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
This is to ignore other non-command Python files, such as constants file.
e1487ce to
671564e
Compare
671564e to
14d256d
Compare
| """ | ||
| configuration_file = consts.APP_DATA_DIRECTORY / consts.CONFIGURATION_FILE_NAME | ||
| try: | ||
| configuration = yaml.safe_load(configuration_file.read_text()) |
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.
If you are getting more than one settings per program execution, it might be better to load the configuration only once and cache the dict in memory.
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.
cache the dict in memory
How?
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.
Global variable, or defining a function performing yaml.safe_load(configuration_file.read_text()) and decorating it with @functools.cache.
| Abort if path doesn't exist. | ||
| :param path: path to check | ||
| :param command: command to be passed to`click.Context` if aborting is needed | ||
| :param path_type: optional "dir" or "file". If not passed, only check for existence. If passed, check for type. |
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.
It is better to have separate functions for each case (exists/is_dir/is_file) instead of a string parameter: check_dir_exists(...) is nicer than check_path_exists(..., "dir").
See https://wiki.c2.com/?StringlyTyped.
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.
Apparently, I am not using it, so I deleted it (afdec7d).
| raise click.Abort() | ||
|
|
||
|
|
||
| def send_aoc_request(method, endpoint: str, payload=None) -> str: |
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.
Replace with a function per HTTP method. This way the GET function does not need to take an optional payload parameter.
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.
Why? This is a utility function, requests.request() takes an optional payload too.
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.
requests.request() is a lower level function, the requests.get() does not receive data/payload.
| import sys | ||
|
|
||
|
|
||
| def get_answer(input_text: str): |
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.
Let's try to call the solution code without subprocess, to avoid having to write the boilerplate "main function" code. I'll be happy to help.
|
There are still a few tasks to finish, but because Advent of Code 2022 has already started, I'll merge this now and additional fixes and features will be added later. |
No description provided.