Skip to content
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

feat: allow config in command decorator #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Thomzoy
Copy link
Collaborator

@Thomzoy Thomzoy commented Jul 18, 2023

Description

The goal of this PR is to add an config argument in @app.command. As such, it allows to pass one (or more) Config object to the underlying script. All additional configurations provided through the CLI will still be used via merging.

@app.command("script", config=Config(...))
def run(...):
    ...

Then python -m script.py will run as is

Checklist

  • If this PR is a bug fix, the bug is documented in the test suite.
  • Changes were documented in the changelog (pending section).
  • If necessary, changes were made to the documentation.

@Thomzoy Thomzoy requested a review from percevalw July 18, 2023 12:27
@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.03 🎉

Comparison is base (1c5aac2) 97.82% compared to head (08ac9fe) 97.86%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #4      +/-   ##
==========================================
+ Coverage   97.82%   97.86%   +0.03%     
==========================================
  Files           8        8              
  Lines         644      655      +11     
==========================================
+ Hits          630      641      +11     
  Misses         14       14              
Impacted Files Coverage Δ
confit/cli.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Thomzoy Thomzoy force-pushed the config_in_command branch from c595e44 to 9d0f007 Compare July 18, 2023 12:31
@Thomzoy Thomzoy requested review from percevalw and removed request for percevalw July 18, 2023 12:31
@Thomzoy Thomzoy force-pushed the config_in_command branch from 6c07215 to 08ac9fe Compare July 19, 2023 08:17
Copy link
Member

@percevalw percevalw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition !

Comment on lines +112 to 131
if initial_config is not None:
initial_configs = (
[initial_config]
if isinstance(initial_config, Config)
else initial_config
)

initial_config_path = []

for c in initial_configs:
temp_file = tempfile.NamedTemporaryFile(delete=False)
temp_file.write(
c.to_str().encode()
) # Write the string to the file
temp_file.close()
initial_config_path.append(Path(temp_file.name))
config_path = initial_config_path + config_path

if config_path:
config, name_from_file = merge_from_disk(config_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel the disk writing operation is not really necessary, if its only purpose is to use merge_from_disk. Could we drop merge_from_disk, load all configs and merge them directly from memory instead ?

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.

2 participants