Skip to content

Commit 2d14d11

Browse files
committed
Package.json single source of version
1 parent 695f1c8 commit 2d14d11

File tree

2 files changed

+68
-49
lines changed

2 files changed

+68
-49
lines changed

docs/source/conf.py

Lines changed: 55 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
# -*- coding: utf-8 -*-
33
#
4+
45
# jupyterannotate documentation build configuration file
56
#
67
# This file is execfile()d with the current directory set to its
@@ -23,14 +24,14 @@
2324
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
2425
# ones.
2526
extensions = [
26-
'sphinx.ext.autodoc',
27-
'sphinx.ext.viewcode',
28-
'sphinx.ext.intersphinx',
29-
'sphinx.ext.napoleon',
30-
'sphinx.ext.todo',
31-
'nbsphinx',
32-
'jupyter_sphinx',
33-
'nbsphinx_link',
27+
"sphinx.ext.autodoc",
28+
"sphinx.ext.viewcode",
29+
"sphinx.ext.intersphinx",
30+
"sphinx.ext.napoleon",
31+
"sphinx.ext.todo",
32+
"nbsphinx",
33+
"jupyter_sphinx",
34+
"nbsphinx_link",
3435
]
3536

3637
# Set the nbsphinx JS path to empty to avoid showing twice of the widgets
@@ -40,27 +41,28 @@
4041
# Ensure our extension is available:
4142
import sys
4243
from os.path import dirname, join as pjoin
44+
4345
docs = dirname(dirname(__file__))
4446
root = dirname(docs)
4547
sys.path.insert(0, root)
46-
sys.path.insert(0, pjoin(docs, 'sphinxext'))
48+
sys.path.insert(0, pjoin(docs, "sphinxext"))
4749

4850
# Add any paths that contain templates here, relative to this directory.
49-
templates_path = ['_templates']
51+
templates_path = ["_templates"]
5052

5153
# The suffix(es) of source filenames.
5254
# You can specify multiple suffix as a list of string:
5355
#
5456
# source_suffix = ['.rst', '.md']
55-
source_suffix = '.rst'
57+
source_suffix = ".rst"
5658

5759
# The master toctree document.
58-
master_doc = 'index'
60+
master_doc = "index"
5961

6062
# General information about the project.
61-
project = 'jupyterannotate'
62-
copyright = '2022, Stuart Quin'
63-
author = 'Stuart Quin'
63+
project = "jupyterannotate"
64+
copyright = "2022, Stuart Quin"
65+
author = "Stuart Quin"
6466

6567
# The version info for the project you're documenting, acts as replacement for
6668
# |version| and |release|, also used in various other places throughout the
@@ -71,17 +73,18 @@
7173

7274
# get version from python package:
7375
import os
76+
7477
here = os.path.dirname(__file__)
75-
repo = os.path.join(here, '..', '..')
76-
_version_py = os.path.join(repo, 'jupyterannotate', '_version.py')
78+
repo = os.path.join(here, "..", "..")
79+
_version_py = os.path.join(repo, "jupyterannotate", "_version.py")
7780
version_ns = {}
7881
with open(_version_py) as f:
7982
exec(f.read(), version_ns)
8083

8184
# The short X.Y version.
82-
version = '%i.%i' % version_ns['version_info'][:2]
85+
version = "%s.%s" % version_ns["version_info"][:2]
8386
# The full version, including alpha/beta/rc tags.
84-
release = version_ns['__version__']
87+
release = version_ns["__version__"]
8588

8689
# The language for content autogenerated by Sphinx. Refer to documentation
8790
# for a list of supported languages.
@@ -93,10 +96,10 @@
9396
# List of patterns, relative to source directory, that match files and
9497
# directories to ignore when looking for source files.
9598
# This patterns also effect to html_static_path and html_extra_path
96-
exclude_patterns = ['**.ipynb_checkpoints']
99+
exclude_patterns = ["**.ipynb_checkpoints"]
97100

98101
# The name of the Pygments (syntax highlighting) style to use.
99-
pygments_style = 'sphinx'
102+
pygments_style = "sphinx"
100103

101104
# If true, `todo` and `todoList` produce output, else they produce nothing.
102105
todo_include_todos = False
@@ -114,13 +117,13 @@
114117
# Add any paths that contain custom static files (such as style sheets) here,
115118
# relative to this directory. They are copied after the builtin static files,
116119
# so a file named "default.css" will overwrite the builtin "default.css".
117-
html_static_path = ['_static']
120+
html_static_path = ["_static"]
118121

119122

120123
# -- Options for HTMLHelp output ------------------------------------------
121124

122125
# Output file base name for HTML help builder.
123-
htmlhelp_basename = 'jupyterannotatedoc'
126+
htmlhelp_basename = "jupyterannotatedoc"
124127

