Skip to content

Commit 90721d7

Browse files
authored
Merge pull request #48 from malthe/modernize-repo
Modernize repo
2 parents 027079b + cd11299 commit 90721d7

File tree

8 files changed

+417
-179
lines changed

8 files changed

+417
-179
lines changed

.github/workflows/main.yml

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
on:
2+
push:
3+
pull_request:
4+
# Allow to run this workflow manually from the Actions tab
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
runs-on: macos-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- run: python -m pip install setuptools wheel
13+
- run: python setup.py sdist
14+
- run: python setup.py bdist_wheel
15+
- uses: actions/upload-artifact@v4
16+
with:
17+
name: MacFSEvents
18+
path: ./dist/
19+
test:
20+
strategy:
21+
# We want to see all failures:
22+
fail-fast: false
23+
matrix:
24+
config:
25+
- ["3.8", "py38", "macos-12"]
26+
- ["3.9", "py38", "macos-12"]
27+
- ["3.9", "lint", "macos-12"]
28+
- ["3.9", "py39", "macos-12"]
29+
- ["3.10", "py310", "macos-12"]
30+
- ["3.11", "py311", "macos-12"]
31+
- ["3.12", "py312", "macos-12"]
32+
- ["3.12", "py312", "macos-13"]
33+
- ["3.12", "py312", "macos-14"]
34+
runs-on: ${{ matrix.config[2] }}
35+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
36+
name: ${{ matrix.config[0] }}-${{ matrix.config[1] }}-${{ matrix.config[2] }}
37+
steps:
38+
- run: git config --global core.autocrlf false
39+
- uses: actions/checkout@v3
40+
- name: Set up Python
41+
uses: actions/setup-python@v4
42+
with:
43+
python-version: ${{ matrix.config[0] }}
44+
- name: Pip cache
45+
uses: actions/cache@v3
46+
with:
47+
path: ~/.cache/pip
48+
key: ${{ runner.os }}-pip-${{ matrix.config[0] }}-${{ hashFiles('setup.*', 'tox.ini') }}
49+
restore-keys: |
50+
${{ runner.os }}-pip-${{ matrix.config[0] }}-
51+
${{ runner.os }}-pip-
52+
- name: Install dependencies
53+
run: |
54+
python -m pip install --upgrade pip
55+
pip install tox
56+
- name: Test
57+
run: tox -e ${{ matrix.config[1] }}

.travis.yml

-18
This file was deleted.

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.py
2+
include tox.ini

fsevents.py

+106-69
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,57 @@
44
import unicodedata
55

66
from _fsevents import (
7-
loop,
8-
stop,
9-
schedule,
10-
unschedule,
11-
CF_POLLIN,
12-
CF_POLLOUT,
13-
FS_IGNORESELF,
14-
FS_FILEEVENTS,
15-
FS_ITEMCREATED,
16-
FS_ITEMREMOVED,
17-
FS_ITEMINODEMETAMOD,
18-
FS_ITEMRENAMED,
19-
FS_ITEMMODIFIED,
20-
FS_ITEMFINDERINFOMOD,
21-
FS_ITEMCHANGEOWNER,
22-
FS_ITEMXATTRMOD,
23-
FS_ITEMISFILE,
24-
FS_ITEMISDIR,
25-
FS_ITEMISSYMLINK,
7+
FS_CFLAGFILEEVENTS,
8+
FS_CFLAGNONE,
269
FS_EVENTIDSINCENOW,
2710
FS_FLAGEVENTIDSWRAPPED,
28-
FS_FLAGNONE,
2911
FS_FLAGHISTORYDONE,
30-
FS_FLAGROOTCHANGED,
3112
FS_FLAGKERNELDROPPED,
32-
FS_FLAGUNMOUNT,
3313
FS_FLAGMOUNT,
34-
FS_FLAGUSERDROPPED,
3514
FS_FLAGMUSTSCANSUBDIRS,
36-
FS_CFLAGFILEEVENTS,
37-
FS_CFLAGNONE,
38-
FS_CFLAGIGNORESELF,
39-
FS_CFLAGUSECFTYPES,
40-
FS_CFLAGNODEFER,
41-
FS_CFLAGWATCHROOT,
15+
FS_FLAGROOTCHANGED,
16+
FS_FLAGUNMOUNT,
17+
FS_FLAGUSERDROPPED,
18+
FS_ITEMCHANGEOWNER,
19+
FS_ITEMCREATED,
20+
FS_ITEMFINDERINFOMOD,
21+
FS_ITEMINODEMETAMOD,
22+
FS_ITEMISDIR,
23+
FS_ITEMISFILE,
24+
FS_ITEMISSYMLINK,
25+
FS_ITEMMODIFIED,
26+
FS_ITEMREMOVED,
27+
FS_ITEMRENAMED,
28+
FS_ITEMXATTRMOD,
29+
loop,
30+
schedule,
31+
stop,
32+
unschedule
4233
)
4334

