Package pylearn :: Module version
[hide private]

Module version

source code

Functions [hide private]
 
record_versions(results, modules, prefix='version_')
Bizarre version-recording function...
source code
string
src_version(module_name)
Return compact identifier of module code.
source code
tuple (last changeset, modified)
hg_version(dirname, filenames=None)
Return current changeset of directory dirname.
source code
 
_import_id_py_source(location) source code
 
_import_id_py_compiled(location) source code
 
_import_id_pkg_directory(location) source code
 
_import_id(tag) source code
 
import_id(tag)
Return an identifier of the code imported by 'import <tag>'.
source code
 
get_all_src_versions()
Get the version of all loaded module.
source code
Variables [hide private]
  _cache = {}
  _unknown_version = 'unknown version'

Imports: _subprocess, _imp, sys, os


Function Details [hide private]

record_versions(results, modules, prefix='version_')

source code 

Bizarre version-recording function...

For each module in `modules` it executes result.<prefix><module.__name__> = import_id(module.__name)

:returns: None

src_version(module_name)

source code 

Return compact identifier of module code.

Returns: string
compact identifier of module code.
Notes:
  • This function tries to establish that the source files and the repo are syncronized. It raises an Exception if there are un-tracked '.py' files, or if there are un-committed modifications. This implementation uses "hg id" to establish this. The code returned by "hg id" is not affected by hg pull, but pulling might remove the " tip" string which might have appeared. This implementation ignores the " tip" information, and only uses the code.
  • This implementation is assumes that the import directory is under version control by mercurial.

hg_version(dirname, filenames=None)

source code 

Return current changeset of directory dirname.

Parameters:
  • filename (list of str (or default: None)) - if specified, we ignore modifications to other files.
Returns: tuple (last changeset, modified)

import_id(tag)

source code 
Return an identifier of the code imported by 'import <tag>'.

@param tag: a module or file name
@type tag: string

@rtype: string
@return: identifier of the code imported by 'import <tag>'.

This high-level function might do different things depending on, for
example, whether I{tag} identifies a file or a directory, or whether the
named entity is under some sort of version/revision control.

Versions are sought in the following order:
0. If I{tag} is 'python' then sys.version will be returned
1. If I{tag} names a file or folder under revision control, this function
will attempt to guess which one, and return a string that identifies the
running code (a revision id, not the whole file!)
2.  If I{tag} names a module with a __version__ attribute, then that
attribute will be returned as a string.
3. The string starting with 'unknown version' will be returned for other valid modules.
4. An exception will be raise for non-existent modules.

@note: This function may import the named entity in order to return a
__version__ module attribute.

get_all_src_versions()

source code 

Get the version of all loaded module. Calls src_version on all loaded modules. These modules are found using sys.modules.

Returns a dictionnary: name->version.

@RETURN dict Dictionnary (module's name) -> (version) @SEE src_version