Patchwork [5,of,8] import-checker: skip site-packages for virtualenv

login
register
mail settings
Submitter timeless@mozdev.org
Date March 30, 2016, 9:24 a.m.
Message ID <54b962661f75e4a55c21.1459329845@waste.org>
Download mbox | patch
Permalink /patch/14182/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - March 30, 2016, 9:24 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1459325405 0
#      Wed Mar 30 08:10:05 2016 +0000
# Node ID 54b962661f75e4a55c213c0eeb30f5d6024f7dbe
# Parent  9bdba93f0afd6ffe087663510f5198fdb8e40536
import-checker: skip site-packages for virtualenv

pygments was being treated as a stdlib...
Yuya Nishihara - March 31, 2016, 2:25 p.m.
On Wed, 30 Mar 2016 04:24:05 -0500, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1459325405 0
> #      Wed Mar 30 08:10:05 2016 +0000
> # Node ID 54b962661f75e4a55c213c0eeb30f5d6024f7dbe
> # Parent  9bdba93f0afd6ffe087663510f5198fdb8e40536
> import-checker: skip site-packages for virtualenv
> 
> pygments was being treated as a stdlib...

If I understand it, pygments should be treated as a stdlib. stdlib_modules is
used to sort out system-installed modules from our modules.
timeless - March 31, 2016, 3:20 p.m.
> pygments was being treated as a stdlib...

Yuya Nishihara <yuya@tcha.org> wrote:
> If I understand it, pygments should be treated as a stdlib. stdlib_modules is
> used to sort out system-installed modules from our modules.

so, isort has 3 categories: stdlib, other, local

If what we're trying to capture is "modules that are part of
mercurial" vs "modules that are not part of mercurial", we should
rename the concept to "non_mercurial_modules" or "external_modules".

Personally, I think I favor isort's approach and would suggest we
probably want to sort into three categories instead of two categories.

But we can do that later.
Yuya Nishihara - March 31, 2016, 3:44 p.m.
On Thu, 31 Mar 2016 11:20:05 -0400, timeless wrote:
> > pygments was being treated as a stdlib...  
> 
> Yuya Nishihara <yuya@tcha.org> wrote:
> > If I understand it, pygments should be treated as a stdlib. stdlib_modules is
> > used to sort out system-installed modules from our modules.  
> 
> so, isort has 3 categories: stdlib, other, local
> 
> If what we're trying to capture is "modules that are part of
> mercurial" vs "modules that are not part of mercurial", we should
> rename the concept to "non_mercurial_modules" or "external_modules".
> 
> Personally, I think I favor isort's approach and would suggest we
> probably want to sort into three categories instead of two categories.

Or just checks if a module is ours, i.e. hgext.* or mercurial.*. I think it
should be possible if we can get rid of relative imports.
Gregory Szorc - April 3, 2016, 6:13 p.m.
On Thu, Mar 31, 2016 at 8:20 AM, timeless <timeless@gmail.com> wrote:

> > pygments was being treated as a stdlib...
>
> Yuya Nishihara <yuya@tcha.org> wrote:
> > If I understand it, pygments should be treated as a stdlib.
> stdlib_modules is
> > used to sort out system-installed modules from our modules.
>
> so, isort has 3 categories: stdlib, other, local
>
> If what we're trying to capture is "modules that are part of
> mercurial" vs "modules that are not part of mercurial", we should
> rename the concept to "non_mercurial_modules" or "external_modules".
>
> Personally, I think I favor isort's approach and would suggest we
> probably want to sort into three categories instead of two categories.
>

+1. IMO the sorting should be stdlib, other, mercurial/local.

Patch

diff --git a/contrib/import-checker.py b/contrib/import-checker.py
--- a/contrib/import-checker.py
+++ b/contrib/import-checker.py
@@ -206,6 +206,9 @@ 
         else:
             stdlib_prefixes.add(dirname)
     for libpath in sys.path:
+        # We need to skip virtualenv site-packages which are in stdlib_perfiexes
+        if 'site-packages' in libpath:
+            continue
         # We want to walk everything in sys.path that starts with
         # something in stdlib_prefixes. check-code suppressed because
         # the ast module used by this script implies the availability