-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added some more documentation and fixed some false path warnings
- Loading branch information
1 parent
b08b984
commit 4c90c2b
Showing
7 changed files
with
153 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.2' | ||
__version__ = '0.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,73 @@ | ||
from typing import Iterable, List, Tuple | ||
from typing import Iterable, Tuple | ||
|
||
|
||
class VisibilityMarkerError(Exception): | ||
pass | ||
|
||
|
||
def _process_code(code_lines: Iterable[str], marker: str) -> List[str]: | ||
class CodeMarker: | ||
MARKERS = ('hide', 'skip') | ||
|
||
marker_start = f'#{marker}:start' | ||
marker_stop = f'#{marker}:stop' | ||
marker_toggle = f'#{marker}:toggle' | ||
def __init__(self, marker: str): | ||
assert marker in CodeMarker.MARKERS | ||
self.start = f'#{marker}:start' | ||
self.stop = f'#{marker}:stop' | ||
self.toggle = f'#{marker}:toggle' | ||
|
||
self.do_add = True | ||
self.skip_empty = False | ||
self.lines = [] | ||
|
||
def is_marker(self, line: str) -> bool: | ||
if line == self.start: | ||
if not self.do_add: | ||
raise VisibilityMarkerError(f'{self.start[1:]} already called! ' | ||
f'Use {self.stop[1:]} or {self.toggle[1:]}!') | ||
self.do_add = False | ||
return True | ||
|
||
if line == self.stop: | ||
if self.do_add: | ||
raise VisibilityMarkerError(f'{self.stop[1:]} already called! ' | ||
f'Use {self.start[1:]} or {self.toggle[1:]}!') | ||
self.do_add = True | ||
self.skip_empty = True | ||
return True | ||
|
||
if line == self.toggle: | ||
self.do_add = not self.do_add | ||
return True | ||
|
||
return False | ||
|
||
def add_line(self, line: str): | ||
if not self.do_add: | ||
return None | ||
|
||
if self.skip_empty: | ||
if not line.strip(): | ||
return None | ||
self.skip_empty = False | ||
|
||
self.lines.append(line) | ||
|
||
|
||
def get_show_exec_code(code_lines: Iterable[str]) -> Tuple[str, str]: | ||
hide = CodeMarker('hide') | ||
skip = CodeMarker('skip') | ||
|
||
lines = [] | ||
do_add = True | ||
for org_line in code_lines: | ||
line = org_line.replace(' ', '').replace('-', '').lower() | ||
if line == marker_start: | ||
if not do_add: | ||
raise VisibilityMarkerError(f'{marker}:start already called! Use {marker}:stop or {marker}:toggle!') | ||
do_add = False | ||
continue | ||
elif line == marker_stop: | ||
if do_add: | ||
raise VisibilityMarkerError(f'{marker}:stop already called! Use {marker}:start or {marker}:toggle!') | ||
do_add = True | ||
|
||
if hide.is_marker(line): | ||
continue | ||
elif line == marker_toggle: | ||
do_add = not do_add | ||
if skip.is_marker(line): | ||
continue | ||
|
||
if do_add: | ||
lines.append(org_line) | ||
return lines | ||
|
||
hide.add_line(org_line) | ||
skip.add_line(org_line) | ||
|
||
def get_show_exec_code(code_lines: Iterable[str]) -> Tuple[str, str]: | ||
shown_code = '\n'.join(_process_code(code_lines, 'hide')) | ||
executed_code = '\n'.join(_process_code(code_lines, 'skip')) | ||
shown_code = '\n'.join(hide.lines) | ||
executed_code = '\n'.join(skip.lines) | ||
|
||
return shown_code.strip(), executed_code.strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters