Patches item #784089, was opened at 2003-08-06 12:47 Message generated for change (Comment added) made by birkenfeld You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=784089&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Demos and tools Group: Python 2.5 >Status: Closed Resolution: Accepted Priority: 5 Submitted By: Oleg Broytmann (phd) Assigned to: Reinhold Birkenfeld (birkenfeld) 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: Reinhold Birkenfeld (birkenfeld) Date: 2005-08-24 20:31 Message: Logged In: YES user_id=1188172 Committed both modules to Tools/scripts after a bit of cleanup. ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2005-08-24 09:19 Message: Logged In: YES user_id=80475 Apply only to Py2.5. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2005-04-05 18: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 16: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 16: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 16: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 16: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 20: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 08: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 09: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-07 23: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 14: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 _______________________________________________ Patches mailing list [email protected] http://mail.python.org/mailman/listinfo/patches
