Importing and using pep8.py from another python module

268 visualizações
Pular para a primeira mensagem não lida

Sym

não lida,
18 de nov. de 2009, 06:04:0118/11/2009
para pep8
Hi,

Sorry if this is not the place to ask...seems no one else is using
this mailing list...

I'm trying to import pep8.py and use it in my own module. What I
really want to do is call the tests on arbitrary strings and get the
results returned for use later.

Is this possible? I've had a go at using pep8.Checker(), but I ran in
to problems with the optparser not being set up. I know I could call
pep8 in a subprocess and parse the output, but that seems a really
messy way of doing it!

Thanks,

Sym

Reinout van Rees

não lida,
18 de nov. de 2009, 07:41:5918/11/2009
para pe...@googlegroups.com
On Wed, Nov 18, 2009 at 12:04 PM, Sym <simo...@gmail.com> wrote:
>
> Sorry if this is not the place to ask...seems no one else is using
> this mailing list...

This is the right place. We only set up the mailing list last week :-)

> I'm trying to import pep8.py and use it in my own module.  What I
> really want to do is call the tests on arbitrary strings and get the
> results returned for use later.
>
> Is this possible?  I've had a go at using pep8.Checker(), but I ran in
> to problems with the optparser not being set up.  I know I could call
> pep8 in a subprocess and parse the output, but that seems a really
> messy way of doing it!

You could try calling process_options(arglist=None) to set up the
options with their defaults first.I haven't tried it, but looking at
the code, this should at least fix the optparse problem.

The code atm isn't really set up for use as a library, though it would
not be hard to fix that.


Reinout

--
Reinout van Rees - rei...@vanrees.org
http://reinout.vanrees.org/ - http://www.thehealthagency.com
"I can be googled, therefore I am."

Simon Roe

não lida,
18 de nov. de 2009, 07:56:2618/11/2009
para pe...@googlegroups.com
On Wed, Nov 18, 2009 at 12:41 PM, Reinout van Rees <rei...@vanrees.org> wrote:
> On Wed, Nov 18, 2009 at 12:04 PM, Sym <simo...@gmail.com> wrote:

> You could try calling process_options(arglist=None) to set up the
> options with their defaults first.I haven't tried it, but looking at
> the code, this should at least fix the optparse problem.
>
> The code atm isn't really set up for use as a library, though it would
> not be hard to fix that.

Thanks for the reply.

Since I posted I found the following worked:

arglist =['-qq', filepath]
pep8.process_options(arglist)
pep8.input_file(filepath)
error_stats = pep8.get_error_statistics()
warning_stats = pep8.get_warning_statistics()

Although it's not the most intuitive API, it's fine for my needs, and
as you say it's not really designed for use as a library.

I'm writing this for a slightly odd online code writing project I'm
working on, but I'm also creating a commit hook for mercurial that
will run pep8 against the changed code. If there is any interest in
this, I'll gladly shove it up somewhere.

Thanks again,

Sym


--
E: sym...@talusdesign.co.uk
M: 07742079314

Stefano Costa

não lida,
3 de dez. de 2009, 12:08:2403/12/2009
para pep8
On 18 Nov, 13:56, Simon Roe <simon....@gmail.com> wrote:

> I'm writing this for a slightly odd online code writing project I'm
> working on, but I'm also creating a commit hook for mercurial that
> will run pep8 against the changed code.  If there is any interest in
> this, I'll gladly shove it up somewhere.

I would be interested in the mercurial commit hook. Today I found this
http://www.selenic.com/pipermail/mercurial/2009-August/027069.html but
I really can't make it work following the given hgrc settings.

Thanks,
steko
Responder a todos
Responder ao autor
Encaminhar
0 nova mensagem