Commit c0991f95 authored by Denis Bilenko's avatar Denis Bilenko

updates to makedist.py and set_version.py

set_version.py: add --dry-run option
set_version.py: update regexes to match only start of the line
set_version.py: recognize 'dev' as a version
makedist.py: use --version option instead of argument
makedist.py: show git branch
parent ebf4a1d6
...@@ -55,15 +55,11 @@ def makedist(*args, **kwargs): ...@@ -55,15 +55,11 @@ def makedist(*args, **kwargs):
os.chdir(cwd) os.chdir(cwd)
def _makedist(version='dev', dest=None): def _makedist(version=None, dest=None):
assert exists('gevent/__init__.py'), 'Where am I?' assert exists('gevent/__init__.py'), 'Where am I?'
basedir = abspath(os.getcwd()) basedir = abspath(os.getcwd())
version = version or 'dev'
if version.lower() == 'dev': set_version_command = 'util/set_version.py --version %s ./gevent/__init__.py' % version
set_version_command = 'util/set_version.py gevent/__init__.py'
else:
set_version_command = 'util/set_version.py --version %s gevent/__init__.py' % version
os.chdir('/tmp') os.chdir('/tmp')
system('rm -fr ' + TMPDIR) system('rm -fr ' + TMPDIR)
os.mkdir(TMPDIR) os.mkdir(TMPDIR)
...@@ -75,6 +71,7 @@ def _makedist(version='dev', dest=None): ...@@ -75,6 +71,7 @@ def _makedist(version='dev', dest=None):
assert len(directory) == 1, directory assert len(directory) == 1, directory
os.chdir(directory[0]) os.chdir(directory[0])
system('git branch')
system(set_version_command) system(set_version_command)
system('git diff', noisy=False) system('git diff', noisy=False)
system('python setup.py -q sdist') system('python setup.py -q sdist')
...@@ -99,12 +96,10 @@ def _makedist(version='dev', dest=None): ...@@ -99,12 +96,10 @@ def _makedist(version='dev', dest=None):
def main(): def main():
parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option('--dest') parser.add_option('--dest')
parser.add_option('--version')
options, args = parser.parse_args() options, args = parser.parse_args()
assert not args, 'Expected no arguments'
if len(args) != 1: return makedist(options.version, dest=options.dest)
sys.exit('Expected one argument: version (could be "dev").')
return makedist(args[0], dest=options.dest)
def copy(source, dest): def copy(source, dest):
......
...@@ -12,8 +12,8 @@ from optparse import OptionParser ...@@ -12,8 +12,8 @@ from optparse import OptionParser
from distutils.version import LooseVersion from distutils.version import LooseVersion
version_re = re.compile("__version__\s*=\s*'([^']+)'", re.M) version_re = re.compile("^__version__\s*=\s*'([^']+)'", re.M)
version_info_re = re.compile(r"version_info\s*=\s*([^\n]+)") version_info_re = re.compile(r"^version_info\s*=\s*([^\n]+)", re.M)
strict_version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$', re.VERBOSE) strict_version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$', re.VERBOSE)
...@@ -129,16 +129,25 @@ def write(filename, data): ...@@ -129,16 +129,25 @@ def write(filename, data):
def main(): def main():
global options global options
parser = OptionParser() parser = OptionParser()
parser.add_option('--version') parser.add_option('--version', default='dev')
parser.add_option('--dry-run', action='store_true')
options, args = parser.parse_args() options, args = parser.parse_args()
if options.version: assert len(args) == 1, 'One argument is expected, got %s' % len(args)
if strict_version_re.match(options.version) is None: version = options.version
sys.exit('Not a strict version: %r (bdist_msi will fail)' % options.version) if version.lower() == 'dev':
assert len(args) == 1, args version = ''
if version and strict_version_re.match(version) is None:
sys.stderr.write('WARNING: Not a strict version: %r (bdist_msi will fail)' % version)
filename = args[0] filename = args[0]
original_content, new_content = modify_version(filename, options.version) original_content, new_content = modify_version(filename, version)
write(filename, new_content) if options.dry_run:
print 'Updated %s' % filename tmpname = '/tmp/' + os.path.basename(filename) + '.set_version'
write(tmpname, new_content)
if not os.system('diff -u %s %s' % (filename, tmpname)):
sys.exit('No differences applied')
else:
write(filename, new_content)
print 'Updated %s' % filename
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment