FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Change blurb approach to confirming valid repo. · python/blurb@dbe5a22 · GitHub

Repository navigation

Commit dbe5a22

Browse files
committed
Change blurb approach to confirming valid repo.
1 parent 1b98637 commit dbe5a22

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

‎blurb.py‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python3
22
"""Command-line tool to manage CPython Misc/NEWS.d entries."""
3-
__version__ = "1.0.2.dev1"
3+
__version__ = "1.0.3"
44

55
##
66
## blurb version 1.0
@@ -52,6 +52,7 @@
5252
import inspect
5353
import math
5454
import os
55+
import re
5556
import shutil
5657
import subprocess
5758
import sys
@@ -622,20 +623,50 @@ def run(s):
622623
return process.stdout.decode('ascii')
623624

624625

626+
readme_re = re.compile(r"This is Python version [23]\.\d")
627+
625628
def chdir_to_repo_root():
626629
global root
630+
631+
def fail(where):
632+
sys.exit('You\'re not inside a CPython repo right now! (failed at "{}")'.format(where))
633+
627634
try:
628-
run("git log -r 7f777ed95a19224294949e1b4ce56bbffcb1fe9f")
629-
except subprocess.SubprocessError:
630-
sys.exit("You're not inside a CPython repo right now!")
635+
git_dir = run("git rev-parse --git-dir").strip()
636+
except subprocess.CalledProcessError:
637+
fail("git rev-parse")
631638

632-
git_dir = run("git rev-parse --git-dir").strip()
633639
if '.git/worktrees' in git_dir:
634640
with open(os.path.join(git_dir, 'gitdir'), "rt", encoding="utf-8") as f:
635641
git_dir = f.read().strip()
636642
root = os.path.dirname(os.path.abspath(git_dir))
637643
os.chdir(root)
638644

645+
# make totally, absolutely sure we're in a valid CPython repo
646+
def test_first_line(filename, test):
647+
with open(filename, "rt") as f:
648+
lines = f.read().split('\n')
649+
if not (lines and test(lines[0])):
650+
fail(filename)
651+
652+
for readme in ("README", "README.rst"):
653+
if os.path.exists(readme):
654+
test_first_line(readme, readme_re.match)
655+
break
656+
else:
657+
fail(readme)
658+
659+
test_first_line("LICENSE", "A. HISTORY OF THE SOFTWARE".__eq__)
660+
661+
def test_existence(filename):
662+
if not os.path.exists(filename):
663+
fail(filename)
664+
665+
test_existence("Include/Python.h")
666+
test_existence("Python/ceval.c")
667+
668+
return root
669+
639670

640671
def error(*a):
641672
s = " ".join(str(x) for x in a)
@@ -1010,6 +1041,12 @@ def flush_git_rm_files():
10101041
git_rm_files.clear()
10111042

10121043

1044+
# @subcommand
1045+
# def noop():
1046+
# "Do-nothing command. Used for blurb smoke-testing."
1047+
# pass
1048+
1049+
10131050
@subcommand
10141051
def populate():
10151052
"""

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL