|
1 | | -# create tag number for the latest git check in and record that in |
2 | | -# the git_version.py file. |
| 1 | +# create numerical tag number for the latest git check in and record that in |
| 2 | +# the git_version.py file. This also advances the minor version number |
| 3 | +# for the GSAS-II version number (from 5.X.Y to 5.X+1.0) |
3 | 4 |
|
4 | 5 | # perhaps someday this should be made automatic in some fashion (perhaps |
5 | | -# not used on every check-in but don't go too many days/mosds without a new |
| 6 | +# not used on every check-in but don't go too many days/mods without a new |
6 | 7 | # version # |
7 | 8 |
|
8 | 9 | # perhaps someday include as a clean (run on git add) or smudge |
9 | | -# step (run on git pull). |
| 10 | +# step (run on git pull). |
10 | 11 | # Alternately, on commit/pull might get a count of how many untagged |
11 | | -# check-ins there have been. |
| 12 | +# check-ins there have been. |
12 | 13 | # |
13 | 14 | # [filter "createVersionFile"] |
14 | 15 | # clean = python git_filters.py --tag-version |
|
30 | 31 | path2repo = os.path.dirname(path2GSAS2) |
31 | 32 |
|
32 | 33 | if __name__ == '__main__': |
33 | | - |
| 34 | + |
34 | 35 | g2repo = git.Repo(path2repo) |
35 | | - if g2repo.active_branch.name != 'master': |
36 | | - print(f'Not on master branch {commit0[:6]!r}') |
37 | | - sys.exit() |
38 | | - if g2repo.head.is_detached: |
39 | | - print(f'Detached head {commit0[:6]!r}') |
| 36 | +# if g2repo.active_branch.name != 'master': |
| 37 | +# print('Not on master branch') |
| 38 | +# sys.exit() |
| 39 | + if g2repo.head.is_detached: |
| 40 | + print(f'Detached head {commit0[:7]!r}') |
40 | 41 | sys.exit() |
41 | 42 | # make a list of tags without a dash; get the largest numeric tag |
| 43 | + # someday use the packaging module (but no more dependencies for now) |
42 | 44 | numtag = [i for i in g2repo.tags if '-' not in i.name] |
43 | 45 | max_numeric = max([int(i.name) for i in numtag if i.name.isdecimal()]) |
44 | | - |
45 | | - # scan for the newest untagged commits, stopping at the first |
46 | | - # tagged one |
47 | | - untagged = [] |
48 | | - for i,c in enumerate(g2repo.iter_commits('HEAD')): |
49 | | - if i > 500: |
50 | | - print('No tag found in 500 commits!') |
51 | | - #break |
52 | | - sys.exit() |
53 | | - tags = g2repo.git.tag('--points-at',c).split('\n') |
54 | | - if tags == ['']: |
55 | | - untagged.append(c) |
56 | | - else: |
57 | | - break |
58 | | - # add a tag to the newest untagged version |
59 | | - tagnum = max_numeric |
60 | | - for i in sorted(untagged,key=lambda k:k.committed_datetime,reverse=True): |
| 46 | + # get the latest version number |
| 47 | + releases = [i for i in g2repo.tags if '.' in i.name and i.name.startswith('v')] |
| 48 | + majors = [i.name.split('.')[0][1:] for i in releases] |
| 49 | + major = max([int(i) for i in majors if i.isdecimal()]) |
| 50 | + minors = [i.name.split('.')[1] for i in releases if i.name.startswith(f'v{major}.')] |
| 51 | + minor = max([int(i) for i in minors if i.isdecimal()]) |
| 52 | + minis = [i.name.split('.',2)[2] for i in releases if i.name.startswith(f'v{major}.{minor}')] |
| 53 | + # mini can be integer, float or even have letters (5.2.1.1rc1) |
| 54 | + # for now, ignore anything with letters or decimals |
| 55 | + mini = max([int(i) for i in minis if i.isdecimal()]) |
| 56 | + latest = f'{major}.{minor}.{mini}' |
| 57 | + #nextmini = f'v{major}.{minor}.{mini+1}' |
| 58 | + nextminor = f'v{major}.{minor+1}.0' |
| 59 | + versiontag = nextminor |
| 60 | + if versiontag in releases: |
| 61 | + print(f'Versioning problem, generated next version {versiontag} already defined!') |
| 62 | + versiontag = '?' |
| 63 | + |
| 64 | + # is the newest commit tagged? |
| 65 | + c = g2repo.head.commit |
| 66 | + tags = g2repo.git.tag('--points-at',c).split('\n') |
| 67 | + if tags != ['']: |
| 68 | + print(f'Latest commit ({c.hexsha[:7]}) is already tagged ({tags}).') |
| 69 | + sys.exit() |
| 70 | + # add a tag to the newest commit |
| 71 | + tagnum = max_numeric + 1 |
| 72 | + while str(tagnum) in g2repo.tags: |
| 73 | + print(f'Error: {tagnum} would be repeated') |
61 | 74 | tagnum += 1 |
62 | | - if str(tagnum) in g2repo.tags: |
63 | | - print(f'Error: {tagnum} would be repeated') |
64 | | - break |
65 | | - g2repo.create_tag(str(tagnum),ref=i) |
66 | | - print(f'created tag {tagnum} for {i.hexsha[:6]}') |
67 | | - break |
| 75 | + g2repo.create_tag(str(tagnum),ref=c) |
| 76 | + print(f'created tag {tagnum} for {c.hexsha[:7]}') |
| 77 | + if versiontag != '?': |
| 78 | + g2repo.create_tag(str(versiontag),ref=c) |
| 79 | + print(f'created version # {versiontag} for {c.hexsha[:7]}') |
68 | 80 |
|
69 | | - # create a file with GSAS-II version infomation |
| 81 | + # create a file with GSAS-II version information |
70 | 82 | try: |
71 | 83 | g2repo = git.Repo(path2repo) |
72 | 84 | except: |
73 | 85 | print('Launch of gitpython for version file failed'+ |
74 | 86 | f' with path {path2repo}') |
75 | 87 | sys.exit() |
76 | 88 | commit = g2repo.head.commit |
77 | | - ctim = commit.committed_datetime.strftime('%d-%b-%Y %H:%M') |
| 89 | + #ctim = commit.committed_datetime.strftime('%d-%b-%Y %H:%M') |
78 | 90 | now = dt.datetime.now().replace( |
79 | 91 | tzinfo=commit.committed_datetime.tzinfo) |
80 | 92 | commit0 = commit.hexsha |
81 | | - tags0 = g2repo.git.tag('--points-at',commit).split('\n') |
| 93 | + tags0 = [i for i in g2repo.git.tag('--points-at',commit).split('\n') if i.isdecimal()] |
82 | 94 | history = list(g2repo.iter_commits('HEAD')) |
83 | 95 | for i in history[1:]: |
84 | 96 | tags = g2repo.git.tag('--points-at',i) |
85 | 97 | if not tags: continue |
86 | 98 | commitm1 = i.hexsha |
87 | | - tagsm1 = tags.split('\n') |
| 99 | + tagsm1 = [i for i in tags.split('\n') if i.isdecimal()] |
| 100 | + if not tagsm1: continue |
88 | 101 | break |
89 | 102 | pyfile = os.path.join(path2GSAS2,'git_verinfo.py') |
90 | 103 | try: |
|
94 | 107 | sys.exit() |
95 | 108 | fp.write('# -*- coding: utf-8 -*-\n') |
96 | 109 | fp.write(f'# {os.path.split(pyfile)[1]} - GSAS-II version info from git\n') |
97 | | - fp.write(f'# Do not edit, generated by {" ".join(sys.argv)!r} command\n') |
| 110 | + fp.write(f'# Do not edit, generated by {" ".join(sys.argv)!r} script\n') |
98 | 111 | fp.write(f'# Created {now}\n\n') |
99 | 112 | fp.write(f'git_version = {commit0!r}\n') |
100 | 113 | if tags: |
|
103 | 116 | fp.write('git_tags = []\n') |
104 | 117 | fp.write(f'git_prevtaggedversion = {commitm1!r}\n') |
105 | 118 | fp.write(f'git_prevtags = {tagsm1}\n') |
| 119 | + fp.write(f'git_versiontag = {versiontag!r}\n') |
106 | 120 | fp.close() |
107 | | - print(f'Created git version file {pyfile} at {now} for {commit0[:6]!r}') |
| 121 | + print(f'Created git version file {pyfile} at {now} for {commit0[:7]!r}') |
108 | 122 |
|
109 | | - print('Now do\n\t git add \n\t git commit \n\t git push \n\t git push --follow-tags (better than git push --tags?)') |
| 123 | + print('Now do:\n\t git add \n\t git commit \n\t git push \n\t git push --tags (better than git push --follow-tags?)') |
110 | 124 |
|
111 | 125 | # Git 2.4 has added the push.followTags option to turn that flag on by default which you can set with: |
112 | 126 | # |
|
0 commit comments