##// END OF EJS Templates
Support for 'hg --version'. setup.py stores version from hg repository....
Thomas Arendsen Hein -
r423:25afb21d default
parent child Browse files
Show More
@@ -0,0 +1,62 b''
1 # Copyright (C) 2005 by Intevation GmbH
2 # Author(s):
3 # Thomas Arendsen Hein <thomas@intevation.de>
4 #
5 # This program is free software under the GNU GPL (>=v2)
6 # Read the file COPYING coming with the software for details.
7
8 """
9 Mercurial version
10 """
11
12 import os
13 import os.path
14 import re
15 import time
16
17 unknown_version = 'unknown'
18
19 def get_version():
20 """Return version information if available."""
21 try:
22 from mercurial.__version__ import version
23 except ImportError:
24 version = unknown_version
25 return version
26
27 def write_version(version):
28 """Overwrite version file."""
29 filename = os.path.join(os.path.dirname(__file__), '__version__.py')
30 f = open(filename, 'w')
31 f.write("# This file is auto-generated.\n")
32 f.write("version = %r\n" % version)
33 f.close()
34
35 def remember_version():
36 """Store version information."""
37 f = os.popen("hg identify 2>/dev/null") # use real hg installation
38 ident = f.read()[:-1]
39 if not f.close() and ident:
40 ids = ident.split(' ', 1)
41 version = ids.pop(0)
42 if version[-1] == '+':
43 version = version[:-1]
44 modified = True
45 else:
46 modified = False
47 if version.isalnum() and ids:
48 for tag in ids[0].split('/'):
49 # is a tag is suitable as a version number?
50 if re.match(r'^(\d+\.)+[\w.-]+$', tag):
51 version = tag
52 break
53 if modified:
54 version += time.strftime('+%Y%m%d')
55 else:
56 version = unknown_version
57 write_version(version)
58
59 def forget_version():
60 """Remove version information."""
61 write_version(unknown_version)
62
@@ -7,4 +7,5 b' build/.*'
7 dist/
7 dist/
8 MANIFEST$
8 MANIFEST$
9 .pc/
9 .pc/
10 patches/ No newline at end of file
10 patches/
11 mercurial/__version__.py$
@@ -6,7 +6,7 b' General:'
6 - python 2.2 support
6 - python 2.2 support
7 - better import support
7 - better import support
8 - export to git
8 - export to git
9 - Add standard files: AUTHORS, CREDITS, COPYING. ChangeLog? What else?
9 - Add standard files: AUTHORS, CREDITS, ChangeLog? What else?
10 - Code cleanup: apply http://python.org/peps/pep-0008.html
10 - Code cleanup: apply http://python.org/peps/pep-0008.html
11
11
12 Core:
12 Core:
@@ -33,7 +33,6 b' Commands:'
33 - hg -v history doesn't show tkmerge as modified (removed).
33 - hg -v history doesn't show tkmerge as modified (removed).
34 - hg import vs. hg patch in help etc., import is a reserved python
34 - hg import vs. hg patch in help etc., import is a reserved python
35 word, PEP8 mentions trailing underscore as a convention for this.
35 word, PEP8 mentions trailing underscore as a convention for this.
36 - version reporting (hg --version / version.py / setup.py etc.)
37 - hg pull default in a subdir doesn't work, if it is a relative path
36 - hg pull default in a subdir doesn't work, if it is a relative path
38 - optionally only show merges (two parents or parent != changeset-1, etc.)
37 - optionally only show merges (two parents or parent != changeset-1, etc.)
39
38
@@ -8,7 +8,7 b''
8 import os, re, sys, signal
8 import os, re, sys, signal
9 import fancyopts, ui, hg
9 import fancyopts, ui, hg
10 from demandload import *
10 from demandload import *
11 demandload(globals(), "mdiff time hgweb traceback random signal errno")
11 demandload(globals(), "mdiff time hgweb traceback random signal errno version")
12
12
13 class UnknownCommand(Exception): pass
13 class UnknownCommand(Exception): pass
14
14
@@ -134,6 +134,16 b' def show_changeset(ui, repo, rev=0, chan'
134 ui.status("summary: %s\n" % description.splitlines()[0])
134 ui.status("summary: %s\n" % description.splitlines()[0])
135 ui.status("\n")
135 ui.status("\n")
136
136
137 def show_version(ui):
138 """output version and copyright information"""
139 ui.write("Mercurial version %s\n" % version.get_version())
140 ui.status(
141 "\nCopyright (C) 2005 Matt Mackall <mpm@selenic.com>\n"
142 "This is free software; see the source for copying conditions. "
143 "There is NO\nwarranty; "
144 "not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
145 )
146
137 def help(ui, cmd=None):
147 def help(ui, cmd=None):
138 '''show help for a given command or all commands'''
148 '''show help for a given command or all commands'''
139 if cmd:
149 if cmd:
@@ -156,7 +166,10 b' def help(ui, cmd=None):'
156 ui.warn("hg: unknown command %s\n" % cmd)
166 ui.warn("hg: unknown command %s\n" % cmd)
157 sys.exit(0)
167 sys.exit(0)
158 else:
168 else:
159 ui.status('hg commands:\n\n')
169 if not ui.quiet:
170 show_version(ui)
171 ui.write('\n')
172 ui.write('hg commands:\n\n')
160
173
161 h = {}
174 h = {}
162 for e in table.values():
175 for e in table.values():
@@ -171,7 +184,7 b' def help(ui, cmd=None):'
171 fns.sort()
184 fns.sort()
172 m = max(map(len, fns))
185 m = max(map(len, fns))
173 for f in fns:
186 for f in fns:
174 ui.status(' %-*s %s\n' % (m, f, h[f]))
187 ui.write(' %-*s %s\n' % (m, f, h[f]))
175
188
176 # Commands start here, listed alphabetically
189 # Commands start here, listed alphabetically
177
190
@@ -679,7 +692,7 b' table = {'
679 "verify": (verify, [], 'hg verify'),
692 "verify": (verify, [], 'hg verify'),
680 }
693 }
681
694
682 norepo = "init branch help debugindex debugindexdot"
695 norepo = "init version help debugindex debugindexdot"
683
696
684 def find(cmd):
697 def find(cmd):
685 i = None
698 i = None
@@ -704,6 +717,7 b' def dispatch(args):'
704 ('q', 'quiet', None, 'quiet'),
717 ('q', 'quiet', None, 'quiet'),
705 ('p', 'profile', None, 'profile'),
718 ('p', 'profile', None, 'profile'),
706 ('y', 'noninteractive', None, 'run non-interactively'),
719 ('y', 'noninteractive', None, 'run non-interactively'),
720 ('', 'version', None, 'output version information and exit'),
707 ]
721 ]
708
722
709 args = fancyopts.fancyopts(args, opts, options,
723 args = fancyopts.fancyopts(args, opts, options,
@@ -717,6 +731,10 b' def dispatch(args):'
717 u = ui.ui(options["verbose"], options["debug"], options["quiet"],
731 u = ui.ui(options["verbose"], options["debug"], options["quiet"],
718 not options["noninteractive"])
732 not options["noninteractive"])
719
733
734 if options["version"]:
735 show_version(u)
736 sys.exit(0)
737
720 try:
738 try:
721 i = find(cmd)
739 i = find(cmd)
722 except UnknownCommand:
740 except UnknownCommand:
@@ -9,24 +9,30 b' import glob'
9 from distutils.core import setup, Extension
9 from distutils.core import setup, Extension
10 from distutils.command.install_data import install_data
10 from distutils.command.install_data import install_data
11
11
12 import mercurial.version
13
12 class install_package_data(install_data):
14 class install_package_data(install_data):
13 def finalize_options(self):
15 def finalize_options(self):
14 self.set_undefined_options('install',
16 self.set_undefined_options('install',
15 ('install_lib', 'install_dir'))
17 ('install_lib', 'install_dir'))
16 install_data.finalize_options(self)
18 install_data.finalize_options(self)
17
19
18 setup(name='mercurial',
20 try:
19 version='0.5b',
21 mercurial.version.remember_version()
20 author='Matt Mackall',
22 setup(name='mercurial',
21 author_email='mpm@selenic.com',
23 version=mercurial.version.get_version(),
22 url='http://selenic.com/mercurial',
24 author='Matt Mackall',
23 description='scalable distributed SCM',
25 author_email='mpm@selenic.com',
24 license='GNU GPL',
26 url='http://selenic.com/mercurial',
25 packages=['mercurial'],
27 description='scalable distributed SCM',
26 ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c'])],
28 license='GNU GPL',
27 data_files=[('mercurial/templates',
29 packages=['mercurial'],
28 ['templates/map'] +
30 ext_modules=[Extension('mercurial.mpatch', ['mercurial/mpatch.c'])],
29 glob.glob('templates/map-*') +
31 data_files=[('mercurial/templates',
30 glob.glob('templates/*.tmpl'))],
32 ['templates/map'] +
31 cmdclass = { 'install_data' : install_package_data },
33 glob.glob('templates/map-*') +
32 scripts=['hg', 'hgmerge'])
34 glob.glob('templates/*.tmpl'))],
35 cmdclass = { 'install_data' : install_package_data },
36 scripts=['hg', 'hgmerge'])
37 finally:
38 mercurial.version.forget_version()
@@ -2,10 +2,10 b''
2
2
3 set -x
3 set -x
4
4
5 hg help
5 hg -q help
6 hg add -h
6 hg add -h
7 hg help diff
7 hg help diff
8 hg help foo
8 hg help foo
9 hg commands
9 hg -q commands
10
10
11 exit 0 No newline at end of file
11 exit 0
@@ -1,4 +1,4 b''
1 + hg help
1 + hg -q help
2 hg commands:
2 hg commands:
3
3
4 add add the specified files on the next commit
4 add add the specified files on the next commit
@@ -45,7 +45,7 b' hg diff [-r A] [-r B] [files]'
45 diff working directory (or selected files)
45 diff working directory (or selected files)
46 + hg help foo
46 + hg help foo
47 hg: unknown command foo
47 hg: unknown command foo
48 + hg commands
48 + hg -q commands
49 hg: unknown command 'commands'
49 hg: unknown command 'commands'
50 hg commands:
50 hg commands:
51
51
General Comments 0
You need to be logged in to leave comments. Login now