Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace module compares directories as strings (--ignore-dir) #55105

Open
vrutsky mannequin opened this issue Jan 12, 2011 · 7 comments
Open

trace module compares directories as strings (--ignore-dir) #55105

vrutsky mannequin opened this issue Jan 12, 2011 · 7 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@vrutsky
Copy link
Mannequin

vrutsky mannequin commented Jan 12, 2011

BPO 10896
Nosy @abalkin
Superseder
  • bpo-10908: Improvements to trace._Ignore
  • Files
  • test.py: test Python file
  • test.cmd: shell script to run test
  • test.out: output for shell script
  • trace.diff
  • trace_ignore_case_fix.patch: Fix case for --ignore-dir and file
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2011-01-12.14:44:16.332>
    labels = ['type-bug', 'library']
    title = 'trace module compares directories as strings (--ignore-dir)'
    updated_at = <Date 2011-01-19.15:40:45.848>
    user = 'https://bugs.python.org/vrutsky'

    bugs.python.org fields:

    activity = <Date 2011-01-19.15:40:45.848>
    actor = 'SilentGhost'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2011-01-12.14:44:16.332>
    creator = 'vrutsky'
    dependencies = []
    files = ['20368', '20369', '20370', '20378', '20452']
    hgrepos = []
    issue_num = 10896
    keywords = ['patch']
    message_count = 7.0
    messages = ['126101', '126110', '126112', '126272', '126524', '126526', '126535']
    nosy_count = 3.0
    nosy_names = ['belopolsky', 'SilentGhost', 'vrutsky']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = '10908'
    type = 'behavior'
    url = 'https://bugs.python.org/issue10896'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    @vrutsky
    Copy link
    Mannequin Author

    vrutsky mannequin commented Jan 12, 2011

    This is code from recent trace.py (http://svn.python.org/view/python/branches/release27-maint/Lib/trace.py?view=markup):

    trace.py:169:
    # Ignore a file when it contains one of the ignorable paths
    for d in self._dirs:
    # The '+ os.sep' is to ensure that d is a parent directory,
    # as compared to cases like:
    # d = "/usr/local"
    # filename = "/usr/local.py"
    # or
    # d = "/usr/local.py"
    # filename = "/usr/local.py"
    if filename.startswith(d + os.sep):
    self._ignore[modulename] = 1
    return 1

    Directories comparison like "filename.startswith(d + os.sep)" works incorrect on case-insensitive filesystems (such as NTFS on Windows).

    This leads to confusing results on Windows:
    python trace.py --ignore-dir='$prefix' -t test.py
    or
    python trace.py --ignore-dir C:\Python26\Lib -t test.py
    shows all calls from standard library, but this one doesn't:
    python trace.py --ignore-dir=c:\python26\lib -t test.py

    See attached test files and log for details.

    @vrutsky vrutsky mannequin added the stdlib Python modules in the Lib dir label Jan 12, 2011
    @vrutsky
    Copy link
    Mannequin Author

    vrutsky mannequin commented Jan 12, 2011

    Workaround for people on Windows who don't wan't to modify trace.py:
    to get clean trace of only your project calls add to ignore list python path with mix of character cases. For me worked out this string:
    python -m trace --ignore-dir=c:\python26\lib;C:\python26\lib;C:\Python26\Lib -t main.py

    @SilentGhost
    Copy link
    Mannequin

    SilentGhost mannequin commented Jan 12, 2011

    It's due to the os.path.normpath not normalizing case. Here is the patch.

    Also affects 3.x

    @pitrou pitrou added the type-bug An unexpected behavior, bug, or error label Jan 12, 2011
    @SilentGhost
    Copy link
    Mannequin

    SilentGhost mannequin commented Jan 14, 2011

    bpo-10908 is dealing with this and other issue re ignored dirs.

    @SilentGhost SilentGhost mannequin closed this as completed Jan 14, 2011
    @SilentGhost SilentGhost mannequin reopened this Jan 15, 2011
    @vrutsky
    Copy link
    Mannequin Author

    vrutsky mannequin commented Jan 19, 2011

    SilentGhost, thanks for the patch! I can confirm, that adding os.path.normcase fixes issues with different cases of files.

    I believe there also may be issue with FAT's long file name mangling, like "C:\PROGRA~1\python26\" instead of "C:\Program Files\python26\". But never experienced such issue with Python.

    @vrutsky
    Copy link
    Mannequin Author

    vrutsky mannequin commented Jan 19, 2011

    Sorry I was wrong - patch don't fix original issue.

    Case should be normalized not only for directories provided through --ignore-dir, but also for directories obtained from __file__. In my tests on Windows Ignore.names(self, filename, modulename) receives `filename''s argument like:
    C:\Python26\Lib\site-packages\shapely\init.pyc

    Attaching patch fixes this issue for me (for Python 2.7 from http://svn.python.org/projects/python/branches/release27-maint, patch attached by SilentGhost is for 3.X I think).

    @SilentGhost
    Copy link
    Mannequin

    SilentGhost mannequin commented Jan 19, 2011

    Vladimir, superseder's patch fixes that too.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant