From e59935ac71888f244376dceb3b988acaf08a508f Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 08:03:58 -0400 Subject: [PATCH 01/15] added pandoc filter --- clean_readme.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 clean_readme.py diff --git a/clean_readme.py b/clean_readme.py new file mode 100644 index 00000000..f4fe7d4a --- /dev/null +++ b/clean_readme.py @@ -0,0 +1,25 @@ +from pandocfilters import toJSONFilter + + +def strip_links(key, value, format, meta): + # strip readme badges + if key == 'Para': + if value[0]['t'] == 'Link' and value[0]['c'][1][0]['t'] == 'Image': + return [] + + # turn links to text + if key == 'Link': + return value[1] + + # 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, '', '') From ad05e9271d40befd129ea781e4e7b904e3346431 Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 08:05:30 -0400 Subject: [PATCH 02/15] added pandocfilters==1.4.1 to ci requirements --- ci-requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/ci-requirements.txt b/ci-requirements.txt index 1c0d8ac6..ab42c23c 100644 --- a/ci-requirements.txt +++ b/ci-requirements.txt @@ -13,3 +13,4 @@ pytest-cov==2.5.1 # misc GitPython==2.1.5 +pandocfilters==1.4.1 From b90a3569164e062894761c4bf0e29f86b12e0caf Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 08:05:42 -0400 Subject: [PATCH 03/15] upgraded travis pandoc command --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b11a0345..d2036d2d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,7 +36,7 @@ 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 README.md | python clean_readme.py | pandoc -s -f json -t rst -o README.rst - cat README.rst - pip install . From 8b112f55b3bf5f8db3794fe6e57fed85c56a7574 Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 08:26:44 -0400 Subject: [PATCH 04/15] downgraded pandocfilters due to compatibility with Travis CI trusty --- ci-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci-requirements.txt b/ci-requirements.txt index ab42c23c..c1353e10 100644 --- a/ci-requirements.txt +++ b/ci-requirements.txt @@ -13,4 +13,4 @@ pytest-cov==2.5.1 # misc GitPython==2.1.5 -pandocfilters==1.4.1 +pandocfilters==1.2.4 From b9a03385615e351b04dcf70b1a0386ad99a36269 Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 08:31:12 -0400 Subject: [PATCH 05/15] debugging travis ci --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d2036d2d..eb5868e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -36,6 +36,8 @@ install: - pip install -r ci-requirements.txt - python update_version.py - pandoc -v +- 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 . From be4c91e2a9b98172253d9e78da2bd8264a21065e Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 08:38:53 -0400 Subject: [PATCH 06/15] fixing json-object path due to old pandoc version used on old travis ci trusty image --- clean_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_readme.py b/clean_readme.py index f4fe7d4a..5655f27c 100644 --- a/clean_readme.py +++ b/clean_readme.py @@ -4,7 +4,7 @@ def strip_links(key, value, format, meta): # strip readme badges if key == 'Para': - if value[0]['t'] == 'Link' and value[0]['c'][1][0]['t'] == 'Image': + if value[0]['t'] == 'Link' and value[0]['c'][0][0]['t'] == 'Image': return [] # turn links to text From 6eac2fc4eb995cd66c7cfc28705939ddb77cb67b Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 09:34:06 -0400 Subject: [PATCH 07/15] =?UTF-8?q?fixed=20return=20value=20for=20pandoc=201?= =?UTF-8?q?.12.2.1=E2=80=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clean_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_readme.py b/clean_readme.py index 5655f27c..20895b4b 100644 --- a/clean_readme.py +++ b/clean_readme.py @@ -9,7 +9,7 @@ def strip_links(key, value, format, meta): # turn links to text if key == 'Link': - return value[1] + return value[0] # strip raw html, logo, and ruled lines if key in ['RawBlock', 'HorizontalRule', 'Image']: From ca4963d087a4170962e19bacb5f731693ad6aefe Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 09:38:00 -0400 Subject: [PATCH 08/15] fixing vulture lint --- clean_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_readme.py b/clean_readme.py index 20895b4b..c4447ce4 100644 --- a/clean_readme.py +++ b/clean_readme.py @@ -1,7 +1,7 @@ from pandocfilters import toJSONFilter -def strip_links(key, value, format, meta): +def strip_links(key, value, format, _): # strip readme badges if key == 'Para': if value[0]['t'] == 'Link' and value[0]['c'][0][0]['t'] == 'Image': From 075d486c11c0dbd3a3c81440ccb12ff788bd120f Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 10:50:17 -0400 Subject: [PATCH 09/15] parsing git branch to append commit sha to branch versions when uploading to testPyPI --- update_version.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/update_version.py b/update_version.py index a453ea6e..5d23671c 100644 --- a/update_version.py +++ b/update_version.py @@ -10,9 +10,23 @@ 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)) +latest_tag = repo.tags[-1] +current_branch = repo.active_branch +sha = repo.head.object.hexsha +short_sha = repo.git.rev_parse(sha, short=4) + +logging.info('Repo:\t{}'.format(repo)) +logging.info('Latest tag:\t{}'.format(latest_tag)) +logging.info('Current branch:\t{}'.format(current_branch)) +logging.info('Last commit sha:\t{}'.format(sha)) +logging.info('Last commit short sha:\t{}'.format(short_sha)) + +if str(current_branch) == 'master': + version = '{}'.format(latest_tag) +else: + version = '{}+{}'.format(latest_tag, short_sha) + +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)) From 2f62010e34cea1d0d1040796a385e50e616d07cf Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 11:01:51 -0400 Subject: [PATCH 10/15] debugging travis ci --- update_version.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/update_version.py b/update_version.py index 5d23671c..4c903773 100644 --- a/update_version.py +++ b/update_version.py @@ -10,15 +10,31 @@ logging.info('Root path:\t{}'.format(root_path)) repo = git.Repo(root_path) -latest_tag = repo.tags[-1] -current_branch = repo.active_branch -sha = repo.head.object.hexsha -short_sha = repo.git.rev_parse(sha, short=4) - logging.info('Repo:\t{}'.format(repo)) + +latest_tag = repo.tags[-1] logging.info('Latest tag:\t{}'.format(latest_tag)) -logging.info('Current branch:\t{}'.format(current_branch)) + +# current_branch = repo.active_branch +# logging.info('Current branch:\t{}'.format(current_branch)) + +travis_commit = os.environ.get('TRAVIS_COMMIT') +logging.info('Travis commit:\t{}'.format(travis_commit)) + +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') +logging.info('Travis tag:\t{}'.format(travis_tag)) + + +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)) if str(current_branch) == 'master': From 75e341037951e008743dc5ac8cbcabeda0bcb331 Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 11:07:26 -0400 Subject: [PATCH 11/15] using travis variables to help versioning --- update_version.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/update_version.py b/update_version.py index 4c903773..fcf2ea49 100644 --- a/update_version.py +++ b/update_version.py @@ -15,12 +15,15 @@ latest_tag = repo.tags[-1] logging.info('Latest tag:\t{}'.format(latest_tag)) -# current_branch = repo.active_branch -# logging.info('Current branch:\t{}'.format(current_branch)) - 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)) @@ -30,14 +33,7 @@ travis_tag = os.environ.get('TRAVIS_TAG') logging.info('Travis tag:\t{}'.format(travis_tag)) - -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)) - -if str(current_branch) == 'master': +if len(travis_tag) > 0: version = '{}'.format(latest_tag) else: version = '{}+{}'.format(latest_tag, short_sha) From ceefc6395c9a1f76c67e039b033dd1c61790cdfc Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 11:27:17 -0400 Subject: [PATCH 12/15] converting short sha to int for PEP440 compliance --- update_version.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/update_version.py b/update_version.py index fcf2ea49..358612c0 100644 --- a/update_version.py +++ b/update_version.py @@ -31,12 +31,13 @@ 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 = '{}+{}'.format(latest_tag, short_sha) + version = '{}.dev{}'.format(latest_tag, int(short_sha, 16)) logging.info('Package version:\t{}'.format(version)) From 9a9d68c60e03cbd2626f797872100667feedc4e6 Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 11:58:55 -0400 Subject: [PATCH 13/15] format arg shadowed built in name and isn't used; ignoring variable --- clean_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_readme.py b/clean_readme.py index c4447ce4..758a189a 100644 --- a/clean_readme.py +++ b/clean_readme.py @@ -1,7 +1,7 @@ from pandocfilters import toJSONFilter -def strip_links(key, value, format, _): +def strip_links(key, value, _, _): # strip readme badges if key == 'Para': if value[0]['t'] == 'Link' and value[0]['c'][0][0]['t'] == 'Image': From 7a61c9beef3c8a72060a0a4d2bdc54eda3d32ba7 Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 12:06:39 -0400 Subject: [PATCH 14/15] fixing SyntaxError: duplicate argument '_' in function definition --- clean_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_readme.py b/clean_readme.py index 758a189a..15558445 100644 --- a/clean_readme.py +++ b/clean_readme.py @@ -1,7 +1,7 @@ from pandocfilters import toJSONFilter -def strip_links(key, value, _, _): +def strip_links(key, value, fmt, _): # strip readme badges if key == 'Para': if value[0]['t'] == 'Link' and value[0]['c'][0][0]['t'] == 'Image': From c24b66e270f154d8d371094d2cccb69e64bf1473 Mon Sep 17 00:00:00 2001 From: Nicholas Nadeau Date: Tue, 20 Jun 2017 12:16:13 -0400 Subject: [PATCH 15/15] ignoring args --- clean_readme.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clean_readme.py b/clean_readme.py index 15558445..72249198 100644 --- a/clean_readme.py +++ b/clean_readme.py @@ -1,7 +1,7 @@ from pandocfilters import toJSONFilter -def strip_links(key, value, fmt, _): +def strip_links(key, value, *_): # strip readme badges if key == 'Para': if value[0]['t'] == 'Link' and value[0]['c'][0][0]['t'] == 'Image':