125128

126129
# -- Options for LaTeX output ---------------------------------------------
@@ -129,15 +132,12 @@
129132
# The paper size ('letterpaper' or 'a4paper').
130133
#
131134
# 'papersize': 'letterpaper',
132-
133135
# The font size ('10pt', '11pt' or '12pt').
134136
#
135137
# 'pointsize': '10pt',
136-
137138
# Additional stuff for the LaTeX preamble.
138139
#
139140
# 'preamble': '',
140-
141141
# Latex figure (float) alignment
142142
#
143143
# 'figure_align': 'htbp',
@@ -147,8 +147,13 @@
147147
# (source start file, target name, title,
148148
# author, documentclass [howto, manual, or own class]).
149149
latex_documents = [
150-
(master_doc, 'jupyterannotate.tex', 'jupyterannotate Documentation',
151-
'Stuart Quin', 'manual'),
150+
(
151+
master_doc,
152+
"jupyterannotate.tex",
153+
"jupyterannotate Documentation",
154+
"Stuart Quin",
155+
"manual",
156+
),
152157
]
153158

154159

@@ -157,10 +162,7 @@
157162
# One entry per manual page. List of tuples
158163
# (source start file, name, description, authors, manual section).
159164
man_pages = [
160-
(master_doc,
161-
'jupyterannotate',
162-
'jupyterannotate Documentation',
163-
[author], 1)
165+
(master_doc, "jupyterannotate", "jupyterannotate Documentation", [author], 1)
164166
]
165167

166168

@@ -170,27 +172,30 @@
170172
# (source start file, target name, title, author,
171173
# dir menu entry, description, category)
172174
texinfo_documents = [
173-
(master_doc,
174-
'jupyterannotate',
175-
'jupyterannotate Documentation',
176-
author,
177-
'jupyterannotate',
178-
'A Custom Jupyter Widget Library',
179-
'Miscellaneous'),
175+
(
176+
master_doc,
177+
"jupyterannotate",
178+
"jupyterannotate Documentation",
179+
author,
180+
"jupyterannotate",
181+
"A Custom Jupyter Widget Library",
182+
"Miscellaneous",
183+
),
180184
]
181185

182186

183187
# Example configuration for intersphinx: refer to the Python standard library.
184-
intersphinx_mapping = {'https://docs.python.org/': None}
188+
intersphinx_mapping = {"https://docs.python.org/": None}
185189

186190
# Read The Docs
187191
# on_rtd is whether we are on readthedocs.org, this line of code grabbed from
188192
# docs.readthedocs.org
189-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
193+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
190194

191195
if not on_rtd: # only import and set the theme if we're building docs locally
192196
import sphinx_rtd_theme
193-
html_theme = 'sphinx_rtd_theme'
197+
198+
html_theme = "sphinx_rtd_theme"
194199
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
195200

196201
# otherwise, readthedocs.org uses their theme by default, so no need to specify it
@@ -199,15 +204,18 @@
199204
# Uncomment this line if you have know exceptions in your included notebooks
200205
# that nbsphinx complains about:
201206
#
202-
nbsphinx_allow_errors = True # exception ipstruct.py ipython_genutils
207+
nbsphinx_allow_errors = True # exception ipstruct.py ipython_genutils
203208

204209
from sphinx.util import logging
210+
205211
logger = logging.getLogger(__name__)
206212

213+
207214
def setup(app):
208215
def add_scripts(app):
209-
for fname in ['helper.js', 'embed-bundle.js']:
210-
if not os.path.exists(os.path.join(here, '_static', fname)):
211-
logger.warning('missing javascript file: %s' % fname)
216+
for fname in ["helper.js", "embed-bundle.js"]:
217+
if not os.path.exists(os.path.join(here, "_static", fname)):
218+
logger.warning("missing javascript file: %s" % fname)
212219
app.add_js_file(fname)
213-
app.connect('builder-inited', add_scripts)
220+
221+
app.connect("builder-inited", add_scripts)

jupyterannotate/_version.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,16 @@
44
# Copyright (c) Stuart Quin.
55
# Distributed under the terms of the Modified BSD License.
66

7-
version_info = (0, 1, 2)
8-
__version__ = ".".join(map(str, version_info))
7+
import json
8+
from os.path import exists
9+
10+
if exists("./package.json"):
11+
package_json = None
12+
with open("./package.json", "r") as package_json_file:
13+
package_json = json.loads(package_json_file.read())
14+
15+
__version__ = package_json["version"]
16+
else:
17+
__version__ = "0.0.0"
18+
19+
version_info = tuple(__version__.split("."))

0 commit comments

Comments
 (0)