Mercurial > hg
comparison setup.py @ 46512:866eb4d6bd9f
build: fake PEP440 versions
If the current version is not exactly a tag, use a local version
specifier to fix it up. PEP 440 uses the "+" separator and only allows
alphanumeric and dot, so use dot for further separations.
Old devel build: 5.7+155-a163cc36d06b
New devel build: 5.7+hg155.a163cc36d06b
Differential Revision: https://phab.mercurial-scm.org/D9955
author | Joerg Sonnenberger <joerg@bec.de> |
---|---|
date | Thu, 04 Feb 2021 23:11:42 +0100 |
parents | 16c18d5e5dc8 |
children | 359bdd8fc60a |
comparison
equal
deleted
inserted
replaced
46511:02d91167cfc3 | 46512:866eb4d6bd9f |
---|---|
417 else: # no tag found | 417 else: # no tag found |
418 ltagcmd = ['parents', '--template', '{latesttag}'] | 418 ltagcmd = ['parents', '--template', '{latesttag}'] |
419 ltag = sysstr(hg.run(ltagcmd)) | 419 ltag = sysstr(hg.run(ltagcmd)) |
420 changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag] | 420 changessincecmd = ['log', '-T', 'x\n', '-r', "only(.,'%s')" % ltag] |
421 changessince = len(hg.run(changessincecmd).splitlines()) | 421 changessince = len(hg.run(changessincecmd).splitlines()) |
422 version = '%s+%s-%s' % (ltag, changessince, hgid) | 422 version = '%s+hg%s.%s' % (ltag, changessince, hgid) |
423 if version.endswith('+'): | 423 if version.endswith('+'): |
424 version += time.strftime('%Y%m%d') | 424 version = version[:-1] + 'local' + time.strftime('%Y%m%d') |
425 elif os.path.exists('.hg_archival.txt'): | 425 elif os.path.exists('.hg_archival.txt'): |
426 kw = dict( | 426 kw = dict( |
427 [[t.strip() for t in l.split(':', 1)] for l in open('.hg_archival.txt')] | 427 [[t.strip() for t in l.split(':', 1)] for l in open('.hg_archival.txt')] |
428 ) | 428 ) |
429 if 'tag' in kw: | 429 if 'tag' in kw: |
430 version = kw['tag'] | 430 version = kw['tag'] |
431 elif 'latesttag' in kw: | 431 elif 'latesttag' in kw: |
432 if 'changessincelatesttag' in kw: | 432 if 'changessincelatesttag' in kw: |
433 version = '%(latesttag)s+%(changessincelatesttag)s-%(node).12s' % kw | 433 version = ( |
434 '%(latesttag)s+.%(changessincelatesttag)s.%(node).12s' % kw | |
435 ) | |
434 else: | 436 else: |
435 version = '%(latesttag)s+%(latesttagdistance)s-%(node).12s' % kw | 437 version = '%(latesttag)s+.%(latesttagdistance)s.%(node).12s' % kw |
436 else: | 438 else: |
437 version = kw.get('node', '')[:12] | 439 version = '0+' + kw.get('node', '')[:12] |
438 | 440 |
439 if version: | 441 if version: |
440 versionb = version | 442 versionb = version |
441 if not isinstance(versionb, bytes): | 443 if not isinstance(versionb, bytes): |
442 versionb = versionb.encode('ascii') | 444 versionb = versionb.encode('ascii') |
448 b'# this file is autogenerated by setup.py\n' | 450 b'# this file is autogenerated by setup.py\n' |
449 b'version = b"%s"\n' % versionb, | 451 b'version = b"%s"\n' % versionb, |
450 ] | 452 ] |
451 ), | 453 ), |
452 ) | 454 ) |
453 | |
454 try: | |
455 oldpolicy = os.environ.get('HGMODULEPOLICY', None) | |
456 os.environ['HGMODULEPOLICY'] = 'py' | |
457 from mercurial import __version__ | |
458 | |
459 version = __version__.version | |
460 except ImportError: | |
461 version = b'unknown' | |
462 finally: | |
463 if oldpolicy is None: | |
464 del os.environ['HGMODULEPOLICY'] | |
465 else: | |
466 os.environ['HGMODULEPOLICY'] = oldpolicy | |
467 | 455 |
468 | 456 |
469 class hgbuild(build): | 457 class hgbuild(build): |
470 # Insert hgbuildmo first so that files in mercurial/locale/ are found | 458 # Insert hgbuildmo first so that files in mercurial/locale/ are found |
471 # when build_py is run next. | 459 # when build_py is run next. |
1681 | 1669 |
1682 # distutils expects version to be str/unicode. Converting it to | 1670 # distutils expects version to be str/unicode. Converting it to |
1683 # unicode on Python 2 still works because it won't contain any | 1671 # unicode on Python 2 still works because it won't contain any |
1684 # non-ascii bytes and will be implicitly converted back to bytes | 1672 # non-ascii bytes and will be implicitly converted back to bytes |
1685 # when operated on. | 1673 # when operated on. |
1686 assert isinstance(version, bytes) | 1674 assert isinstance(version, str) |
1687 setupversion = version.decode('ascii') | 1675 setupversion = version |
1688 | 1676 |
1689 extra = {} | 1677 extra = {} |
1690 | 1678 |
1691 py2exepackages = [ | 1679 py2exepackages = [ |
1692 'hgdemandimport', | 1680 'hgdemandimport', |