Mercurial > pylearn
comparison __init__.py @ 306:e2e5157ff044
added src_version cache
author | James Bergstra <bergstrj@iro.umontreal.ca> |
---|---|
date | Tue, 10 Jun 2008 13:02:04 -0400 |
parents | 410a6ef674ed |
children | 9ebc960260c5 |
comparison
equal
deleted
inserted
replaced
303:410a6ef674ed | 306:e2e5157ff044 |
---|---|
27 """ | 27 """ |
28 # | 28 # |
29 # NOTE | 29 # NOTE |
30 # | 30 # |
31 # If you find bugs in this function, please update the __src_version__ | 31 # If you find bugs in this function, please update the __src_version__ |
32 # function in pylearn, and email either theano-dev or pylearn-dev so that | 32 # function in theano, pylearn, and email either theano-dev or pylearn-dev so |
33 # people can update their experiment dirs (the output of this function is | 33 # that people can update their experiment dirs (the output of this function |
34 # meant to be hard-coded in external files). | 34 # is meant to be hard-coded in external files). |
35 # | 35 # |
36 | 36 |
37 #print 'name:', __name__ | 37 if not hasattr(__src_version__, 'rval'): |
38 location = _imp.find_module(__name__)[1] | 38 #print 'name:', __name__ |
39 #print 'location:', location | 39 location = _imp.find_module(__name__)[1] |
40 #print 'location:', location | |
40 | 41 |
41 status = _subprocess.Popen(('hg','st'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] | 42 status = _subprocess.Popen(('hg','st'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] |
42 #status_codes = [line[0] for line in if line and line[0] != '?'] | 43 #status_codes = [line[0] for line in if line and line[0] != '?'] |
43 for line in status.split('\n'): | 44 for line in status.split('\n'): |
44 if not line: continue | 45 if not line: continue |
45 if line[0] != '?': | 46 if line[0] != '?': |
46 raise Exception('Uncommitted modification to "%s" in %s (%s)' | 47 raise Exception('Uncommitted modification to "%s" in %s (%s)' |
47 %(line[2:], __name__,location)) | 48 %(line[2:], __name__,location)) |
48 if line[0] == '?' and line[-3:] == '.py': | 49 if line[0] == '?' and line[-3:] == '.py': |
49 raise Exception('Untracked file "%s" in %s (%s)' | 50 raise Exception('Untracked file "%s" in %s (%s)' |
50 %(line[2:], __name__, location)) | 51 %(line[2:], __name__, location)) |
51 | 52 |
52 hg_id = _subprocess.Popen(('hg','id'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] | 53 hg_id = _subprocess.Popen(('hg','id'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] |
53 | 54 |
54 #This asserts my understanding of hg id return values | 55 #This asserts my understanding of hg id return values |
55 # There is mention in the doc that it might return two parent hash codes | 56 # There is mention in the doc that it might return two parent hash codes |
56 # but I've never seen it, and I dont' know what it means or how it is | 57 # but I've never seen it, and I dont' know what it means or how it is |
57 # formatted. | 58 # formatted. |
58 tokens = hg_id.split(' ') | 59 tokens = hg_id.split(' ') |
59 assert len(tokens) <= 2 | 60 assert len(tokens) <= 2 |
60 assert len(tokens) >= 1 | 61 assert len(tokens) >= 1 |
61 assert tokens[0][-1] != '+' # the trailing + indicates uncommitted changes | 62 assert tokens[0][-1] != '+' # the trailing + indicates uncommitted changes |
62 if len(tokens) == 2: | 63 if len(tokens) == 2: |
63 assert tokens[1] == 'tip\n' | 64 assert tokens[1] == 'tip\n' |
64 | 65 |
65 return tokens[0] | 66 __src_version__.rval = tokens[0] |
66 | 67 |
68 return __src_version__.rval | |
69 | |
70 |