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

Decorator interface for registering processing funcs? #9

Closed
goodboy opened this issue Jan 8, 2016 · 4 comments
Closed

Decorator interface for registering processing funcs? #9

goodboy opened this issue Jan 8, 2016 · 4 comments

Comments

@goodboy
Copy link

goodboy commented Jan 8, 2016

What's your opinion on a using decorators to register processing functions?

It would eliminate the whole needing to have the -f fixer:add_header explicit syntax. Instead you just point to a module and the decorated funcs are auto loaded.

Also the requirement that the module is on the python path could be avoided by a simple import of the file directly

Whatcha think?

@elmotec
Copy link
Owner

elmotec commented Jan 9, 2016

I agree, the -f fixer:add_header is a little cryptic, one needs to remember the syntax and I seem to forget every time.

So if I understand correctly, you propose to pass just a python file like -f path/to/fixer.py that would get loaded (wherever it is) and then use some magic decorator like say @massedit to let the script know about the program.

I'd like to keep the backward compatibility with -f fixer at least (provided fixer is in $PYTHONPATH, but yeah, sounds like a good idea.

@goodboy
Copy link
Author

goodboy commented Jan 10, 2016

Yes exactly. Personally I'd go with a api something like,

@massedit.processor
def my_processing_func(lines, path):
    for line in lines:
        ...

This lets you then do verification at import time with inspect:

  • verify the function signature args
  • verify that the processor is a generator

I can offer up a PR if you'd like.

@elmotec
Copy link
Owner

elmotec commented Jan 18, 2016

Yeah, that sounds good. I was hoping you'd offer :-)

@elmotec
Copy link
Owner

elmotec commented Sep 20, 2017

So I took a different approach and created an option --generate to generate a template fixer.py file.

I found that most of the time the issue was not so much what function I should tell massedit.py to call (I had just created it) but what the callback should look like in the first place.

565bbd3 should fix that problem and allow the user to quickly see how to use massedit.

@elmotec elmotec closed this as completed Sep 20, 2017
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

No branches or pull requests

2 participants