[Patches] [ python-Patches-784089 ] A program to scan python files and list those require coding

SourceForge.net noreply at sourceforge.net
Tue Apr 5 18:29:33 CEST 2005


Patches item #784089, was opened at 2003-08-06 14:47
Message generated for change (Comment added) made by phd
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=784089&group_id=5470

Category: Demos and tools
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Oleg Broytmann (phd)
Assigned to: Raymond Hettinger (rhettinger)
Summary: A program to scan python files and list those require coding

Initial Comment:
A program to scan python files (recursively) and list
those that require coding directive (pseudocomment)
because there non-ASCII characters in the file
(including comments).

The program treats files as python files if the
extension is .py or there is "python" in the first line
of the file.


----------------------------------------------------------------------

>Comment By: Oleg Broytmann (phd)
Date: 2005-04-05 20:29

Message:
Logged In: YES 
user_id=4799

I've reworked and advanced the patch. See the attached
bzipped tarball.

The pysource.py module exports three functions.
looks_like_python() takes a quick look and recognizes a
Python source file if it is not too big, has .py expension
and has the word "python" in the first line.

The function can_be_compiled() tries to compile the file.

The generator python_files() runs through all paths whether
they are files or directories, descends into directories,
test if all encountered files are python source files and
yield them.

find-nocoding.py now has an option -c to use
can_be_compiled() instead of the default loks_like_python().
The arguments can be files or directories.

There are also 3 simple tests. "find-nocoding.py ." must
find test/test2.py; "find-nocoding.py -c ." must find
test/test2.py and test/test3.py.

----------------------------------------------------------------------

Comment By: Oleg Broytmann (phd)
Date: 2005-03-03 18:42

Message:
Logged In: YES 
user_id=4799

Sorry for my poor English. "Can have" and "may have"...

----------------------------------------------------------------------

Comment By: Oleg Broytmann (phd)
Date: 2005-03-03 18:41

Message:
Logged In: YES 
user_id=4799

Thank you for pointing the regex. I fixed both programs.

But you are wrong about .py extension. A python module
really can only has .py extension, but a python program may
has any, for example, .cgi, or no extension at all.

----------------------------------------------------------------------

Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-03-03 18:35

Message:
Logged In: YES 
user_id=1188172

Also, perhaps there could be another mode of operation in
which the files in question are checked if they need an
encoding declaration anyways.

----------------------------------------------------------------------

Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-03-03 18:18

Message:
Logged In: YES 
user_id=1188172

The script only checks for "-*- coding", while the docs
state that the correct regex is "coding[=:]\s*([-\w.]+)".

In the pysource.py, I don't know if it is useful to open the
file and check the first line for "python". Normally, Python
files should be given the extension .py, so there is a great
probability of false positives.

----------------------------------------------------------------------

Comment By: Oleg Broytmann (phd)
Date: 2004-12-17 22:52

Message:
Logged In: YES 
user_id=4799

Added pysource.py module and an alternative implementation
using the module. The pysource.py module is, probably, of a
general interest and can be added to the standard library.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-10-20 10:04

Message:
Logged In: YES 
user_id=80475

Will make a few cleanups, replace the recursion and fileext
guessing to a glob.glob format, and will add to Tools/scripts.

----------------------------------------------------------------------

Comment By: Oleg Broytmann (phd)
Date: 2004-10-07 11:49

Message:
Logged In: YES 
user_id=4799

And don't forget to make it executable.

----------------------------------------------------------------------

Comment By: A.M. Kuchling (akuchling)
Date: 2004-08-08 01:50

Message:
Logged In: YES 
user_id=11375

So, does something need to be done with this script, like adding it to the 
distribution?


----------------------------------------------------------------------

Comment By: M.-A. Lemburg (lemburg)
Date: 2003-08-06 16:36

Message:
Logged In: YES 
user_id=38388

Thanks.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=784089&group_id=5470


More information about the Patches mailing list