def get_version(self, version_file=None, version_variable=None):
version = getattr(self, '<STR_LIT:version>', None)<EOL>if version is not None:<EOL><INDENT>return version<EOL><DEDENT>if version_file is None:<EOL><INDENT>files = ['<STR_LIT>',<EOL>self.name.split('<STR_LIT:.>')[-<NUM_LIT:1>]+'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>'<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>files = [version_file]<EOL><DEDENT>if version_variable is None:<EOL><INDENT>version_vars = ['<STR_LIT:version>',<EOL>'<STR_LIT>',<EOL>self.name.split('<STR_LIT:.>')[-<NUM_LIT:1>]+'<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>version_vars = [version_variable]<EOL><DEDENT>for f in files:<EOL><INDENT>fn = njoin(self.local_path, f)<EOL>if os.path.isfile(fn):<EOL><INDENT>info = (open(fn), fn, ('<STR_LIT>', '<STR_LIT>', <NUM_LIT:1>))<EOL>name = os.path.splitext(os.path.basename(fn))[<NUM_LIT:0>]<EOL>n = dot_join(self.name, name)<EOL>try:<EOL><INDENT>version_module = imp.load_module('<STR_LIT:_>'.join(n.split('<STR_LIT:.>')),*info)<EOL><DEDENT>except ImportError:<EOL><INDENT>msg = get_exception()<EOL>self.warn(str(msg))<EOL>version_module = None<EOL><DEDENT>if version_module is None:<EOL><INDENT>continue<EOL><DEDENT>for a in version_vars:<EOL><INDENT>version = getattr(version_module, a, None)<EOL>if version is not None:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if version is not None:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>if version is not None:<EOL><INDENT>self.version = version<EOL>return version<EOL><DEDENT>revision = self._get_svn_revision(self.local_path)<EOL>if revision is None:<EOL><INDENT>revision = self._get_hg_revision(self.local_path)<EOL><DEDENT>if revision is not None:<EOL><INDENT>version = str(revision)<EOL>self.version = version<EOL><DEDENT>return version<EOL>
Try to get version string of a package.

        Return a version string of the current package or None if the version
        information could not be detected.

        Notes
        -----
        This method scans files named
        __version__.py, <packagename>_version.py, version.py, and
        __svn_version__.py for string variables version, __version\__, and
        <packagename>_version, until a version number is found.