style: fix flake8 error for tools.py by zmx27 · Pull Request #9 · diffpy/diffpy.srxconfutils · GitHub
Skip to content

style: fix flake8 error for tools.py#9

Merged
sbillinge merged 4 commits into
diffpy:migrationfrom
zmx27:fix-flake8-tools
Sep 20, 2025
Merged

style: fix flake8 error for tools.py#9
sbillinge merged 4 commits into
diffpy:migrationfrom
zmx27:fix-flake8-tools

Conversation

@zmx27

@zmx27 zmx27 commented Sep 10, 2025

Copy link
Copy Markdown
Collaborator

No description provided.

@zmx27

zmx27 commented Sep 10, 2025

Copy link
Copy Markdown
Collaborator Author

@sbillinge sbillinge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pls see comments

Comment thread src/diffpy/srxconfutils/tools.py Outdated
@@ -171,7 +171,7 @@ def checkCRC32(filename):
"""
try:
fd = open(filename, "rb")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Its probably a good idea to bring this all up to our general standards, not just flake8 (e.g., in this case, using context manager for file reads). On the minus side, it makes these flinting corrections go more slowly but on the plus side, these are hard to find later and fix if we don't fix them when we find them. An alternative is to put a # fixme and then have an issue that later goes back and cleans the fixme's

Comment thread src/diffpy/srxconfutils/tools.py Outdated
try:
fd = open(filename, "rb")
except:
except Exception:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would prefer a more precise exception here, and maybe a more robust way of handling it? Returning some random string? What does other code that call this function do with this string?

@zmx27

zmx27 commented Sep 17, 2025

Copy link
Copy Markdown
Collaborator Author

@sbillinge ready for review

@sbillinge sbillinge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good. Let's take the opportunity to write a test for this. Also make the function name pep8 compliant (lower-case)

@zmx27

zmx27 commented Sep 18, 2025

Copy link
Copy Markdown
Collaborator Author

@sbillinge ready for review

@sbillinge sbillinge left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please see comments. I think if we just move the tmpfile to conftest then I can merge.

Comment thread tests/test_tools.py Outdated
from diffpy.srxconfutils import tools


@pytest.fixture

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

arguably we might want to put this in conftest.py so it is available to all tests, or something like it that can be extended in each test.

Comment thread tests/test_tools.py Outdated
return file_path, content


def test_check_md5(temp_file):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would guess that a function called "check_md5would return True or False. If it returns an md5, then maybeget_md5`? but since doing that is one line why do we need a function? Is it that it takes a path and then finds a file and returns its hash?

We could handle all this a bit better but it is probably not worth spending the time at this point. Thanks for writing this test at least. I will merge it like this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

You're right, I believe that get_md5 would make more sense for the function name. From what I understand, the purpose of the function is that it handles reading large files in chunks and wraps errors nicely. I will also rename the check_crc32 function`.

@zmx27

zmx27 commented Sep 19, 2025

Copy link
Copy Markdown
Collaborator Author

@sbillinge ready for review

@sbillinge sbillinge merged commit dc66eef into diffpy:migration Sep 20, 2025
@sbillinge sbillinge deleted the fix-flake8-tools branch September 20, 2025 10:32
@sbillinge

Copy link
Copy Markdown
Contributor

super, this looks great, I merged. btw, did you do the test that this didn't break anything?

If, as you mention, these tools are used to help with file chunking, it is probably worth spending a few minutes to see if there are packages for this, as this is a very standard task done by everyone. For example, since we are using gcp, we could use tools in google-cloud-storage package.

@zmx27

zmx27 commented Sep 20, 2025

Copy link
Copy Markdown
Collaborator Author

Yes, I did do the test to make sure that this didn't break anything. However, I'm not very familiar with gcp or the google-cloud-storage package. Do you want me to look into these and find out how I can implement them into our code?

@sbillinge

Copy link
Copy Markdown
Contributor

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