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

Make lock file compatible with S3 FileSystem #114

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion fasteners/process_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from typing import Callable
from typing import Optional
from typing import Union
from s3fs import S3FileSystem

from fasteners import _utils
from fasteners.process_mechanism import _interprocess_mechanism
Expand Down Expand Up @@ -79,6 +80,14 @@ def __init__(self,
self.acquired = False
self.sleep_func = sleep_func
self.logger = _utils.pick_first_not_none(logger, LOG)
if self.path.startswith("s3://"):
self._open = S3FileSystem(
endpoint_url=os.environ["AWS_ENDPOINT_URL"],
key=os.environ["AWS_ACCESS_KEY_ID"],
secret=os.environ["AWS_SECRET_ACCESS_KEY"]
).open
else:
self._open = open

def _try_acquire(self, blocking, watch):
try:
Expand Down Expand Up @@ -111,7 +120,7 @@ def _do_open(self):
# the target file. This eliminates the possibility of an attacker
# creating a symlink to an important file in our lock path.
if self.lockfile is None or self.lockfile.closed:
self.lockfile = open(self.path, 'a')
self.lockfile = self._open(self.path, 'a')

def acquire(self,
blocking: bool = True,
Expand Down
1 change: 1 addition & 0 deletions requirements-pkg.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build
twine
s3fs