Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #92 from nnadeau/pandoc-filter
Browse files Browse the repository at this point in the history
Added Pandoc filter
  • Loading branch information
nnadeau authored Jun 20, 2017
2 parents a93054f + c24b66e commit a571a9f
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ install:
- pip install -r ci-requirements.txt
- python update_version.py
- pandoc -v
- pandoc --from=markdown --to=rst --output=README.rst README.md
- pandoc -s -f markdown_github -t json -o README.json README.md
- cat README.json
- pandoc -s -f markdown_github -t json README.md | python clean_readme.py | pandoc -s -f json -t rst -o README.rst
- cat README.rst
- pip install .

Expand Down
1 change: 1 addition & 0 deletions ci-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ pytest-cov==2.5.1

# misc
GitPython==2.1.5
pandocfilters==1.2.4
25 changes: 25 additions & 0 deletions clean_readme.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from pandocfilters import toJSONFilter


def strip_links(key, value, *_):
# strip readme badges
if key == 'Para':
if value[0]['t'] == 'Link' and value[0]['c'][0][0]['t'] == 'Image':
return []

# turn links to text
if key == 'Link':
return value[0]

# strip raw html, logo, and ruled lines
if key in ['RawBlock', 'HorizontalRule', 'Image']:
return []


if __name__ == "__main__":
toJSONFilter(strip_links)

# debugging
# with open('README.json') as f:
# doc = json.load(f)
# walk(doc, strip_links, '', '')
33 changes: 30 additions & 3 deletions update_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,36 @@
logging.info('Root path:\t{}'.format(root_path))

repo = git.Repo(root_path)
tag = repo.tags[-1]
version = tag.name
logging.info('Latest git tag:\t{}'.format(version))
logging.info('Repo:\t{}'.format(repo))

latest_tag = repo.tags[-1]
logging.info('Latest tag:\t{}'.format(latest_tag))

travis_commit = os.environ.get('TRAVIS_COMMIT')
logging.info('Travis commit:\t{}'.format(travis_commit))

sha = repo.head.object.hexsha
logging.info('Last commit sha:\t{}'.format(sha))

short_sha = repo.git.rev_parse(sha, short=4)
logging.info('Last commit short sha:\t{}'.format(short_sha))

travis_branch = os.environ.get('TRAVIS_BRANCH')
logging.info('Travis branch:\t{}'.format(travis_branch))

travis_pr_branch = os.environ.get('TRAVIS_PULL_REQUEST_BRANCH')
logging.info('Travis PR branch:\t{}'.format(travis_pr_branch))

travis_tag = os.environ.get('TRAVIS_TAG')
travis_tag = travis_tag if travis_tag is not None else ''
logging.info('Travis tag:\t{}'.format(travis_tag))

if len(travis_tag) > 0:
version = '{}'.format(latest_tag)
else:
version = '{}.dev{}'.format(latest_tag, int(short_sha, 16))

logging.info('Package version:\t{}'.format(version))

output_file = os.path.join(root_path, 'VERSION')
logging.info('Writing version info to:\t{}'.format(output_file))
Expand Down

0 comments on commit a571a9f

Please sign in to comment.