Skip to content

Commit

Permalink
Fix sphinx build (#56)
Browse files Browse the repository at this point in the history
* Grab version from setup.py when build docs
* Move to one source of package version
  • Loading branch information
hardbyte authored Jan 25, 2018
1 parent 0318db1 commit 72c3e4d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
41 changes: 24 additions & 17 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,42 @@

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])

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.
Expand All @@ -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 = ""
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sphinx==1.6.2
sphinxcontrib-napoleon==0.6.1
sphinx>=1.6.2
sphinxcontrib-napoleon>=0.6.1
19 changes: 19 additions & 0 deletions phe/__about__.py
Original file line number Diff line number Diff line change
@@ -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__)
6 changes: 1 addition & 5 deletions phe/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,6 +11,3 @@
import phe.command_line
except ImportError:
pass

__version__ = pkg_resources.get_distribution('phe').version
__author__ = 'N1 Analytics'
22 changes: 10 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 72c3e4d

Please sign in to comment.