| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1b98637 commit dbe5a22
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | #!/usr/bin/env python3 | |
| 2 | 2 | """Command-line tool to manage CPython Misc/NEWS.d entries.""" | |
| 3 | - __version__ = "1.0.2.dev1" | ||
| 3 | + __version__ = "1.0.3" | ||
| 4 | 4 | ||
| 5 | 5 | ## | |
| 6 | 6 | ## blurb version 1.0 | |
@@ -52,6 +52,7 @@ | |||
| 52 | 52 | import inspect | |
| 53 | 53 | import math | |
| 54 | 54 | import os | |
| 55 | + import re | ||
| 55 | 56 | import shutil | |
| 56 | 57 | import subprocess | |
| 57 | 58 | import sys | |
@@ -622,20 +623,50 @@ def run(s): | |||
| 622 | 623 | return process.stdout.decode('ascii') | |
| 623 | 624 | ||
| 624 | 625 | ||
| 626 | + readme_re = re.compile(r"This is Python version [23]\.\d") | ||
| 627 | + | ||
| 625 | 628 | def chdir_to_repo_root(): | |
| 626 | 629 | global root | |
| 630 | + | ||
| 631 | + def fail(where): | ||
| 632 | + sys.exit('You\'re not inside a CPython repo right now! (failed at "{}")'.format(where)) | ||
| 633 | + | ||
| 627 | 634 | 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") | ||
| 631 | 638 | ||
| 632 | - git_dir = run("git rev-parse --git-dir").strip() | ||
| 633 | 639 | if '.git/worktrees' in git_dir: | |
| 634 | 640 | with open(os.path.join(git_dir, 'gitdir'), "rt", encoding="utf-8") as f: | |
| 635 | 641 | git_dir = f.read().strip() | |
| 636 | 642 | root = os.path.dirname(os.path.abspath(git_dir)) | |
| 637 | 643 | os.chdir(root) | |
| 638 | 644 | ||
| 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 | + | ||
| 639 | 670 | ||
| 640 | 671 | def error(*a): | |
| 641 | 672 | s = " ".join(str(x) for x in a) | |
@@ -1010,6 +1041,12 @@ def flush_git_rm_files(): | |||
| 1010 | 1041 | git_rm_files.clear() | |
| 1011 | 1042 | ||
| 1012 | 1043 | ||
| 1044 | + # @subcommand | ||
| 1045 | + # def noop(): | ||
| 1046 | + # "Do-nothing command. Used for blurb smoke-testing." | ||
| 1047 | + # pass | ||
| 1048 | + | ||
| 1049 | + | ||
| 1013 | 1050 | @subcommand | |
| 1014 | 1051 | def populate(): | |
| 1015 | 1052 | """ | |
| Back | FazBrowse Home | New Git URL |
0 commit comments