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

Transfer of fasteners dependency to filelock #4800

Merged
merged 54 commits into from
Jan 12, 2025

Conversation

talagayev
Copy link
Member

@talagayev talagayev commented Nov 22, 2024

Fixes #4797

Changes made in this Pull Request:

  • Removal of fasteners dependency from XDR.py and all installation files
  • Addition of filelock as an replacement dependency of fasteners

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

Developers certificate of origin


📚 Documentation preview 📚: https://mdanalysis--4800.org.readthedocs.build/en/4800/

changes fasteners to filelock dependency
changes fasteners to filelock dependency
changes in the action the fasteners dependency to filelock
adjusted input fasteners to filelock
changed fasteners to filelock
changed fasteners to filelock
changed fasteners to filelock
@talagayev talagayev changed the title Transfer of fasteners dependency to fielock Transfer of fasteners dependency to fielock Nov 22, 2024
Copy link

codecov bot commented Nov 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.62%. Comparing base (bdfb2c9) to head (7b580c1).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4800      +/-   ##
===========================================
- Coverage    93.66%   93.62%   -0.05%     
===========================================
  Files          177      189      +12     
  Lines        21795    22861    +1066     
  Branches      3067     3067              
===========================================
+ Hits         20414    21403     +989     
- Misses         929     1006      +77     
  Partials       452      452              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

test _read_offsets adjustment
modification of test_offset_lock_created to adjust to new dependency
returned the warning and read_offsets for tests
required removal of asser_equal to not get the error, since now the files, dont't end with lock and the removal of the end would be a duplicate of the other assert_equal
@talagayev
Copy link
Member Author

@yuxuanzhuang I would ping you since you worked on the XDR.py PR to get your opinion regarding the lines:

https://github.com/talagayev/mdanalysis/blob/b66e3d21680909f4b4a15379d77602090f879fd0/package/MDAnalysis/coordinates/XDR.py#L204-L206

and if they require modification.

Other than that the only problem that I encounter now is the Azure failing, due to Windows runners gw0 and gw1 crashing during the test_persistent_offsets_readonly, which I currently cannot explain.

@orbeckst orbeckst changed the title Transfer of fasteners dependency to fielock Transfer of fasteners dependency to filelock Nov 25, 2024
changed read offsets from True to False, retained the warning
changed and to or pytest warning in test
@talagayev
Copy link
Member Author

@IAlibay I would probably ping you in this PR to get your opinion, due to the problem with test_persistent_offsets_readonly, which has an problem with the Azure pipelines and windows, possibly similar to #4122, can't say how similar that case is to the one that was then, if it was also connected with crashing of runners.

@yuxuanzhuang
Copy link
Contributor

The issue is that filelock hangs when attempting to acquire a lock in Windows.

Refer to the following line of code:
https://github.com/tox-dev/filelock/blob/57f488ff8fdc2193572efe102408fb63cfefe4e4/src/filelock/_windows.py#L28

When the lock file cannot be written in Windows, instead of raising a PermissionError, the library keeps retrying to acquire again:
https://github.com/tox-dev/filelock/blob/57f488ff8fdc2193572efe102408fb63cfefe4e4/src/filelock/_api.py#L329

In contrast, on UNIX systems https://github.com/tox-dev/filelock/blob/57f488ff8fdc2193572efe102408fb63cfefe4e4/src/filelock/_unix.py#L42, if the file cannot be written, the operation fails immediately, raising an appropriate exception.

Not sure why platforms are implemented differently though.

test path modification
add skip exception for azure
@pep8speaks
Copy link

pep8speaks commented Dec 8, 2024

Hello @talagayev! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 990:80: E501 line too long (96 > 79 characters)

Comment last updated at 2025-01-11 15:59:37 UTC

@talagayev
Copy link
Member Author

Sorry for the late reply and not working on the PR, was mainly on holidays and afterwards working on an publication. @yuxuanzhuang I adjusted now the two pytests for test_persistent_offsets_readonly with the mock.patch as you suggested and for test_offset_lock_created it's basically testing if it is locked and then unlocked, tried a couple of versions of this pytest, some led to the file unlocking step taking a lot of time or getting stuck, but this version now works.

Currently the linters / black action fails, thus I ran the parts added through black again, but didn't touch any remainder of test_xdr.py to meddle with the other pytest parts

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

My comments have been addressed. I have one non-blocking question/suggestion. Thanks!!

# Acquire the lock
lock.acquire()

time.sleep(5) # wait 5 seconds before checking if the file is locked
Copy link
Member

Choose a reason for hiding this comment

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

Why did you choose 5 seconds? Could 1s be sufficient — the less time we spend in a test, the better.

Add a comment why delay is needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was debating if to have the sleep overall or not. @yuxuanzhuang suggested 10 seconds, I thought 5 seconds would be the optimum, but yes for tests speed it makes sense to reduce it. Overall now that I see I think that the time.sleep() is overall redundant here, since @yuxuanzhuang meant it in a different sense. So I would tend to remove it overall, since it is not necessary to have it in the test and just makes the test 5 seconds longer

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not exactly the same test as I suggested.

One possible approach could be to spawn a file lock in a separate process for 10 seconds and then verify that the read_offsets function takes more than 10 seconds to complete, indicating it’s waiting for the lock to be released.

I think it’s fine to revert to the original test that simply verifies the creation of the offset lock file.

The other part of the PR looks good to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not exactly the same test as I suggested.

One possible approach could be to spawn a file lock in a separate process for 10 seconds and then verify that the read_offsets function takes more than 10 seconds to complete, indicating it’s waiting for the lock to be released.

I think it’s fine to revert to the original test that simply verifies the creation of the offset lock file.

The other part of the PR looks good to me.

@yuxuanzhuang yes somehow I think I tried it first before the holidays with the separate process, but had troubles implementing it, since I had the case that the tests ran indefinetly and after the holidays the idea of the 10 seconds kinda got lost overtime, which is why the pytest looks different than what you had in mind.

As for reverting you mean reverting back to the current version of the test in the develop branch:

def test_offset_lock_created(self):
assert os.path.exists(
XDR.offsets_filename(self.filename, ending="lock")
)

or any iteration from the previous commits in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

The one in the develop branch.

Copy link
Member Author

Choose a reason for hiding this comment

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

@yuxuanzhuang hm, now the problem appears again regardin the ending="lock" which is not present and thus leads to an error and by removing the ending="lock" it just checks that the file exists but not that it is locked.

Copy link
Contributor

Choose a reason for hiding this comment

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

I’m not sure, but the test was originally checking the existence of lock file for self.filename, whereas it should have been testing self.traj instead. The test passed previously more as a side effect of directly reading offsets from self.filename in the other test.

@talagayev
Copy link
Member Author

My comments have been addressed. I have one non-blocking question/suggestion. Thanks!!

Nice, thank you @orbeckst, the only thing I am not sure about, would be the linters / black (pull_request) failing, is there something I can do about it?

# Acquire the lock
lock.acquire()

time.sleep(5) # wait 5 seconds before checking if the file is locked
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not exactly the same test as I suggested.

One possible approach could be to spawn a file lock in a separate process for 10 seconds and then verify that the read_offsets function takes more than 10 seconds to complete, indicating it’s waiting for the lock to be released.

I think it’s fine to revert to the original test that simply verifies the creation of the offset lock file.

The other part of the PR looks good to me.

Copy link
Contributor

@yuxuanzhuang yuxuanzhuang left a comment

Choose a reason for hiding this comment

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

It appears that the lock file only exists when it is actively locked on Windows machines.

@talagayev
Copy link
Member Author

It appears that the lock file only exists when it is actively locked on Windows machines.

quite an interesting case that it behaves differently on Windows compared to the other systems 🤔

@yuxuanzhuang
Copy link
Contributor

@orbeckst Let me know you need to have another look at this PR, otherwise, I think it is good to get merged.

Extra things need to be done:

Once this PR is getting towards merging, please also

  1. raise an issue to update the User Guide in the Contributing Code section, where the explicit package dependencies are listed — and it would be wonderful if you could then start a PR to address the issue!
  2. raise an issue to update the conda-forge feedstock https://github.com/conda-forge/mdanalysis-feedstock/ to change the package dependencies, specifically the recipe meta.yaml.

@orbeckst
Copy link
Member

All ok from my side.

Please do the follow-up issues.

@talagayev
Copy link
Member Author

@yuxuanzhuang I could raise the Issue for the User Guide, but for the conda-forge I think it makes more sense for you as a coredev to raise the Issue, or do you want to raise both or should I raise both Issues?

@yuxuanzhuang yuxuanzhuang merged commit 6842fd7 into MDAnalysis:develop Jan 12, 2025
22 of 24 checks passed
@yuxuanzhuang
Copy link
Contributor

Thanks @talagayev! I will raise issues in both locations.

@talagayev
Copy link
Member Author

Thanks @talagayev! I will raise issues in both locations.

Perfect, thank you @yuxuanzhuang with helping with the PR and thank you @orbeckst for looking into the PR :)

@talagayev talagayev deleted the fasteners_to_filelock branch January 12, 2025 23:19
@talagayev
Copy link
Member Author

@yuxuanzhuang the Userguide Issue would be quite a fast and straightforward PR. The question would be, should I quickly do it tomorrow or would it be more reasonable to keep it for now in case of GSOC, since I have a feeling that there are not so many beginner friendly PRs left for newcomers currently and the parallelization ones that are not tackled are the ones, that I already tried tackling locally and had struggles to find a solution to get them parallelized, so those would probably be complicated for beginners 🤔

@IAlibay
Copy link
Member

IAlibay commented Jan 13, 2025

@yuxuanzhuang the Userguide Issue would be quite a fast and straightforward PR. The question would be, should I quickly do it tomorrow or would it be more reasonable to keep it for now in case of GSOC, since I have a feeling that there are not so many beginner friendly PRs left for newcomers currently and the parallelization ones that are not tackled are the ones, that I already tried tackling locally and had struggles to find a solution to get them parallelized, so those would probably be complicated for beginners 🤔

Now please - we shouldn't sit on anything that deal with dependencies, especially when it's a non-optional one.

@talagayev
Copy link
Member Author

@yuxuanzhuang the Userguide Issue would be quite a fast and straightforward PR. The question would be, should I quickly do it tomorrow or would it be more reasonable to keep it for now in case of GSOC, since I have a feeling that there are not so many beginner friendly PRs left for newcomers currently and the parallelization ones that are not tackled are the ones, that I already tried tackling locally and had struggles to find a solution to get them parallelized, so those would probably be complicated for beginners 🤔

Now please - we shouldn't sit on anything that deal with dependencies, especially when it's a non-optional one.

Ah I see @yuxuanzhuang already created a PR for it, so all good :)

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.

replace fasteners
5 participants