File: remove_ancient_constructs.py

package info (click to toggle)
ubelt 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,180 kB
  • sloc: python: 15,487; sh: 807; makefile: 24
file content (26 lines) | stat: -rw-r--r-- 951 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
def remove_old_python2_headers():
    """
    Helper to modernize the code
    """
    import re
    import ubelt as ub
    from xdev import search_replace
    from xdev import patterns

    repo_dpath = ub.Path('.')
    # fpaths = set(ub.Path('~/code/watch/').expand().glob('**/*.py'))
    fpaths = set(repo_dpath.glob('**/*.py'))

    lines_to_remove = [
        patterns.Pattern.from_regex(re.escape('from __future__ import absolute_import, ') + '.*', dotall=True),
        patterns.Pattern.from_regex(re.escape('# -*- coding: utf-8 -*-') + '.*', dotall=True),
    ]

    fpaths = {f for f in fpaths if 'remove_ancient_constructs' not in str(f)}
    # fpaths = fpaths - {ub.Path('~/code/ubelt/dev/remove_ancient_constructs.py').expand()}

    dry = 0
    for fpath in fpaths:
        # x = fpath.read_text().split('\n')[0:1][0]
        for pat in lines_to_remove:
            search_replace.sedfile(fpath, regexpr=pat, repl='', dry=dry, verbose=3)