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

Share some options between the CLI and magic. #350

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Carreau
Copy link
Contributor

@Carreau Carreau commented Nov 20, 2024

This refactor compute_render_options, to be shared between CLI and magic.

Add a few of the CLI options to be available in the magic.

The only thing I don't really like is that we redefine the help text options.

@Carreau
Copy link
Contributor Author

Carreau commented Nov 20, 2024

See discussion in #334

This refactor compute_render_options, to be shared between CLI and
magic.

Add a few of the CLI options to be available in the magic.

The only thing I don't really like is that we redefine
the help text options.
@Carreau
Copy link
Contributor Author

Carreau commented Dec 2, 2024

Closing and reopening to trigger CI.

Copy link
Owner

@joerick joerick left a comment

Choose a reason for hiding this comment

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

sorry for the delay in the review. it looks good! just a couple comments

pyinstrument/__main__.py Outdated Show resolved Hide resolved
Comment on lines +435 to +446
def _compute_render_options(
options: CommandLineOptions,
renderer_class: type[renderers.Renderer],
unicode_support: bool,
color_support: bool,
) -> Tuple[Optional[str], Optional[dict[str, Any]]]:
"""
Similar as compute_render_options, but return a tuple (error message, data)
if there is an error; this will let us reuse _compute_render_options in magics.

output_file, has been replaced by unicode_support:bool, color_support:bool
"""
Copy link
Owner

Choose a reason for hiding this comment

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

I think we don't need this extra wrapper function, rather, instead we could wrap the invocations of compute_render_options in magic.py with try:...catch:...? unless i'm missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wanted to avoid contaminating the magic system with OptionsParseError, which is defined in __main__, and I don't want cyclic imports; but I can make compute_render_option not raise as it is used in a single place, and raise OptionsParseError in the sole place it it used.

Copy link
Contributor Author

@Carreau Carreau Jan 15, 2025

Choose a reason for hiding this comment

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

Also compute_render_options, takes an output_file while the private variant takes two booleans (unicode_support: bool, color_support: bool), as there are no output file when running the magic. I can lift both of those as well

@Carreau
Copy link
Contributor Author

Carreau commented Jan 6, 2025

sorry for the delay in the review. it looks good

No needs to apologize, this is open source and users are not owed anything.
I've learn myself to instead of apologizing, thanking contributor for their patience – at least I try. It's a subtle difference, but at least help me with framing my guilt and decrease burnout.

I will look back into this when possible,

Happy new year as well.

Co-authored-by: Joe Rickerby <joerick@mac.com>
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