Skip to content

Commit

Permalink
deleting start and end description markers
Browse files Browse the repository at this point in the history
  • Loading branch information
edublancas committed Oct 25, 2021
1 parent 2d560eb commit d5d7232
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/ploomber/cli/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,19 @@ def _delete_git_repo(path):
os.chmod(Path(root, file_), stat.S_IRWXU)


def _display_markdown(tw, path):
source = path.read_text()
def _delete(source, sub):
return source.replace(sub, '')


def _cleanup_markdown(source):
source = _delete(source, '<!-- start description -->\n')
source = _delete(source, '<!-- end description -->\n')
source = _skip_header(source)
return source


def _display_markdown(tw, path):
source = _cleanup_markdown(path.read_text())

lines = source.splitlines()

Expand Down Expand Up @@ -216,7 +225,8 @@ def list(self):

tw.write('\nTo run these examples in free, hosted '
f'environment, see instructions at: {_URL}')
tw.write('\nTo download: ploomber examples -n {name}\n')
tw.write('\nTo download: ploomber examples -n name -o path\n')
tw.write('Example: ploomber examples -n templates/ml-basic -o ml\n')


def main(name, force=False, branch=None, output=None):
Expand All @@ -240,7 +250,7 @@ def main(name, force=False, branch=None, output=None):
selected = manager.path_to(name)

if not selected.exists():
click.echo(f'\n\nThere is no example named {name!r}.\n'
click.echo(f'There is no example named {name!r}.\n'
'To list examples: ploomber examples\n'
'To update local copy: ploomber examples -f')
else:
Expand Down
11 changes: 11 additions & 0 deletions tests/cli/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,14 @@ def test_find_header(md, expected):
])
def test_skip_header(md, clean):
assert examples._skip_header(md) == clean


@pytest.mark.parametrize('md, clean', [
['', ''],
['there is no header', 'there is no header'],
['stuff\n<!-- end header -->\nthings', 'things'],
['<!-- start description -->\nthings', 'things'],
['<!-- end description -->\nthings', 'things'],
])
def test_cleanup_markdown(md, clean):
assert examples._cleanup_markdown(md) == clean

0 comments on commit d5d7232

Please sign in to comment.