Mercurial > pylearn
comparison __init__.py @ 301:57c45df381f1
added source-version function, close ticket #44
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Tue, 10 Jun 2008 11:01:00 -0400 |
parents | 2be51c13b55f |
children | 675d92789941 |
comparison
equal
deleted
inserted
replaced
300:7c5e5356cb11 | 301:57c45df381f1 |
---|---|
1 import filetensor | 1 import filetensor |
2 import nnet_ops | 2 import nnet_ops |
3 | 3 |
4 from lookup_list import LookupList | 4 from lookup_list import LookupList |
5 | 5 |
6 | |
7 | |
8 import subprocess as _subprocess | |
9 import imp as _imp | |
10 def __src_version__(): | |
11 """Return compact identifier of module code. | |
12 | |
13 @return: compact identifier of module code. | |
14 @rtype: string | |
15 | |
16 @note: This function tries to establish that the source files and the repo | |
17 are syncronized. It raises an Exception if there are un-tracked '.py' | |
18 files, or if there are un-committed modifications. This implementation uses | |
19 "hg id" to establish this. The code returned by "hg id" is not affected by | |
20 hg pull, but pulling might remove the " tip" string which might have | |
21 appeared. This implementation ignores the " tip" information, and only | |
22 uses the code. | |
23 | |
24 @note: This implementation is assumes that the import directory is under | |
25 version control by mercurial. | |
26 | |
27 """ | |
28 #print 'name:', __name__ | |
29 location = _imp.find_module(__name__)[1] | |
30 #print 'location:', location | |
31 | |
32 status = _subprocess.Popen(('hg','st'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] | |
33 #status_codes = [line[0] for line in if line and line[0] != '?'] | |
34 for line in status.split('\n'): | |
35 if not line: continue | |
36 if line[0] != '?': | |
37 raise Exception('Uncommitted modification to "%s" in %s (%s)' | |
38 %(line[2:], __name__,location)) | |
39 if line[0] == '?' and line[-3:] == '.py': | |
40 raise Exception('Untracked file "%s" in %s (%s)' | |
41 %(line[2:], __name__, location)) | |
42 | |
43 hg_id = _subprocess.Popen(('hg','id'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] | |
44 | |
45 #This asserts my understanding of hg id return values | |
46 # There is mention in the doc that it might return two parent hash codes | |
47 # but I've never seen it, and I dont' know what it means or how it is | |
48 # formatted. | |
49 tokens = hg_id.split(' ') | |
50 assert len(tokens) <= 2 | |
51 assert len(tokens) >= 1 | |
52 assert tokens[0][-1] != '+' # the trailing + indicates uncommitted changes | |
53 if len(tokens) == 2: | |
54 assert tokens[1] == 'tip' | |
55 | |
56 return tokens[0] | |
57 |