Mercurial > pylearn
annotate __init__.py @ 305:93280a0c151a
more verbose
author | Thierry Bertin-Mahieux <bertinmt@iro.umontreal.ca> |
---|---|
date | Tue, 10 Jun 2008 17:42:59 -0400 |
parents | 410a6ef674ed |
children | e2e5157ff044 |
rev | line source |
---|---|
35 | 1 import filetensor |
2 import nnet_ops | |
224
2be51c13b55f
added LookupList to pylearn namespace
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
35
diff
changeset
|
3 |
2be51c13b55f
added LookupList to pylearn namespace
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
35
diff
changeset
|
4 from lookup_list import LookupList |
2be51c13b55f
added LookupList to pylearn namespace
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
35
diff
changeset
|
5 |
301
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
6 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
7 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
8 import subprocess as _subprocess |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
9 import imp as _imp |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
10 def __src_version__(): |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
11 """Return compact identifier of module code. |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
12 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
13 @return: compact identifier of module code. |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
14 @rtype: string |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
15 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
16 @note: This function tries to establish that the source files and the repo |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
17 are syncronized. It raises an Exception if there are un-tracked '.py' |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
18 files, or if there are un-committed modifications. This implementation uses |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
19 "hg id" to establish this. The code returned by "hg id" is not affected by |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
20 hg pull, but pulling might remove the " tip" string which might have |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
21 appeared. This implementation ignores the " tip" information, and only |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
22 uses the code. |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
23 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
24 @note: This implementation is assumes that the import directory is under |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
25 version control by mercurial. |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
26 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
27 """ |
303
410a6ef674ed
added comment to source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
302
diff
changeset
|
28 # |
410a6ef674ed
added comment to source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
302
diff
changeset
|
29 # NOTE |
410a6ef674ed
added comment to source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
302
diff
changeset
|
30 # |
410a6ef674ed
added comment to source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
302
diff
changeset
|
31 # If you find bugs in this function, please update the __src_version__ |
410a6ef674ed
added comment to source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
302
diff
changeset
|
32 # function in pylearn, and email either theano-dev or pylearn-dev so that |
410a6ef674ed
added comment to source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
302
diff
changeset
|
33 # people can update their experiment dirs (the output of this function is |
410a6ef674ed
added comment to source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
302
diff
changeset
|
34 # meant to be hard-coded in external files). |
410a6ef674ed
added comment to source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
302
diff
changeset
|
35 # |
410a6ef674ed
added comment to source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
302
diff
changeset
|
36 |
301
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
37 #print 'name:', __name__ |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
38 location = _imp.find_module(__name__)[1] |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
39 #print 'location:', location |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
40 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
41 status = _subprocess.Popen(('hg','st'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
42 #status_codes = [line[0] for line in if line and line[0] != '?'] |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
43 for line in status.split('\n'): |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
44 if not line: continue |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
45 if line[0] != '?': |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
46 raise Exception('Uncommitted modification to "%s" in %s (%s)' |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
47 %(line[2:], __name__,location)) |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
48 if line[0] == '?' and line[-3:] == '.py': |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
49 raise Exception('Untracked file "%s" in %s (%s)' |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
50 %(line[2:], __name__, location)) |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
51 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
52 hg_id = _subprocess.Popen(('hg','id'),cwd=location,stdout=_subprocess.PIPE).communicate()[0] |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
53 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
54 #This asserts my understanding of hg id return values |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
55 # There is mention in the doc that it might return two parent hash codes |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
56 # but I've never seen it, and I dont' know what it means or how it is |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
57 # formatted. |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
58 tokens = hg_id.split(' ') |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
59 assert len(tokens) <= 2 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
60 assert len(tokens) >= 1 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
61 assert tokens[0][-1] != '+' # the trailing + indicates uncommitted changes |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
62 if len(tokens) == 2: |
302
675d92789941
debugging source-version function
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
301
diff
changeset
|
63 assert tokens[1] == 'tip\n' |
301
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
64 |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
65 return tokens[0] |
57c45df381f1
added source-version function, close ticket #44
James Bergstra <bergstrj@iro.umontreal.ca>
parents:
224
diff
changeset
|
66 |