msg44389 - (view) |
Author: Oleg Broytman (phd) * |
Date: 2003-08-06 10:47 |
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. |
|
|
msg44390 - (view) |
Author: Marc-Andre Lemburg (lemburg) *  |
Date: 2003-08-06 12:36 |
Logged In: YES user_id=38388 Thanks. |
|
|
msg44391 - (view) |
Author: A.M. Kuchling (akuchling) *  |
Date: 2004-08-07 21:50 |
Logged In: YES user_id=11375 So, does something need to be done with this script, like adding it to the distribution? |
|
|
msg44392 - (view) |
Author: Oleg Broytman (phd) * |
Date: 2004-10-07 07:49 |
Logged In: YES user_id=4799 And don't forget to make it executable. |
|
|
msg44393 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2004-10-20 06:04 |
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. |
|
|
msg44394 - (view) |
Author: Oleg Broytman (phd) * |
Date: 2004-12-17 19:52 |
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. |
|
|
msg44395 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2005-03-03 15:18 |
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. |
|
|
msg44396 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2005-03-03 15:35 |
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. |
|
|
msg44397 - (view) |
Author: Oleg Broytman (phd) * |
Date: 2005-03-03 15:41 |
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. |
|
|
msg44398 - (view) |
Author: Oleg Broytman (phd) * |
Date: 2005-03-03 15:42 |
Logged In: YES user_id=4799 Sorry for my poor English. "Can have" and "may have"... |
|
|
msg44399 - (view) |
Author: Oleg Broytman (phd) * |
Date: 2005-04-05 16:29 |
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. |
|
|
msg44400 - (view) |
Author: Raymond Hettinger (rhettinger) *  |
Date: 2005-08-24 07:19 |
Logged In: YES user_id=80475 Apply only to Py2.5. |
|
|
msg44401 - (view) |
Author: Georg Brandl (georg.brandl) *  |
Date: 2005-08-24 18:31 |
Logged In: YES user_id=1188172 Committed both modules to Tools/scripts after a bit of cleanup. |
|
|