From 72c3e4d08113608350d196bac824f502814fba2f Mon Sep 17 00:00:00 2001 From: Brian Thorne Date: Thu, 25 Jan 2018 14:20:52 +1100 Subject: [PATCH] Fix sphinx build (#56) * Grab version from setup.py when build docs * Move to one source of package version --- docs/conf.py | 41 ++++++++++++++++++++++++----------------- docs/requirements.txt | 4 ++-- phe/__about__.py | 19 +++++++++++++++++++ phe/__init__.py | 6 +----- setup.py | 22 ++++++++++------------ 5 files changed, 56 insertions(+), 36 deletions(-) create mode 100644 phe/__about__.py diff --git a/docs/conf.py b/docs/conf.py index a966ca6..ca51c8d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,11 +14,11 @@ import sys import os - +import pkg_resources import pip try: - from mock import Mock as MagicMock + from unittest.mock import MagicMock except ImportError: def install(package): pip.main(['install', package]) @@ -26,29 +26,30 @@ def install(package): install('mock') from mock import Mock as MagicMock +try: + from sphinxcontrib import spelling +except ImportError: + spelling = None + on_rtd = os.environ.get('READTHEDOCS', None) == 'True' -if on_rtd: - html_theme = 'default' -else: - html_theme = 'nature' + +html_theme = 'nature' # ------------------------------------------------------------------- # # MOCK MODULES # ------------------------------------------------------------------- # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' if on_rtd: class Mock(MagicMock): @classmethod def __getattr__(cls, name): - return Mock() + return MagicMock() MOCK_MODULES = ['gmpy2', 'numpy'] sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES) - # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. @@ -64,12 +65,16 @@ def __getattr__(cls, name): # ones. extensions = [ 'sphinx.ext.autodoc', + 'sphinx.ext.intersphinx', 'sphinx.ext.viewcode', 'sphinx.ext.doctest', 'sphinx.ext.napoleon', # Sphinx >= 1.3 #'sphinxcontrib.napoleon' # Sphinx 1.2 ] +if spelling is not None: + extensions.append('sphinxcontrib.spelling') + # Don't test blocks that are not doctest directive blocks - e.g. all the # code in alternitives.rst doctest_test_doctest_blocks = "" @@ -86,18 +91,24 @@ def __getattr__(cls, name): # The master toctree document. master_doc = 'index' + +base_dir = os.path.join(os.path.dirname(__file__), os.pardir) +about = {} +with open(os.path.join(base_dir, "phe", "__about__.py")) as f: + exec(f.read(), about) + # General information about the project. project = 'python-paillier' -copyright = '2016, DATA61 | CSIRO' +copyright = about['__copyright__'] # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # -# The short X.Y version. -version = '1.3' # The full version, including alpha/beta/rc tags. -release = '1.3.1' +version = about['__version__'] +# The short X.Y version. +release = pkg_resources.parse_version(version).base_version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -140,10 +151,6 @@ def __getattr__(cls, name): # -- Options for HTML output ---------------------------------------------- -# The theme to use for HTML and HTML Help pages. See the documentation for -# a list of builtin themes. -html_theme = 'nature' - # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. diff --git a/docs/requirements.txt b/docs/requirements.txt index 9bac57b..6390dce 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,2 +1,2 @@ -sphinx==1.6.2 -sphinxcontrib-napoleon==0.6.1 +sphinx>=1.6.2 +sphinxcontrib-napoleon>=0.6.1 diff --git a/phe/__about__.py b/phe/__about__.py new file mode 100644 index 0000000..4183cf3 --- /dev/null +++ b/phe/__about__.py @@ -0,0 +1,19 @@ +from __future__ import absolute_import, division, print_function + +__all__ = [ + "__title__", "__summary__", "__uri__", "__version__", "__author__", + "__email__", "__license__", "__copyright__", +] + +__title__ = "phe" +__summary__ = "Partially Homomorphic Encryption library for Python" +__uri__ = "https://github.com/n1analytics/python-paillier" + +# We use semantic versioning - semver.org +__version__ = "1.3.1-dev0" + +__author__ = "N1 Analytics developers" +__email__ = "info@n1analytics.com" + +__license__ = "GPLv3" +__copyright__ = "Copyright 2013-2018 {0}".format(__author__) diff --git a/phe/__init__.py b/phe/__init__.py index 43951b2..3e89277 100644 --- a/phe/__init__.py +++ b/phe/__init__.py @@ -1,5 +1,4 @@ -import pkg_resources - +from phe.__about__ import * from phe.encoding import EncodedNumber from phe.paillier import generate_paillier_keypair from phe.paillier import EncryptedNumber @@ -12,6 +11,3 @@ import phe.command_line except ImportError: pass - -__version__ = pkg_resources.get_distribution('phe').version -__author__ = 'N1 Analytics' diff --git a/setup.py b/setup.py index bbbd9ee..ed8a37c 100644 --- a/setup.py +++ b/setup.py @@ -19,23 +19,21 @@ here = os.path.abspath(os.path.dirname(__file__)) - -def find_version(): - # Note the version is also in the docs/conf.py file - # We use semantic versioning - semver.org - return "1.3.1" +about = {} +with open(os.path.join(here, "phe", "__about__.py")) as f: + exec(f.read(), about) setup( - name="phe", - version=find_version(), - description="Partially Homomorphic Encryption library for Python", + name=about['__title__'], + version=about['__version__'], + description=about['__summary__'], long_description=open(os.path.join(here, "README.rst")).read(), - url="https://github.com/n1analytics/python-paillier", + url=about['__uri__'], download_url="https://pypi.python.org/pypi/phe/#downloads", - author="Data61 | CSIRO", - author_email="brian.thorne@data61.csiro.au", - license="GPLv3", + author=about['__author__'], + author_email=about['__email__'], + license=about['__license__'], classifiers=[ 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 'Natural Language :: English',