-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
Sync files from an upstream CPython release. | ||
""" | ||
|
||
import json | ||
import pathlib | ||
import subprocess | ||
import re | ||
|
||
import autocommand | ||
import packaging.version | ||
from requests_toolbelt import sessions | ||
|
||
|
||
gh_content = sessions.BaseUrlSession( | ||
'https://raw.githubusercontent.com/python/cpython/' | ||
) | ||
gh_api = sessions.BaseUrlSession('https://api.github.com/repos/python/cpython/') | ||
|
||
|
||
def load_file_map(): | ||
text = pathlib.Path('file map.json').read_text(encoding='utf-8') | ||
clean = re.sub('^#.*', '', text, re.MULTILINE) | ||
return json.loads(clean) | ||
|
||
|
||
class Version(packaging.version.Version): | ||
@property | ||
def is_stable(self): | ||
""" | ||
Include release candidates in stable. | ||
""" | ||
return not self.is_prerelease or self.is_rc | ||
|
||
@property | ||
def is_rc(self): | ||
return self.pre[1:] == ['rc'] | ||
|
||
|
||
def by_tag(tag): | ||
return Version(tag['name']) | ||
|
||
|
||
def is_stable(tag): | ||
return not by_tag(tag).is_stable | ||
|
||
|
||
@autocommand.autocommand(__name__) | ||
def run(pre=False): | ||
tags = gh_api.get('tags').json() | ||
filtered = tags if pre else filter(is_stable, tags) | ||
tag = max(filtered, key=by_tag) | ||
version = tag['name'] | ||
for src, dst in load_file_map().items(): | ||
resp = gh_content.get(f'{version}/{src}') | ||
resp.raise_for_status() | ||
with open(dst, 'wb') as out: | ||
out.write(resp.content) | ||
cmd = [ | ||
'git', | ||
'commit', | ||
'-a', | ||
'-m', | ||
f'cpython-{version} rev={tag["commit"]["sha"][:12]}', | ||
] | ||
subprocess.run(cmd) |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Adding script for syncing a backport (configparser, singledispatch) to a CPython branch. |