Skip to content

Commit 72c3e4d

Browse files
authored
Fix sphinx build (#56)
* Grab version from setup.py when build docs * Move to one source of package version
1 parent 0318db1 commit 72c3e4d

File tree

5 files changed

+56
-36
lines changed

5 files changed

+56
-36
lines changed

docs/conf.py

+24-17
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,42 @@
1414

1515
import sys
1616
import os
17-
17+
import pkg_resources
1818
import pip
1919

2020
try:
21-
from mock import Mock as MagicMock
21+
from unittest.mock import MagicMock
2222
except ImportError:
2323
def install(package):
2424
pip.main(['install', package])
2525

2626
install('mock')
2727
from mock import Mock as MagicMock
2828

29+
try:
30+
from sphinxcontrib import spelling
31+
except ImportError:
32+
spelling = None
33+
2934

3035
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
31-
if on_rtd:
32-
html_theme = 'default'
33-
else:
34-
html_theme = 'nature'
36+
37+
html_theme = 'nature'
3538

3639
# ------------------------------------------------------------------- #
3740
# MOCK MODULES
3841
# ------------------------------------------------------------------- #
39-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
4042

4143
if on_rtd:
4244
class Mock(MagicMock):
4345
@classmethod
4446
def __getattr__(cls, name):
45-
return Mock()
47+
return MagicMock()
4648

4749
MOCK_MODULES = ['gmpy2', 'numpy']
4850
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)
4951

5052

51-
5253
# If extensions (or modules to document with autodoc) are in another directory,
5354
# add these directories to sys.path here. If the directory is relative to the
5455
# documentation root, use os.path.abspath to make it absolute, like shown here.
@@ -64,12 +65,16 @@ def __getattr__(cls, name):
6465
# ones.
6566
extensions = [
6667
'sphinx.ext.autodoc',
68+
'sphinx.ext.intersphinx',
6769
'sphinx.ext.viewcode',
6870
'sphinx.ext.doctest',
6971
'sphinx.ext.napoleon', # Sphinx >= 1.3
7072
#'sphinxcontrib.napoleon' # Sphinx 1.2
7173
]
7274

75+
if spelling is not None:
76+
extensions.append('sphinxcontrib.spelling')
77+
7378
# Don't test blocks that are not doctest directive blocks - e.g. all the
7479
# code in alternitives.rst
7580
doctest_test_doctest_blocks = ""
@@ -86,18 +91,24 @@ def __getattr__(cls, name):
8691
# The master toctree document.
8792
master_doc = 'index'
8893

94+
95+
base_dir = os.path.join(os.path.dirname(__file__), os.pardir)
96+
about = {}
97+
with open(os.path.join(base_dir, "phe", "__about__.py")) as f:
98+
exec(f.read(), about)
99+
89100
# General information about the project.
90101
project = 'python-paillier'
91-
copyright = '2016, DATA61 | CSIRO'
102+
copyright = about['__copyright__']
92103

93104
# The version info for the project you're documenting, acts as replacement for
94105
# |version| and |release|, also used in various other places throughout the
95106
# built documents.
96107
#
97-
# The short X.Y version.
98-
version = '1.3'
99108
# The full version, including alpha/beta/rc tags.
100-
release = '1.3.1'
109+
version = about['__version__']
110+
# The short X.Y version.
111+
release = pkg_resources.parse_version(version).base_version
101112

102113
# The language for content autogenerated by Sphinx. Refer to documentation
103114
# for a list of supported languages.
@@ -140,10 +151,6 @@ def __getattr__(cls, name):
140151

141152
# -- Options for HTML output ----------------------------------------------
142153

143-
# The theme to use for HTML and HTML Help pages. See the documentation for
144-
# a list of builtin themes.
145-
html_theme = 'nature'
146-
147154
# Theme options are theme-specific and customize the look and feel of a theme
148155
# further. For a list of options available for each theme, see the
149156
# documentation.

docs/requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sphinx==1.6.2
2-
sphinxcontrib-napoleon==0.6.1
1+
sphinx>=1.6.2
2+
sphinxcontrib-napoleon>=0.6.1

phe/__about__.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from __future__ import absolute_import, division, print_function
2+
3+
__all__ = [
4+
"__title__", "__summary__", "__uri__", "__version__", "__author__",
5+
"__email__", "__license__", "__copyright__",
6+
]
7+
8+
__title__ = "phe"
9+
__summary__ = "Partially Homomorphic Encryption library for Python"
10+
__uri__ = "https://github.com/n1analytics/python-paillier"
11+
12+
# We use semantic versioning - semver.org
13+
__version__ = "1.3.1-dev0"
14+
15+
__author__ = "N1 Analytics developers"
16+
__email__ = "[email protected]"
17+
18+
__license__ = "GPLv3"
19+
__copyright__ = "Copyright 2013-2018 {0}".format(__author__)

phe/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import pkg_resources
2-
1+
from phe.__about__ import *
32
from phe.encoding import EncodedNumber
43
from phe.paillier import generate_paillier_keypair
54
from phe.paillier import EncryptedNumber
@@ -12,6 +11,3 @@
1211
import phe.command_line
1312
except ImportError:
1413
pass
15-
16-
__version__ = pkg_resources.get_distribution('phe').version
17-
__author__ = 'N1 Analytics'

setup.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,21 @@
1919

2020
here = os.path.abspath(os.path.dirname(__file__))
2121

22-
23-
def find_version():
24-
# Note the version is also in the docs/conf.py file
25-
# We use semantic versioning - semver.org
26-
return "1.3.1"
22+
about = {}
23+
with open(os.path.join(here, "phe", "__about__.py")) as f:
24+
exec(f.read(), about)
2725

2826

2927
setup(
30-
name="phe",
31-
version=find_version(),
32-
description="Partially Homomorphic Encryption library for Python",
28+
name=about['__title__'],
29+
version=about['__version__'],
30+
description=about['__summary__'],
3331
long_description=open(os.path.join(here, "README.rst")).read(),
34-
url="https://github.com/n1analytics/python-paillier",
32+
url=about['__uri__'],
3533
download_url="https://pypi.python.org/pypi/phe/#downloads",
36-
author="Data61 | CSIRO",
37-
author_email="[email protected]",
38-
license="GPLv3",
34+
author=about['__author__'],
35+
author_email=about['__email__'],
36+
license=about['__license__'],
3937
classifiers=[
4038
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
4139
'Natural Language :: English',

0 commit comments

Comments
 (0)