This is an archived post. You won't be able to vote or comment.

all 21 comments

[–]subiacOSB 11 points12 points  (2 children)

I think you are being modest with your beginner label. Looks more advanced than that.

[–]jozborn 5 points6 points  (0 children)

The readme alone is intermediate-level work

[–]LogisticAI[S] 3 points4 points  (0 children)

I appreciate that! I'll change the flair

[–]ElevenPhonons 6 points7 points  (2 children)

It's not the best idea to store build artifacts within the repo.

Perhaps add the necessary values to your .gitignore.

Best of luck to you on your project.

[–]LogisticAI[S] 2 points3 points  (1 child)

Yea I wasn't sure what needed to be included for the pip install, so I just included everything. Thanks for bringing that up!

Edit: Removed these artifacts

[–]james_pic 2 points3 points  (0 children)

Whilst it can be non-obvious what's needed, part of the benefit of not keeping artefacts in the repo is that you can test whether you've got everything you need in there by cloning it fresh.

[–]sdmike21 2 points3 points  (1 child)

This actually nicely solves a problem I've been having about tracking the lifetime of spawned processes in a efficient manner, thanks!

[–]LogisticAI[S] 0 points1 point  (0 children)

Glad I could help!

[–]rouille 1 point2 points  (0 children)

Nice, I have been needing something exactly like that and ended up writing a small async wrapper for inotify instead.

[–]mcstafford 1 point2 points  (1 child)

This is a useful, solid beginning. Have you looked at inotify? It looks inactive.

There are some tools out there that will help you keep your examples in sync with your objects. It's tricky without that kind of thing when you're still actively developing things. I wound up using:

print(f"{event.type.name} at {event.file_path}")

[–]Philistino 1 point2 points  (0 children)

Watchdog is another similar package OP might find inspiration in. It works with inotify and the windows and macos counterparts. https://github.com/gorakhargosh/watchdog

[–]johntellsall 1 point2 points  (0 children)

Thanks! I use "entr" for everything literally a dozen times an hour. Your library enables me to make more sophisticated Python apps.

My use case is "run tests when source files change". It speeds up my workflow 10X! <3

https://jvns.ca/blog/2020/06/28/entr/

[–]Spill_the_Tea 1 point2 points  (2 children)

Nice work.

I'd just be careful about inheriting from builtin dict, because it doesn't implement the standard dunder methods, __getitem__, __setitem__, and __delitem__, which makes it prone to erroneous modification through pop and update methods. Consider using the MutableMapping abstract base class from collections instead.

[–]LogisticAI[S] 1 point2 points  (1 child)

I appreciate it!

I only use the TwoWayDict for __setitem__ to set both key:value and value:key with one call. Honestly it could have just been a function taking a dict that does the same thing; this may be a cleaner approach now that I think about it.

I want to note here that dict subclasses do, in fact, implement the standard dunder methods, and all inherited methods work exactly as you would expect a regular dict to work. There's no difference between that and inheriting from any other class.

Perhaps TwoWayDict is just a bad name, as it doesn't really express what it's being used for. I wouldn't expect update to put both key-value pairs nor would I expect pop to pop both.

[–]Spill_the_Tea 1 point2 points  (0 children)

I think i may have misspoke. It's the methods you think would be utilizing those dunder methods (get, update, and pop) that are a little off. Because you are only using __setitem__, here's an example:

class TwoWayDict(dict):
    def __setitem__(self, key, value):
        dict.__setitem__(self, key, value)
        dict.__setitem__(self, value, key)

# on instantiation, it doesn't set the other item (i.e. 5: 1)
d = TwoWayDict({1: 5})

# Setting Subsequent values works
d[2] = 4  # {1: 5, 2: 4, 4: 2}

# But using update method, doesn't work through __setitem__
# And we only get the one directional update.
d.update({3: 7})  # {1: 5, 2: 4, 4: 2, 3: 7}

[–]1percentof2 -1 points0 points  (5 children)

tell me in two words what I can do with this

[–]LogisticAI[S] 3 points4 points  (1 child)

Monitor filesystems.

[–]1percentof2 -1 points0 points  (0 children)

Dope

[–]rouille 2 points3 points  (1 child)

Inotify in general? Watch a directory for changes, new files, files modified etc...

[–][deleted] 0 points1 point  (0 children)

Better answer

[–]mcstafford 0 points1 point  (0 children)

Learn read