Skip to content

Commit 340f441

Browse files
committed
write git-info data to install
so that it's available from normal installs
1 parent 3056105 commit 340f441

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ build
1313
dist
1414
node_modules
1515
screenshots
16+
nbviewer/git_info.json
1617
# ignore downloaded notebook sources
1718
notebook-*
1819
.eggs/
1920
MANIFEST
2021
package-lock.json
21-
.vscode/
22+
.vscode/

Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ RUN apt-get update \
4040
COPY --from=builder /wheels /wheels
4141
RUN python3 -mpip install --no-cache /wheels/*
4242

43-
COPY .git /srv/nbviewer/.git
4443
# To change the number of threads use
4544
# docker run -d -e NBVIEWER_THREADS=4 -p 80:8080 nbviewer
4645
ENV NBVIEWER_THREADS 2

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include versioneer.py
22
include nbviewer/_version.py
3-
include requirements.txt
3+
include requirements.txt
4+
include nbviewer/git_info.json

nbviewer/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import cgi
1414
from contextlib import contextmanager
15+
import json
16+
import os
1517
import re
1618
from subprocess import check_output
1719
import time
@@ -33,6 +35,9 @@
3335
'access_token',
3436
]
3537

38+
HERE = os.path.dirname(__file__)
39+
GIT_INFO_JSON = os.path.join(HERE, 'git_info.json')
40+
3641

3742
class EmptyClass(object):
3843
"""
@@ -198,6 +203,9 @@ def parse_header_links(value):
198203

199204
def git_info(path):
200205
"""Return some git info"""
206+
if os.path.exists(GIT_INFO_JSON):
207+
with open(GIT_INFO_JSON, 'r') as f:
208+
return json.load(f)
201209
command = ['git', 'log', '-1', '--format=%H\n%s\n%cD']
202210
sha, msg, date = check_output(command, cwd=path).decode('utf8').splitlines()
203211
return dict(

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def sh(cmd):
2525

2626
def preflight():
2727
log.info("Building LESS")
28+
sh(['invoke', 'git-info'])
2829
sh(['npm', 'install'])
2930
sh(['invoke', 'bower'])
3031
sh(['invoke', 'less'])
@@ -50,7 +51,7 @@ def walk_subpkg(name):
5051

5152
pkg_data = {
5253
"nbviewer": (
53-
['frontpage.json'] +
54+
['frontpage.json', 'git_info.json'] +
5455
walk_subpkg('static') +
5556
walk_subpkg('templates') +
5657
walk_subpkg('providers')

tasks.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from __future__ import print_function
55

6+
import json
67
import os
78
import hashlib
89
import pipes
@@ -151,6 +152,21 @@ def sdist(ctx):
151152
ctx.run('python setup.py sdist')
152153

153154

155+
@invoke.task
156+
def git_info(ctx):
157+
sys.path.insert(0, os.path.join(APP_ROOT, "nbviewer"))
158+
from utils import git_info, GIT_INFO_JSON
159+
try:
160+
info = git_info(APP_ROOT)
161+
except Exception as e:
162+
print("Failed to get git info", e)
163+
return
164+
print("Writing git info to %s" % GIT_INFO_JSON)
165+
with open(GIT_INFO_JSON, "w") as f:
166+
json.dump(info, f)
167+
sys.path.pop(0)
168+
169+
154170
@invoke.task
155171
def release(ctx):
156172
bower(ctx)

0 commit comments

Comments
 (0)