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

Generalized macOS stdout handler in Config #137

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

AlexPatrie
Copy link
Contributor

What new features does this PR implement?
Please summarize the features that this PR implements. As relevant, please indicate the issues that the PR closes.

  • Adds Optional default setting for StandardOutputCapturerLevel to Config object through a validation block. Adjusted default setting from "c" to "python" (resolves dependency on capturer #135)

  • Adds type annotations to functions


What bugs does this PR fix?
Please summarize the bugs that this PR fixes. As relevant, please indicate the issues that the PR closes.

How have you tested this PR?
Pytest, and self testing.

@AlexPatrie AlexPatrie requested a review from eagmon May 8, 2023 20:51
@AlexPatrie AlexPatrie changed the title Generalized macOS handler in Config Generalized macOS handler in Config May 8, 2023
@AlexPatrie AlexPatrie changed the title Generalized macOS handler in Config Generalized macOS stdout handler in Config May 8, 2023
@AlexPatrie AlexPatrie requested a review from jcschaff May 8, 2023 21:00

__all__ = ['Config', 'get_config', 'Colors', 'get_app_dirs']

CURRENT_PLATFORM = platform.system()
try:
assert CURRENT_PLATFORM == "Darwin"
Copy link
Contributor

Choose a reason for hiding this comment

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

so this will catch all Mac OS? Have you also tested the bug in non-Mac OS? Why is it that python is connected to Mac and all others use c?

@@ -117,7 +129,7 @@ def __init__(self,
COLLECT_SED_DOCUMENT_RESULTS (:obj:`bool`, optional): whether to assemble an in memory data structure with all of the
simulation results of SED documents
SAVE_PLOT_DATA (:obj:`bool`, optional): whether to save data for plots alongside data for reports in CSV/HDF5 files
REPORT_FORMATS (:obj:`list` of :obj:`str`, optional): default formats to generate reports in
REPORT_FORMATS (:obj:`list` of :obj:`str`, optional): default formats to generate reports in-->defaults to 'csv'
Copy link
Contributor

Choose a reason for hiding this comment

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

This PR sets the default to None

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 originally was generating the value of REPORT_FORMATS to have a default constructor setting of [ReportFormat.csv] (formats are of type(enum.Enum)), or even [ReportFormat.h5]. Our good friend SonarCloud complained about this definition, which makes sense as the definition is also performing a very basic operation other than just instantiation. This doc string annotation was from when I had it in the definition and must have missed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After review, that doc string is actually as I intended it to be. Following the logic of the constructor, if there is no value for the REPORT_FORMATS attribute upon instantiation, it defaults to 'csv'. As per the constructor: self.REPORT_FORMATS = REPORT_FORMATS or [ReportFormat.csv], which evaluates roughly as:

if not REPORT_FORMATS:
REPORT_FORMATS = [ReportFormat.csv]

@@ -147,8 +160,8 @@ def __init__(self,
self.COLLECT_COMBINE_ARCHIVE_RESULTS = COLLECT_COMBINE_ARCHIVE_RESULTS
self.COLLECT_SED_DOCUMENT_RESULTS = COLLECT_SED_DOCUMENT_RESULTS
self.SAVE_PLOT_DATA = SAVE_PLOT_DATA
self.REPORT_FORMATS = REPORT_FORMATS
self.VIZ_FORMATS = VIZ_FORMATS
self.REPORT_FORMATS = REPORT_FORMATS or [ReportFormat.csv]
Copy link
Contributor

Choose a reason for hiding this comment

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

Hah, I saw this and thought it was an actual csv file rather than a csv attribute of ReportFormat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You know, I did at first as well! As I mentioned, I moved the logic for this inside the actual constructor as per SonarCloud.

DEBUG=False):
DEBUG=False,
STDOUT_LEVEL=DEFAULT_STDOUT_LEVEL,
**CUSTOM_SETTINGS):
Copy link
Contributor

Choose a reason for hiding this comment

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

using the ** I see. kind of dangerous that anything can come in here and will be applied to the settings. Do you have examples of what kind of kwargs might be used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a part of my original implementation in an idea that I had. As you can see starting at line 181, these **kwargs become unpacked in the private method __getcustomsettings() and returned as a dict in the attribute CUSTOM_SETTINGS. I realize the danger of arbitrarily using unpacking, but I have funneled it into a collection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Devising some presentable use cases now to plead my case, hah.

@eagmon
Copy link
Contributor

eagmon commented May 9, 2023

I left some comments, this is looking pretty close. What's failing in the CI?

@sonarcloud
Copy link

sonarcloud bot commented May 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 5 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@AlexPatrie
Copy link
Contributor Author

I left some comments, this is looking pretty close. What's failing in the CI?

I just need to take care of some linting errors in this case.

Copy link
Contributor Author

@AlexPatrie AlexPatrie left a comment

Choose a reason for hiding this comment

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

I am going to add an example use case for the unpacking **CUSTOM_SETTINGS.

DEBUG=False):
DEBUG=False,
STDOUT_LEVEL=DEFAULT_STDOUT_LEVEL,
**CUSTOM_SETTINGS):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was a part of my original implementation in an idea that I had. As you can see starting at line 181, these **kwargs become unpacked in the private method __getcustomsettings() and returned as a dict in the attribute CUSTOM_SETTINGS. I realize the danger of arbitrarily using unpacking, but I have funneled it into a collection.

DEBUG=False):
DEBUG=False,
STDOUT_LEVEL=DEFAULT_STDOUT_LEVEL,
**CUSTOM_SETTINGS):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Devising some presentable use cases now to plead my case, hah.

@@ -117,7 +129,7 @@ def __init__(self,
COLLECT_SED_DOCUMENT_RESULTS (:obj:`bool`, optional): whether to assemble an in memory data structure with all of the
simulation results of SED documents
SAVE_PLOT_DATA (:obj:`bool`, optional): whether to save data for plots alongside data for reports in CSV/HDF5 files
REPORT_FORMATS (:obj:`list` of :obj:`str`, optional): default formats to generate reports in
REPORT_FORMATS (:obj:`list` of :obj:`str`, optional): default formats to generate reports in-->defaults to 'csv'
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 originally was generating the value of REPORT_FORMATS to have a default constructor setting of [ReportFormat.csv] (formats are of type(enum.Enum)), or even [ReportFormat.h5]. Our good friend SonarCloud complained about this definition, which makes sense as the definition is also performing a very basic operation other than just instantiation. This doc string annotation was from when I had it in the definition and must have missed it.

@@ -147,8 +160,8 @@ def __init__(self,
self.COLLECT_COMBINE_ARCHIVE_RESULTS = COLLECT_COMBINE_ARCHIVE_RESULTS
self.COLLECT_SED_DOCUMENT_RESULTS = COLLECT_SED_DOCUMENT_RESULTS
self.SAVE_PLOT_DATA = SAVE_PLOT_DATA
self.REPORT_FORMATS = REPORT_FORMATS
self.VIZ_FORMATS = VIZ_FORMATS
self.REPORT_FORMATS = REPORT_FORMATS or [ReportFormat.csv]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You know, I did at first as well! As I mentioned, I moved the logic for this inside the actual constructor as per SonarCloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

dependency on capturer
2 participants