-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
- Loading branch information
1 parent
67625ff
commit cbaca38
Showing
2 changed files
with
18 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,38 @@ | ||
""" | ||
Execute the reports in this directory with papermill & output them to a github repo | ||
""" | ||
import papermill as pm | ||
import argparse | ||
import os | ||
from datetime import datetime | ||
import pathlib | ||
from contextlib import contextmanager | ||
import argparse | ||
import subprocess | ||
from contextlib import contextmanager | ||
from datetime import datetime | ||
from tempfile import TemporaryDirectory | ||
|
||
import papermill as pm | ||
|
||
HERE = pathlib.Path(__file__).parent | ||
|
||
|
||
@contextmanager | ||
def auto_commit_git_repo(clone_url, message): | ||
with TemporaryDirectory() as d: | ||
subprocess.check_call([ | ||
'git', 'clone', | ||
clone_url, | ||
'--depth', '1', | ||
d | ||
]) | ||
subprocess.check_call(["git", "clone", clone_url, "--depth", "1", d]) | ||
try: | ||
yield d | ||
finally: | ||
subprocess.check_call([ | ||
'git', 'add', '.' | ||
], cwd=d) | ||
subprocess.check_call([ | ||
'git', 'commit', '-m', message | ||
], cwd=d) | ||
subprocess.check_call([ | ||
'git', 'push' | ||
], cwd=d) | ||
|
||
subprocess.check_call(["git", "add", "."], cwd=d) | ||
subprocess.check_call(["git", "commit", "-m", message], cwd=d) | ||
subprocess.check_call(["git", "push"], cwd=d) | ||
|
||
|
||
reports = HERE.glob('*.ipynb') | ||
reports = HERE.glob("*.ipynb") | ||
|
||
with auto_commit_git_repo('[email protected]:yuvipanda/2i2c-reports.git', 'Test commits') as d: | ||
with auto_commit_git_repo( | ||
"[email protected]:yuvipanda/2i2c-reports.git", "Test commits" | ||
) as d: | ||
output_base = pathlib.Path(d) | ||
for report in reports: | ||
output_file = output_base / report.stem / datetime.now().isoformat() | ||
output_file = output_base / report.stem / datetime.now().isoformat() | ||
os.makedirs(output_file.parent, exist_ok=True) | ||
pm.execute_notebook( | ||
report, | ||
str(output_file) + ".ipynb" | ||
) | ||
pm.execute_notebook(report, str(output_file) + ".ipynb") |