CI newbie here. I'm currently working on the python track for Exercism.io. I'm looking for a way to automate the process of running tests from pytest, committing and pushing to github, and finally submitting to exercism if all tests pass. I've implemented a pre-commit hook to invoke tests on commit but I'm not sure how to pass the filename back to exercism for submission. Any help is greatly appreciated!
Asked
Active
Viewed 141 times
1 Answers
0
I put together a solution for anyone else looking for a similar workflow. It utilizes a python script in the root directory and handles the git commands via subprocess. It also supports autocomplete for the file directory (based on this gist). This script assumes you've already initialized the git repo and setup your remote repo as well.
#!/usr/bin/env python
import pytest
import subprocess
import readline
import glob
class tabCompleter(object):
"""
A tab completer that can complete filepaths from the filesystem.
Partially taken from:
http://stackoverflow.com/questions/5637124/tab-completion-in-pythons-raw-input
"""
def pathCompleter(self,text,state):
"""
This is the tab completer for systems paths.
Only tested on *nix systems
"""
return [x for x in glob.glob(text+'*')][state]
if __name__=="__main__":
# Take user input for commit message
commit_msg = raw_input('Enter the commit message: ')
t = tabCompleter()
readline.set_completer_delims('\t')
# Necessary for MacOS, Linux uses tab: complete syntax
if 'libedit' in readline.__doc__:
readline.parse_and_bind("bind ^I rl_complete")
else:
readline.parse_and_bind("tab: complete")
#Use the new pathCompleter
readline.set_completer(t.pathCompleter)
#Take user input for exercise file for submission
ans = raw_input("Select the file to submit to Exercism: ")
if pytest.main([]) == 0:
"""
If all tests pass:
add files to index,
commit locally,
submit to exercism.io,
then finally push to remote repo.
"""
subprocess.call(["git","add","."])
subprocess.call(["git","commit","-m", commit_msg])
subprocess.call(["exercism","submit",ans])
subprocess.call(["git","push","origin","master"])

Matt Hosch
- 1
- 3