chriscz / pysorter

A command line utility for organizing files and directories according to regex patterns.
Mozilla Public License 2.0
44 stars 17 forks source link

Extend rules examples - Fixes #16 #27

Closed astrikos closed 8 years ago

astrikos commented 8 years ago

Is this what you were thinking? I skipped to add example for callables since there is no example yet. I guess as soon as #19 is implemented (I might give it a try later) we can add it then.

coveralls commented 8 years ago

Coverage Status

Coverage remained the same at 96.512% when pulling cb458282c6869a200ece4374828690a6427b0e75 on astrikos:master into 57d9c775711fa8a91b75b022c295441207c76f22 on chriscz:master.

astrikos commented 8 years ago

hm yeah that's not going to work easily. The way you do exec now in rules.py, there shouldn't be any import inside filetype.py file. One possibility would be to have callables like strings (e.g. (r'.cer$', 'action.Skip') ) and and import them using importlib.import_module. I could give it a try see if it works if you think is a way to go. Or maybe you have another solution and I just don't see it :)

chriscz commented 8 years ago

Hey @astrikos,

Would doing an absolute import work instead, or is there a problem with that?. We can assume that developers would have done a pip install -e .

However it may break when doing tests so maybe a hack along the lines of:

try:
    from pysorter import action
except ImportError:
    from . import action

What do you think?

astrikos commented 8 years ago

Hi @chriscz, using absolutely import seems to work, it just breaks consistency throughout the project, which seems to use relative imports (example1, example2). But since it works there is no real need to complicate it more. I will add a comment above import to make sure next one knows that is has to use absolutely imports in this file. Do you want me to squash all commits to one or you prefer to have two different for import and for comment?

chriscz commented 8 years ago

trading consistency for simplicity here should be fine, since this file (will eventually) be viewed and edited by users of pysorter, so it makes sense. A comment would be quite fitting here.

You are free to squash the commits, I haven't developed a preference yet ;). In addition could you rebase on the latest develop branch?

Thanks for contributing, I really appreciate it!

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.01%) to 96.525% when pulling ffbfd8f53688201f28b0efa1bedf3b642e3cb8a6 on astrikos:master into 57d9c775711fa8a91b75b022c295441207c76f22 on chriscz:master.

astrikos commented 8 years ago

okay, squashed everything in one commit and rebase develop branch.