PKgnNRn5**darken/__init__.py""" Apply black only on mdified files """ __version__ = '0.0.1' import black import argparse import sys MARK = """\ # fmt: {} # bm12 """ from itertools import chain def parse_range(rng): parts = rng.split('-') if 1 > len(parts) > 2: raise ValueError("Bad range: '%s'" % (rng,)) parts = [int(i) for i in parts] start = parts[0] end = start if len(parts) == 1 else parts[1] if start > end: end, start = start, end return range(start, end + 1) def parse_range_list(rngs): return sorted(set(chain(*[parse_range(rng) for rng in rngs.split(',')]))) def insert_marks(lines, ranges): activated = False yield '# bm12' yield "# fmt: off" for lnum, line in enumerate(lines, start=1): if lnum in ranges and not activated: activated = True yield '# bm12' yield "# fmt: on" elif lnum not in ranges and activated: activated = False yield '# bm12' yield "# fmt: off" yield line def main(argv): parser = argparse.ArgumentParser(description='Apply black only to some specific lines of a file.') parser.add_argument('filename', metavar='filename', type=str, help='filename to process') parser.add_argument('--ranges', dest='ranges', metavar='ranges', help='') res = parser.parse_args(argv).ranges res = '1-21' ranges = parse_range_list(res) with open('setup.py', 'r') as f: s = f.read() s = '\n'.join(insert_marks(s.splitlines(), ranges)) res = s res = black.format_str(s, mode=black.FileMode()) def filtermark(gen): try: for l in gen: if l.strip().endswith('# bm12'): next(gen) continue yield l except StopIteration: return lines = res.splitlines() re_lines = list(filtermark(iter(lines))) for i,l in enumerate(re_lines, start=1): print(f"{i:02}", l) if __name__ == '__main__': main(sys.argv) PK!H1S&$'darken-0.0.1.dist-info/entry_points.txtN+I/N.,()J,MI,NͳMPK,nN>>darken-0.0.1.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2019 Matthias Bussonnier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HMuSadarken-0.0.1.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,szd&Y)r$[)T&UD"PK!Ht%darken-0.0.1.dist-info/METADATA=n@ E rVMi@ڀV3ֹ" 읆C5hIÀINɮe&k1,l O.ށ4 58㔺:bb.ܓ,iި}jqb8$SXAhnگq%k:Y[e-k{Zu_nXPK!H6)darken-0.0.1.dist-info/RECORDuͲBP}r8,E!Ҡ4m7K|a~Z$@{'v{H3*h`7a4H6r + Ґf0z*-jKʾJ˾_~U:2hдrm=uBϦ;}nhrq%՛>darken-0.0.1.dist-info/LICENSEPK!HMuSa? darken-0.0.1.dist-info/WHEELPK!Ht% darken-0.0.1.dist-info/METADATAPK!H6)darken-0.0.1.dist-info/RECORDPK1