Patchwork import-checker: accept .pyc and .pyo files (issue4812)

login
register
mail settings
Submitter timeless@mozdev.org
Date Sept. 2, 2015, 8:16 p.m.
Message ID <db4607bedf0785a1c49b.1441224960@waste.org>
Download mbox | patch
Permalink /patch/10372/
State Accepted
Headers show

Comments

timeless@mozdev.org - Sept. 2, 2015, 8:16 p.m.
# HG changeset patch
# User timeless@mozdev.org
# Date 1441224455 14400
#      Wed Sep 02 16:07:35 2015 -0400
# Node ID db4607bedf0785a1c49bdf53544cf8548fe4cac7
# Parent  f77a3f27cea533232dc107a72773e90e2de9549d
import-checker: accept .pyc and .pyo files (issue4812)

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin

$ ls '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6'/BaseHTTPServer.py*
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.pyc
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.pyo
Augie Fackler - Sept. 2, 2015, 8:28 p.m.
> On Sep 2, 2015, at 16:16, timeless@mozdev.org wrote:
> 
> # HG changeset patch
> # User timeless@mozdev.org
> # Date 1441224455 14400
> #      Wed Sep 02 16:07:35 2015 -0400
> # Node ID db4607bedf0785a1c49bdf53544cf8548fe4cac7
> # Parent  f77a3f27cea533232dc107a72773e90e2de9549d
> import-checker: accept .pyc and .pyo files (issue4812)

queued, thanks

> 
> Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
> [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
> 
> $ ls '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6'/BaseHTTPServer.py*
> /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.pyc
> /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.pyo
> 
> diff --git a/contrib/import-checker.py b/contrib/import-checker.py
> --- a/contrib/import-checker.py
> +++ b/contrib/import-checker.py
> @@ -200,7 +200,10 @@
>             for name in files:
>                 if name == '__init__.py':
>                     continue
> -                if not (name.endswith('.py') or name.endswith('.so')
> +                if not (name.endswith('.py')
> +                        or name.endswith('.so')
> +                        or name.endswith('.pyc')
> +                        or name.endswith('.pyo')
>                         or name.endswith('.pyd')):
>                     continue
>                 full_path = os.path.join(top, name)
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
Anton Shestakov - Sept. 3, 2015, 5:03 a.m.
03.09.2015, 04:17, "timeless@mozdev.org" <timeless@mozdev.org>:
> # HG changeset patch
> # User timeless@mozdev.org
> # Date 1441224455 14400
> # Wed Sep 02 16:07:35 2015 -0400
> # Node ID db4607bedf0785a1c49bdf53544cf8548fe4cac7
> # Parent f77a3f27cea533232dc107a72773e90e2de9549d
> import-checker: accept .pyc and .pyo files (issue4812)
>
> Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
> [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
>
> $ ls '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6'/BaseHTTPServer.py*
> /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.pyc
> /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.pyo
>
> diff --git a/contrib/import-checker.py b/contrib/import-checker.py
> --- a/contrib/import-checker.py
> +++ b/contrib/import-checker.py
> @@ -200,7 +200,10 @@
>              for name in files:
>                  if name == '__init__.py':
>                      continue
> - if not (name.endswith('.py') or name.endswith('.so')
> + if not (name.endswith('.py')
> + or name.endswith('.so')
> + or name.endswith('.pyc')
> + or name.endswith('.pyo')
>                          or name.endswith('.pyd')):

This could be written like this:

if not name.endswith(('.py', '.so', '.pyc', '.pyo', '.pyd')):

since Python 2.5.

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -200,7 +200,10 @@ 
             for name in files:
                 if name == '__init__.py':
                     continue
-                if not (name.endswith('.py') or name.endswith('.so')
+                if not (name.endswith('.py')
+                        or name.endswith('.so')
+                        or name.endswith('.pyc')
+                        or name.endswith('.pyo')
                         or name.endswith('.pyd')):
                     continue
                 full_path = os.path.join(top, name)