Back to Black
This commit is contained in:
parent
ea489bce6c
commit
5697ff87a8
112 changed files with 1803 additions and 977 deletions
|
|
@ -30,7 +30,7 @@ def migrate_source_attribute(attr, to_this, target_file, regex):
|
|||
new_file = []
|
||||
found = False
|
||||
|
||||
with open(target_file, 'r') as fp:
|
||||
with open(target_file, "r") as fp:
|
||||
lines = fp.readlines()
|
||||
|
||||
for line in lines:
|
||||
|
|
@ -40,61 +40,78 @@ def migrate_source_attribute(attr, to_this, target_file, regex):
|
|||
new_file.append(line)
|
||||
|
||||
if found:
|
||||
with open(target_file, 'w') as fp:
|
||||
with open(target_file, "w") as fp:
|
||||
fp.writelines(new_file)
|
||||
|
||||
|
||||
def migrate_version(target_file, new_version):
|
||||
"""Updates __version__ in the source file"""
|
||||
regex = r"['\"](.*)['\"]"
|
||||
migrate_source_attribute('__version__', "'{new_version}'".format(new_version=new_version), target_file, regex)
|
||||
migrate_source_attribute(
|
||||
"__version__",
|
||||
"'{new_version}'".format(new_version=new_version),
|
||||
target_file,
|
||||
regex,
|
||||
)
|
||||
|
||||
|
||||
def is_master_branch():
|
||||
cmd = ('git rev-parse --abbrev-ref HEAD')
|
||||
cmd = "git rev-parse --abbrev-ref HEAD"
|
||||
tag_branch = subprocess.check_output(cmd, shell=True)
|
||||
return tag_branch in [b'master\n']
|
||||
return tag_branch in [b"master\n"]
|
||||
|
||||
|
||||
def git_tag_name():
|
||||
cmd = ('git describe --tags')
|
||||
cmd = "git describe --tags"
|
||||
tag_branch = subprocess.check_output(cmd, shell=True)
|
||||
tag_branch = tag_branch.decode().strip()
|
||||
return tag_branch
|
||||
|
||||
|
||||
def get_git_version_info():
|
||||
cmd = 'git describe --tags'
|
||||
cmd = "git describe --tags"
|
||||
ver_str = subprocess.check_output(cmd, shell=True)
|
||||
ver, commits_since, githash = ver_str.decode().strip().split('-')
|
||||
ver, commits_since, githash = ver_str.decode().strip().split("-")
|
||||
return ver, commits_since, githash
|
||||
|
||||
|
||||
def prerelease_version():
|
||||
""" return what the prerelease version should be.
|
||||
"""return what the prerelease version should be.
|
||||
https://packaging.python.org/tutorials/distributing-packages/#pre-release-versioning
|
||||
0.0.2.dev22
|
||||
"""
|
||||
ver, commits_since, githash = get_git_version_info()
|
||||
initpy_ver = get_version()
|
||||
|
||||
assert len(initpy_ver.split('.')) in [3, 4], 'moto/__init__.py version should be like 0.0.2.dev'
|
||||
assert initpy_ver > ver, 'the moto/__init__.py version should be newer than the last tagged release.'
|
||||
return '{initpy_ver}.{commits_since}'.format(initpy_ver=initpy_ver, commits_since=commits_since)
|
||||
assert len(initpy_ver.split(".")) in [
|
||||
3,
|
||||
4,
|
||||
], "moto/__init__.py version should be like 0.0.2.dev"
|
||||
assert (
|
||||
initpy_ver > ver
|
||||
), "the moto/__init__.py version should be newer than the last tagged release."
|
||||
return "{initpy_ver}.{commits_since}".format(
|
||||
initpy_ver=initpy_ver, commits_since=commits_since
|
||||
)
|
||||
|
||||
|
||||
def read(*parts):
|
||||
""" Reads in file from *parts.
|
||||
"""
|
||||
"""Reads in file from *parts."""
|
||||
try:
|
||||
return io.open(os.path.join(*parts), 'r', encoding='utf-8').read()
|
||||
return io.open(os.path.join(*parts), "r", encoding="utf-8").read()
|
||||
except IOError:
|
||||
return ''
|
||||
return ""
|
||||
|
||||
|
||||
def get_version():
|
||||
""" Returns version from moto/__init__.py
|
||||
"""
|
||||
version_file = read('moto', '__init__.py')
|
||||
version_match = re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]',
|
||||
version_file, re.MULTILINE)
|
||||
"""Returns version from moto/__init__.py"""
|
||||
version_file = read("moto", "__init__.py")
|
||||
version_match = re.search(
|
||||
r'^__version__ = [\'"]([^\'"]*)[\'"]', version_file, re.MULTILINE
|
||||
)
|
||||
if version_match:
|
||||
return version_match.group(1)
|
||||
raise RuntimeError('Unable to find version string.')
|
||||
raise RuntimeError("Unable to find version string.")
|
||||
|
||||
|
||||
def release_version_correct():
|
||||
|
|
@ -107,14 +124,22 @@ def release_version_correct():
|
|||
initpy = os.path.abspath("moto/__init__.py")
|
||||
|
||||
new_version = prerelease_version()
|
||||
print('updating version in __init__.py to {new_version}'.format(new_version=new_version))
|
||||
assert len(new_version.split('.')) >= 4, 'moto/__init__.py version should be like 0.0.2.dev'
|
||||
print(
|
||||
"updating version in __init__.py to {new_version}".format(
|
||||
new_version=new_version
|
||||
)
|
||||
)
|
||||
assert (
|
||||
len(new_version.split(".")) >= 4
|
||||
), "moto/__init__.py version should be like 0.0.2.dev"
|
||||
migrate_version(initpy, new_version)
|
||||
else:
|
||||
assert False, "No non-master deployments yet"
|
||||
# check that we are a tag with the same version as in __init__.py
|
||||
assert get_version() == git_tag_name(), 'git tag/branch name not the same as moto/__init__.py __verion__'
|
||||
assert (
|
||||
get_version() == git_tag_name()
|
||||
), "git tag/branch name not the same as moto/__init__.py __verion__"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
release_version_correct()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue