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

Replace print statements with logger #566

Merged
merged 22 commits into from
May 17, 2024
Merged

Conversation

botanical
Copy link
Contributor

@botanical botanical commented May 11, 2024

Addresses #511


📚 Documentation preview 📚: https://earthaccess--566.org.readthedocs.build/en/566/

@botanical
Copy link
Contributor Author

I didn't update the notebooks which also contain print() statements. Should I update those as well? 🤔

@mfisher87
Copy link
Collaborator

Good question! I think the notebooks should probably stay the same.

Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

Looks wonderful, thank you for taking this on! 🤩

A couple nitpicks :) What do you think?

CHANGELOG.md Outdated Show resolved Hide resolved
earthaccess/api.py Outdated Show resolved Hide resolved
earthaccess/store.py Outdated Show resolved Hide resolved
@mfisher87
Copy link
Collaborator

Oo, also, what do you think of enabling ruff ruleset T20 to prevent us from re-introducing print statements?

Copy link
Collaborator

@chuckwondo chuckwondo left a comment

Choose a reason for hiding this comment

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

Hi @botanical! Glad to see your PR! Just a couple of tweaks, please, but otherwise, great start to your getting involved here!

Comment on lines 312 to 313
logger.info("Class components: \n")
logger.info([method for method in dir(self) if method.startswith("_") is False])
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should actually remain print calls.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

3fadd28 fixed!

@chuckwondo
Copy link
Collaborator

Oo, also, what do you think of enabling ruff ruleset T20 to prevent us from re-introducing print statements?

Good call. We would just want to disable this check for the lines in print_help, where we actually do want print, although I'd like to simply remove that method. It seems superfluous, and is not called internally, but perhaps that's a separate issue.

@chuckwondo
Copy link
Collaborator

Oo, also, what do you think of enabling ruff ruleset T20 to prevent us from re-introducing print statements?

@botanical, if you can add this to the PR, that would be great. Note that at a minimum you'll have to pull in the latest changes from main to resolve conflicts in CHANGELOG.md. I recommend pulling the latest from upstream main and rebasing your branch on that, but that's not a requirement.

earthaccess/api.py Outdated Show resolved Hide resolved
earthaccess/auth.py Outdated Show resolved Hide resolved
earthaccess/store.py Outdated Show resolved Hide resolved
earthaccess/store.py Outdated Show resolved Hide resolved
Comment on lines 89 to 96
try:
print(f"Testing S3 credentials for {daac['short-name']}")
logger.info(f"Testing S3 credentials for {daac['short-name']}")
credentials = earthaccess.get_s3_credentials(daac["short-name"])
assertions.assertIsInstance(credentials, dict)
assertions.assertTrue("accessKeyId" in credentials)
except Exception as e:
print(
logger.error(
f"An error occured while trying to fetch S3 credentials for {daac['short-name']}: {e}"
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't be logging messages from test functions. In fact, I suspect the try/except should be removed. If an exception occurs during the test, the test should fail. However, I don't know if this is an exception to that rule (no pun intended).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

botanical@64ec135 it seems intentional to me according to this commit 😯

Copy link
Collaborator

Choose a reason for hiding this comment

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

In fact, I suspect the try/except should be removed.

it seems intentional to me according to this commit 😯

It does still seem weird. But let's be intentional about the scope of this PR :) Can we take this to an issue / discussion?

Copy link
Collaborator

Choose a reason for hiding this comment

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

In fact, I suspect the try/except should be removed.

it seems intentional to me according to this commit 😯

It does still seem weird. But let's be intentional about the scope of this PR :) Can we take this to an issue / discussion?

Sounds good to me. @botanical, would you mind opening a separate issue for this? Also, would you open yet another issue about refactoring loops in tests to instead be parametrized tests (pytest.parametrize, and yes, that is how it's spelled, which is apparently a valid variant of parameterize).

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, that is how it's spelled, which is apparently a valid variant of parameterize

Gets me every time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

tests/unit/test_auth.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@chuckwondo chuckwondo left a comment

Choose a reason for hiding this comment

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

@botanical, sorry, I made a number of individual comments rather than unified review comments.

pyproject.toml Outdated
@@ -127,6 +127,9 @@ src = ["earthaccess", "stubs", "tests"]
[tool.ruff.lint]
extend-select = ["I", "T20"]

[tool.ruff.lint.per-file-ignores]
"earthaccess/search.py" = ["T20"]
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 do not know if this is necessarily what we want but I didn't know how to ignore that we have intentional print statements

earthaccess/search.py:312:9: T201 print found
earthaccess/search.py:313:9: T201 print found

Copy link
Collaborator

Choose a reason for hiding this comment

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

On those lines, you can append a comment like # noqa: T201 :) https://docs.astral.sh/ruff/linter/#error-suppression

Copy link
Collaborator

@chuckwondo chuckwondo left a comment

Choose a reason for hiding this comment

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

@botanical, thanks for the cleanup of the print calls and adding the ruff rule. All looks good, except that I see numerous changes that have already landed on main, so it seems perhaps that your attempt to merge things from main went awry somewhere. For example, .codespellignore already exists on main, but shows up in this PR as an addition (among several other existing changes on main). Can you perhaps rebase your changes onto main? Happy to jump on a call to help sort it out if wrangling the commits gets gnarly.

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@mfisher87 mfisher87 left a comment

Choose a reason for hiding this comment

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

Thanks so much @botanical 🤩

@chuckwondo (or anyone else) if you don't have any last thoughts I'll merge tomorrow!

Copy link
Collaborator

@chuckwondo chuckwondo left a comment

Choose a reason for hiding this comment

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

Awesome!

@chuckwondo
Copy link
Collaborator

Thanks so much @botanical 🤩

@chuckwondo (or anyone else) if you don't have any last thoughts I'll merge tomorrow!

@mfisher87, I'd like for us to use "Squash and merge" as a matter of habit. That's what I've been doing for PRs, as it keep the commit history much cleaner, unless there's an objection to that approach.

@jhkennedy
Copy link
Collaborator

That's what I've been doing for PRs, as it keep the commit history much cleaner, unless there's an objection to that approach.

This could be a whole 🔥-war discussion 🤣 and it's come up on slack before, but for Earthaccess I think squash-merging matches the current development/release workflow the best.

I think we should disable all but 1 way to merge personally, so there's no question:
image

@mfisher87
Copy link
Collaborator

I think we can call this mergeable, and squash it is! Thanks again @botanical 🙇

I don't have strong feelings about merge strategy, but I do feel strongly let's take it over here #348 :)

@mfisher87 mfisher87 merged commit 98a0549 into nsidc:main May 17, 2024
11 checks passed
@mfisher87 mfisher87 mentioned this pull request May 17, 2024
@mfisher87 mfisher87 linked an issue May 21, 2024 that may be closed by this pull request
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.

Add logging module usage in place of print calls
4 participants