Skip to content

Conversation

@katzuv
Copy link
Owner

@katzuv katzuv commented Dec 3, 2021

No description provided.

@katzuv katzuv self-assigned this Dec 3, 2021
@katzuv katzuv force-pushed the feature/add-solution-runner branch from e1487ce to 671564e Compare November 18, 2022 18:35
@katzuv katzuv force-pushed the feature/add-solution-runner branch from 671564e to 14d256d Compare November 18, 2022 19:26
"""
configuration_file = consts.APP_DATA_DIRECTORY / consts.CONFIGURATION_FILE_NAME
try:
configuration = yaml.safe_load(configuration_file.read_text())
Copy link
Collaborator

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.

Copy link
Owner Author

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?

Copy link
Collaborator

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.
Copy link
Collaborator

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.

Copy link
Owner Author

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:
Copy link
Collaborator

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.

Copy link
Owner Author

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.

Copy link
Collaborator

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):
Copy link
Collaborator

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.

@katzuv
Copy link
Owner Author

katzuv commented Dec 9, 2022

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.

@katzuv katzuv merged commit d7ab742 into master Dec 9, 2022
@katzuv katzuv deleted the feature/add-solution-runner branch December 9, 2022 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants