From 1fc7df5be55e39131387468563f1e01f3ea23e83 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Fri, 27 Apr 2018 03:48:31 +0100 Subject: [PATCH] Move canonical library version to __init__.py. --- docs/api.rst | 1 + docs/conf.py | 15 +++++++++++++-- mitogen/__init__.py | 5 +++++ mitogen/core.py | 7 ++++--- mitogen/fakessh.py | 1 + mitogen/parent.py | 1 + setup.py | 12 +++++++++++- 7 files changed, 36 insertions(+), 6 deletions(-) diff --git a/docs/api.rst b/docs/api.rst index f69f1405..fa4e058c 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -17,6 +17,7 @@ mitogen Package .. automodule:: mitogen +.. autodata:: mitogen.__version__ .. autodata:: mitogen.is_master .. autodata:: mitogen.context_id .. autodata:: mitogen.parent_id diff --git a/docs/conf.py b/docs/conf.py index 6db8ae56..7c218f8b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,17 @@ +import os import sys + sys.path.append('..') +def grep_version(): + path = os.path.join(os.path.dirname(__file__), '../mitogen/__init__.py') + with open(path) as fp: + for line in fp: + if line.startswith('__version__'): + _, _, s = line.partition('=') + return '.'.join(map(str, eval(s))) + + author = u'David Wilson' copyright = u'2016, David Wilson' exclude_patterns = ['_build'] @@ -20,8 +31,8 @@ language = None master_doc = 'toc' project = u'Mitogen' pygments_style = 'sphinx' -release = u'master' +release = grep_version() source_suffix = '.rst' templates_path = ['_templates'] todo_include_todos = False -version = u'master' +version = grep_version() diff --git a/mitogen/__init__.py b/mitogen/__init__.py index 0d5a1b13..02be6897 100644 --- a/mitogen/__init__.py +++ b/mitogen/__init__.py @@ -31,6 +31,11 @@ On the Mitogen master, this is imported from ``mitogen/__init__.py`` as would be expected. On the slave, it is built dynamically during startup. """ + +#: Library version as a tuple. +__version__ = (0, 0, 2) + + #: This is ``False`` in slave contexts. It is used in single-file Python #: programs to avoid reexecuting the program's :py:func:`main` function in the #: slave. For example: diff --git a/mitogen/core.py b/mitogen/core.py index 62733a7a..5e6a73a7 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -1586,7 +1586,8 @@ class ExternalContext(object): sys.modules['mitogen.core'] = mitogen.core del sys.modules['__main__'] - def _setup_globals(self, context_id, parent_ids): + def _setup_globals(self, version, context_id, parent_ids): + mitogen.__version__ = version mitogen.is_master = False mitogen.context_id = context_id mitogen.parent_ids = parent_ids @@ -1646,7 +1647,7 @@ class ExternalContext(object): self.dispatch_stopped = True def main(self, parent_ids, context_id, debug, profiling, log_level, - max_message_size, in_fd=100, out_fd=1, core_src_fd=101, + max_message_size, version, in_fd=100, out_fd=1, core_src_fd=101, setup_stdio=True, setup_package=True, importer=None, whitelist=(), blacklist=()): self._setup_master(max_message_size, profiling, parent_ids[0], @@ -1657,7 +1658,7 @@ class ExternalContext(object): self._setup_importer(importer, core_src_fd, whitelist, blacklist) if setup_package: self._setup_package() - self._setup_globals(context_id, parent_ids) + self._setup_globals(version, context_id, parent_ids) if setup_stdio: self._setup_stdio() diff --git a/mitogen/fakessh.py b/mitogen/fakessh.py index 6a7303ab..0e737c21 100644 --- a/mitogen/fakessh.py +++ b/mitogen/fakessh.py @@ -350,6 +350,7 @@ def run(dest, router, args, deadline=None, econtext=None): 'parent_ids': parent_ids, 'profiling': getattr(router, 'profiling', False), 'setup_stdio': False, + 'version': mitogen.__version__, },)) finally: fp.close() diff --git a/mitogen/parent.py b/mitogen/parent.py index 2868c93a..b69a489e 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -685,6 +685,7 @@ class Stream(mitogen.core.Stream): 'whitelist': self._router.get_module_whitelist(), 'blacklist': self._router.get_module_blacklist(), 'max_message_size': self.max_message_size, + 'version': mitogen.__version__, } def get_preamble(self): diff --git a/setup.py b/setup.py index af41c13a..a4ec07ba 100644 --- a/setup.py +++ b/setup.py @@ -28,9 +28,19 @@ from setuptools import find_packages, setup + +def grep_version(): + path = os.path.join(os.path.dirname(__file__), 'mitogen/__init__.py') + with open(path) as fp: + for line in fp: + if line.startswith('__version__'): + _, _, s = line.partition('=') + return '.'.join(map(str, eval(s))) + + setup( name = 'mitogen', - version = '0.0.2', + version = grep_version(), description = 'Library for writing distributed self-replicating programs.', author = 'David Wilson', license = 'New BSD',