35+
4436
class Mask(int):
4537
stringmap = {
46-
FS_FLAGMUSTSCANSUBDIRS: 'MustScanSubDirs',
47-
FS_FLAGUSERDROPPED: 'UserDropped',
48-
FS_FLAGKERNELDROPPED: 'KernelDropped',
49-
FS_FLAGEVENTIDSWRAPPED: 'EventIDsWrapped',
50-
FS_FLAGHISTORYDONE: 'HistoryDone',
51-
FS_FLAGROOTCHANGED: 'RootChanged',
52-
FS_FLAGMOUNT: 'Mount',
53-
FS_FLAGUNMOUNT: 'Unmount',
54-
38+
FS_FLAGMUSTSCANSUBDIRS: "MustScanSubDirs",
39+
FS_FLAGUSERDROPPED: "UserDropped",
40+
FS_FLAGKERNELDROPPED: "KernelDropped",
41+
FS_FLAGEVENTIDSWRAPPED: "EventIDsWrapped",
42+
FS_FLAGHISTORYDONE: "HistoryDone",
43+
FS_FLAGROOTCHANGED: "RootChanged",
44+
FS_FLAGMOUNT: "Mount",
45+
FS_FLAGUNMOUNT: "Unmount",
5546
# Flags when creating the stream.
56-
FS_ITEMCREATED: 'ItemCreated',
57-
FS_ITEMREMOVED: 'ItemRemoved',
58-
FS_ITEMINODEMETAMOD: 'ItemInodeMetaMod',
59-
FS_ITEMRENAMED: 'ItemRenamed',
60-
FS_ITEMMODIFIED: 'ItemModified',
61-
FS_ITEMFINDERINFOMOD: 'ItemFinderInfoMod',
62-
FS_ITEMCHANGEOWNER: 'ItemChangedOwner',
63-
FS_ITEMXATTRMOD: 'ItemXAttrMod',
64-
FS_ITEMISFILE: 'ItemIsFile',
65-
FS_ITEMISDIR: 'ItemIsDir',
66-
FS_ITEMISSYMLINK: 'ItemIsSymlink'
47+
FS_ITEMCREATED: "ItemCreated",
48+
FS_ITEMREMOVED: "ItemRemoved",
49+
FS_ITEMINODEMETAMOD: "ItemInodeMetaMod",
50+
FS_ITEMRENAMED: "ItemRenamed",
51+
FS_ITEMMODIFIED: "ItemModified",
52+
FS_ITEMFINDERINFOMOD: "ItemFinderInfoMod",
53+
FS_ITEMCHANGEOWNER: "ItemChangedOwner",
54+
FS_ITEMXATTRMOD: "ItemXAttrMod",
55+
FS_ITEMISFILE: "ItemIsFile",
56+
FS_ITEMISDIR: "ItemIsDir",
57+
FS_ITEMISSYMLINK: "ItemIsSymlink",
6758
}
6859

6960
_svals = list(stringmap.items())
@@ -96,7 +87,8 @@ def check_path_string_type(*paths):
9687
for path in paths:
9788
if not isinstance(path, str):
9889
raise TypeError(
99-
"Path must be string, not '%s'." % type(path).__name__)
90+
"Path must be string, not '%s'." % type(path).__name__
91+
)
10092

10193

10294
class Observer(threading.Thread):
@@ -138,16 +130,25 @@ def _schedule(self, stream):
138130
if stream.file_events:
139131
callback = FileEventCallback(stream.callback, stream.raw_paths)
140132
else:
133+
141134
def callback(paths, masks, ids):
142135
for path, mask, id in zip(paths, masks, ids):
143136
if sys.version_info[0] >= 3:
144-
path = path.decode('utf-8')
137+
path = path.decode("utf-8")
145138
if stream.ids is False:
146139
stream.callback(path, mask)
147140
elif stream.ids is True:
148141
stream.callback(path, mask, id)
149-
150-
schedule(self, stream, callback, stream.paths, stream.since, stream.latency, stream.cflags)
142+
143+
schedule(
144+
self,
145+
stream,
146+
callback,
147+
stream.paths,
148+
stream.since,
149+
stream.latency,
150+
stream.cflags,
151+
)
151152

152153
def schedule(self, stream):
153154
self.lock.acquire()
@@ -181,23 +182,26 @@ def stop(self):
181182
self.event = None
182183
event.set()
183184

