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

Log a warning when an executable is found, but does not have the exec… #22

Merged
merged 8 commits into from
Jul 24, 2024

Conversation

pmrv
Copy link
Contributor

@pmrv pmrv commented Jul 22, 2024

… bit set

@pmrv pmrv added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 22, 2024
@pmrv pmrv requested review from jan-janssen and liamhuber July 22, 2024 13:21
Copy link

Binder 👈 Launch a binder notebook on branch pyiron/pyiron_snippets/warn

Copy link

codacy-production bot commented Jul 22, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.03% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (7a4fe2a) 550 522 94.91%
Head commit (039f62f) 553 (+3) 525 (+3) 94.94% (+0.03%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#22) 3 3 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences


🚀 Don’t miss a bit, follow what’s new on Codacy.

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@coveralls
Copy link

coveralls commented Jul 22, 2024

Pull Request Test Coverage Report for Build 10078911247

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.06%) to 94.964%

Files with Coverage Reduction New Missed Lines %
resources.py 4 96.19%
Totals Coverage Status
Change from base Build 9941886607: 0.06%
Covered Lines: 528
Relevant Lines: 556

💛 - Coveralls

@pmrv
Copy link
Contributor Author

pmrv commented Jul 22, 2024

Fixes #21.

@pmrv pmrv added the format_black Trigger the black formatting bot label Jul 22, 2024
@liamhuber
Copy link
Member

I'm uncomfortable with the cross dependency to another part of the snippets package-- even if it is locked away and not top level.

I need to check, but if we import the logger and then just warnings.warn (or maybe (re)import the default python logger and pass a warning there) doesn't this get caught by the pyiron log? I thought it should bz virtue of the logger module configuring the base logger, but maybe I'm being naive about a fresh instance of the logger ignoring this

@pmrv
Copy link
Contributor Author

pmrv commented Jul 22, 2024

I'm uncomfortable with the cross dependency to another part of the snippets package-- even if it is locked away and not top level.

I need to check, but if we import the logger and then just warnings.warn (or maybe (re)import the default python logger and pass a warning there) doesn't this get caught by the pyiron log? I thought it should bz virtue of the logger module configuring the base logger, but maybe I'm being naive about a fresh instance of the logger ignoring this

Fair, I think this should be possible, but will need to check.

@liamhuber
Copy link
Member

Fair, I think this should be possible, but will need to check.

If it doesn't work pretty straightforwardly, I am content to make an exception (especially since it's not a top-level import), but let's check if we can have our cake and eat it too.

@pmrv
Copy link
Contributor Author

pmrv commented Jul 23, 2024

The standard library has this, with the caveat that it redirects all warnings and to a hard coded logger, but it would be possible to setup similar logic in snippets.logger and redirect all warnings or warnings of a certain type to the pyiron logger. The warning type would have to be defined in a shared module somewhere so still link logger and resources.

Copy link

codacy-production bot commented Jul 23, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.05% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (7a4fe2a) 550 522 94.91%
Head commit (efd976c) 556 (+6) 528 (+6) 94.96% (+0.05%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#22) 6 6 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences


🚀 Don’t miss a bit, follow what’s new on Codacy.

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Copy link
Member

@jan-janssen jan-janssen left a comment

Choose a reason for hiding this comment

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

Looks good to me

@liamhuber
Copy link
Member

The standard library has this, with the caveat that it redirects all warnings and to a hard coded logger, but it would be possible to setup similar logic in snippets.logger and redirect all warnings or warnings of a certain type to the pyiron logger. The warning type would have to be defined in a shared module somewhere so still link logger and resources.

That's unfortunate. But now playing with it myself and thinking about it more, I really, really don't like invoking the snippets logger here. Anyone hitting this warning will suddenly get a pyiron.log file on their filesystem. This seems uncool for people importing a random (not-logger) class from pyiron_snippets.

An alternative would be something like sticking a ._logger = None attribute on the relevant class and then internally doing an if self._logger is None: warnings.warn(msg); else: self._logger.warning(msg), and manually setting the logger attribute when we're using the class where the pyiron logger is available? I feel this is still ugly, but less evil than writing surprise files for people.

pmrv added 2 commits July 24, 2024 12:07
Avoids creating random files for users who otherwise do not use the logger.
@pmrv
Copy link
Contributor Author

pmrv commented Jul 24, 2024

Agree about the uncleanliness when not using the logger otherwise, so I reverted back to warning. I've added a custom warning type, so that we could potential filter and redirect it to the logger in the future, but I'm not too married to it.

@pmrv pmrv added format_black Trigger the black formatting bot and removed format_black Trigger the black formatting bot labels Jul 24, 2024
@pmrv pmrv merged commit 0089e58 into main Jul 24, 2024
19 checks passed
@pmrv pmrv deleted the warn branch July 24, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request format_black Trigger the black formatting bot
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ResourceResolver: Raise warning when executable matches pattern but the executable bit is not set.
5 participants