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 it easier to use as a module rather than a script #35

Closed
treelinelabs opened this issue Sep 2, 2011 · 11 comments
Closed

Make it easier to use as a module rather than a script #35

treelinelabs opened this issue Sep 2, 2011 · 11 comments

Comments

@treelinelabs
Copy link

For writing (say) git/hg hooks, it'd much more convenient to be able to import pep8 as a module and use it inline, rather than having to shell out to run it as a script, capture and parse the output, etc.

This would require some fairly non-trivial changes -- e.g. there's currently lots of inline printing and a global options variable -- and there would be some api decisions to make.

I might take a look at putting together a pull request if there is interest...is there?

@mjumbewu
Copy link

mjumbewu commented Sep 9, 2011

I'm interested and was in fact about to take a look at that myself (which is why I was checking the issues).

@treelinelabs
Copy link
Author

I started on this, but the requisite changes were rather extensive, and I decided I need to take some time to think through what an appropriate approach is.

@florentx
Copy link
Contributor

florentx commented Jun 2, 2012

See also the current possibilities which are summarized on issue #66.
#66 (comment)

@florentx florentx closed this as completed Jun 2, 2012
@josharian
Copy link

#66 appears to offer a functional work-around.

I just have to say, though, that it's not really a happy thing to have to choose between shelling out (PITA), monkey patching stdout (ugh), and subclassing (fragile, ugly). And it'd be much cleaner not to have to call pep8.process_options with a set of constructed strings.

I hope that this was closed as a duplicate of #66, not as a wontfix.

(And lest I appear just a grumpy troll who's complaining about free stuff, I should note that I have put days of work into a branch of pep8, trying to fix these issues, and that I wrote and maintain lumberlabs/pygithooks, which uses pep8 under the hood. I care, which is why I'm being vocal.)

@florentx florentx reopened this Jun 4, 2012
@florentx
Copy link
Contributor

florentx commented Jun 4, 2012

I consider there's interest in some enhancement.

@florentx
Copy link
Contributor

Upcoming release should fix it, at the cost of backward incompatibility.
Please test.

@florentx
Copy link
Contributor

Sample use:

import pep8

pep8style = pep8.StyleGuide(quiet=True)
result = pep8style.check_files(['testsuite/E27.py', 'testsuite/E12.py'])

print("Found %s errors (and warnings)" % result.total_errors)

There's a shortcut when checking a single file.

import pep8

fchecker = pep8.Checker('testsuite/E27.py', show_source=True)
file_errors = fchecker.check_all()

print("Found %s errors (and warnings)" % file_errors)

@josharian
Copy link

Awesome! I'll play with this soon and get it integrated. Many, many thanks.

@JensRantil
Copy link
Contributor

This is great news! Will this API be documented somewhere, too?

@florentx
Copy link
Contributor

Patch accepted :-)

See issue #105

@JensRantil
Copy link
Contributor

Fair enough. I'll see what I can come up with :-)

JensRantil added a commit to JensRantil/pep8 that referenced this issue Jul 26, 2012
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

5 participants