185+
184186
class Stream(object):
185187
def __init__(self, callback, *paths, **options):
186-
file_events = options.pop('file_events', False)
187-
since = options.pop('since',FS_EVENTIDSINCENOW)
188-
cflags = options.pop('flags', FS_CFLAGNONE)
189-
latency = options.pop('latency', 0.01)
190-
ids = options.pop('ids', False)
191-
assert len(options) == 0, "Invalid option(s): %s" % repr(options.keys())
188+
file_events = options.pop("file_events", False)
189+
since = options.pop("since", FS_EVENTIDSINCENOW)
190+
cflags = options.pop("flags", FS_CFLAGNONE)
191+
latency = options.pop("latency", 0.01)
192+
ids = options.pop("ids", False)
193+
assert len(options) == 0, "Invalid option(s): %s" % repr(
194+
options.keys()
195+
)
192196
check_path_string_type(*paths)
193197

194198
self.callback = callback
195199
self.raw_paths = paths
196200

197201
# The C-extension needs the path in 8-bit form.
198202
self.paths = [
199-
path if isinstance(path, bytes)
200-
else path.encode('utf-8') for path in paths
203+
path if isinstance(path, bytes) else path.encode("utf-8")
204+
for path in paths
201205
]
202206

203207
self.file_events = file_events
@@ -206,8 +210,9 @@ def __init__(self, callback, *paths, **options):
206210
self.latency = latency
207211
self.ids = ids
208212

213+
209214
class FileEvent(object):
210-
__slots__ = 'mask', 'cookie', 'name'
215+
__slots__ = "mask", "cookie", "name"
211216

212217
def __init__(self, mask, cookie, name):
213218
self.mask = mask
@@ -217,6 +222,7 @@ def __init__(self, mask, cookie, name):
217222
def __repr__(self):
218223
return repr((self.mask, self.cookie, self.name))
219224

225+
220226
class FileEventCallback(object):
221227
def __init__(self, callback, paths):
222228
self.snapshots = {}
@@ -234,13 +240,13 @@ def __call__(self, paths, masks, ids):
234240
for path in sorted(paths):
235241
# supports UTF-8-MAC(NFD)
236242
if not isinstance(path, unicode):
237-
path = path.decode('utf-8')
238-
path = unicodedata.normalize('NFD', path).encode('utf-8')
243+
path = path.decode("utf-8")
244+
path = unicodedata.normalize("NFD", path).encode("utf-8")
239245

240246
if sys.version_info[0] >= 3:
241-
path = path.decode('utf-8')
242-
243-
path = path.rstrip('/')
247+
path = path.decode("utf-8")
248+
249+
path = path.rstrip("/")
244250
snapshot = self.snapshots[path]
245251
current = {}
246252
try:
@@ -265,13 +271,15 @@ def __call__(self, paths, masks, ids):
265271
observed.discard(name)
266272
else:
267273
event = created.get(snap_stat.st_ino)
268-
if (event is not None):
274+
if event is not None:
269275
self.cookie += 1
270276
event.mask = IN_MOVED_FROM
271277
event.cookie = self.cookie
272278
tmp_filename = event.name
273279
event.name = filename
274-
events.append(FileEvent(IN_MOVED_TO, self.cookie, tmp_filename))
280+
events.append(
281+
FileEvent(IN_MOVED_TO, self.cookie, tmp_filename)
282+
)
275283
else:
276284
event = FileEvent(IN_DELETE, None, filename)
277285
deleted[snap_stat.st_ino] = event
@@ -313,3 +321,32 @@ def snapshot(self, path):
313321
entry[obj] = os.lstat(os.path.join(root, obj))
314322
except OSError:
315323
continue
324+
325+
326+
__all__ = (
327+
FS_CFLAGFILEEVENTS,
328+
FS_CFLAGNONE,
329+
FS_EVENTIDSINCENOW,
330+
FS_FLAGEVENTIDSWRAPPED,
331+
FS_FLAGHISTORYDONE,
332+
FS_FLAGKERNELDROPPED,
333+
FS_FLAGMOUNT,
334+
FS_FLAGMUSTSCANSUBDIRS,
335+
FS_FLAGROOTCHANGED,
336+
FS_FLAGUNMOUNT,
337+
FS_FLAGUSERDROPPED,
338+
FS_ITEMCHANGEOWNER,
339+
FS_ITEMCREATED,
340+
FS_ITEMFINDERINFOMOD,
341+
FS_ITEMINODEMETAMOD,
342+
FS_ITEMISDIR,
343+
FS_ITEMISFILE,
344+
FS_ITEMISSYMLINK,
345+
FS_ITEMMODIFIED,
346+
FS_ITEMREMOVED,
347+
FS_ITEMRENAMED,
348+
FS_ITEMXATTRMOD,
349+
FileEvent,
350+
Stream,
351+
Observer,
352+
)

pyproject.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[tool.black]
2+
line-length = 79
3+
4+
[tool.isort]
5+
multi_line_output=3

0 commit comments

Comments
 (0)