Skip to content

Commit

Permalink
Merge 2745c92 into 69819a9
Browse files Browse the repository at this point in the history
  • Loading branch information
honzajavorek committed Jan 3, 2019
2 parents 69819a9 + 2745c92 commit 87edb9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 64 deletions.
55 changes: 1 addition & 54 deletions docs/conf.py
Expand Up @@ -2,7 +2,6 @@
import sys
import re
import json
import subprocess
import urllib.request

from sphinx.errors import SphinxError
Expand All @@ -20,24 +19,6 @@
# Explicitly put the extensions directory to Python path
sys.path.append(os.path.abspath('_extensions'))

# Detect whether the build happens on ReadTheDocs
IS_READTHEDOCS = os.environ.get('READTHEDOCS') == 'True'

# Specify paths
docs_dir = os.path.dirname(__file__)
project_dir = os.path.join(docs_dir, '..')
node_modules_bin_dir = os.path.join(project_dir, 'node_modules', '.bin')

# Install all npm dependencies if on ReadTheDocs. This requires the latest
# ReadTheDocs build image, which supports Node.js out of the box. This is
# specified in the readthedocs.yml in the root of the project.
if IS_READTHEDOCS:
subprocess.check_call('npm install', cwd=project_dir, shell=True)

# Load package.json data
with open(os.path.join(project_dir, 'package.json')) as f:
package_json = json.load(f)


# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -65,42 +46,8 @@
copyright = 'Apiary Czech Republic, s.r.o.'
author = 'Apiary'

# 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.
def get_release():
try:
# Is internet available? this is to be able to generate docs
# e.g. in train without internet connection
urllib.request.urlopen('https://www.npmjs.com/package/dredd', timeout=3)
except urllib.request.URLError as e:
if IS_READTHEDOCS:
# ReadTheDocs have problem to connect to npm, fail fast
raise SphinxError('Could not determine Dredd version: {}'.format(e))
else:
# Offline local development, use dummy release number
return package_json['version']
else:
# Online, ask Semantic Release what would be the next version
sem_rel_bin = os.path.join(node_modules_bin_dir, 'semantic-release')
sem_rel_output = subprocess.getoutput('{} pre'.format(sem_rel_bin))
match = re.search(r'determined version (\d+\.\d+\.\d+)', sem_rel_output, re.I)
if match:
# Semantic Release would use this version number
return match.group(1)

# Semantic Release wasn't able to determine a new version number,
# either because of some error or because there are no changes which
# would bump the version number. Stick to the latest released version.
return subprocess.getoutput('npm view dredd version').strip()

# The full version, including alpha/beta/rc tags.
release = get_release()
if not re.match(r'\d+\.\d+\.\d+', release):
raise SphinxError("'{}' does not look like version number".format(release))

# The short X.Y version.
version = release
version = 'latest'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down
19 changes: 9 additions & 10 deletions docs/internals.rst
Expand Up @@ -176,10 +176,10 @@ The Travis CI build uses following commands to deliver coverage reports:

The first mentioned command does following:

1. Uses `istanbul <https://github.com/gotwarlost/istanbul>`__ to instrument the JavaScript code
2. Runs the tests on the instrumented code using Mocha with a special lcov reporter, which gives us information about which lines were executed in the standard lcov format
3. Because some integration tests execute the ``bin/dredd`` script in a subprocess, we collect the coverage stats also in this file. The results are appended to a dedicated lcov file
4. All lcov files are then merged into one using the `lcov-result-merger <https://github.com/mweibel/lcov-result-merger>`__ utility and sent to Coveralls
#. Uses `istanbul <https://github.com/gotwarlost/istanbul>`__ to instrument the JavaScript code
#. Runs the tests on the instrumented code using Mocha with a special lcov reporter, which gives us information about which lines were executed in the standard lcov format
#. Because some integration tests execute the ``bin/dredd`` script in a subprocess, we collect the coverage stats also in this file. The results are appended to a dedicated lcov file
#. All lcov files are then merged into one using the `lcov-result-merger <https://github.com/mweibel/lcov-result-merger>`__ utility and sent to Coveralls

Hand-made combined Mocha reporter is used to achieve running tests and collecting coverage at the same time.

Expand Down Expand Up @@ -215,18 +215,17 @@ Even though alternatives exist (dredd.readthedocs.io, dredd.rtfd.io, or dredd.io
Building documentation locally
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The documentation is built by `Sphinx <http://www.sphinx-doc.org/>`__. To render it on your computer, you need `Python 3 <https://www.python.org/>`__ and `Node.js <http://nodejs.org/>`__.
The documentation is built by `Sphinx <http://www.sphinx-doc.org/>`__. To render it on your computer, you need `Python 3 <https://www.python.org/>`__.

1. Make sure ``node`` is an executable and ``npm install`` has been done for the Dredd directory.
2. `Get Python 3 <https://www.python.org/downloads/>`__. `ReadTheDocs <https://readthedocs.org/>`__ build the documentation with Python 3.6, so make sure you have this version.
3. Create a `virtual environment <https://docs.python.org/3/library/venv.html>`__ and activate it:
#. `Get Python 3 <https://www.python.org/downloads/>`__. `ReadTheDocs <https://readthedocs.org/>`__ build the documentation with Python 3.6, so make sure you have this version.
#. Create a `virtual environment <https://docs.python.org/3/library/venv.html>`__ and activate it:

.. code-block:: shell
python3 -m venv ./venv
source ./venv/bin/activate
4. Install dependencies for the docs:
#. Install dependencies for the docs:

.. code-block:: shell
Expand All @@ -246,7 +245,7 @@ Now you can use following commands:
Installation on ReadTheDocs
~~~~~~~~~~~~~~~~~~~~~~~~~~~

The final documentation gets published by `ReadTheDocs <https://readthedocs.org/>`__. Because the documentation needs some of the npm dependencies installed and ReadTheDocs do not support this in their default build environment, we force their latest build image, which includes Node.js out of the box, in the ``readthedocs.yml``. In the Sphinx' configuration file, ``docs/conf.py``, we make sure ``npm install`` is executed on ReadTheDocs.
The final documentation gets published by `ReadTheDocs <https://readthedocs.org/>`__. We force their latest build image in the ``readthedocs.yml`` to get Python 3.


Writing documentation
Expand Down

0 comments on commit 87edb9c

Please sign in to comment.