Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ MANIFEST
# Sphinx
docs/api
docs/_build
docs/_facility_pages

# Eclipse editor project files
.project
Expand Down
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ matrix:
- python: 2.7
env: SETUP_CMD='test --coverage'

# Generate docs in Python 2
- python: 2.7
env: SETUP_CMD='build_docs'

# Do a coverage test in Python 3.
- python: 3.6
env: SETUP_CMD='test --coverage'
Expand Down
44 changes: 44 additions & 0 deletions docs/_templates/facility_page.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Filters of Observation Facility: {{ facility }}
====================================================

{% set facility_data=data[data['Obs. Facility']==facility] %}
{% set inst_list=facility_data['Instrument'].unique().tolist() %}
{% for inst in inst_list %}

{% if inst!='NA' %}
{% if loop.first %}
Following **Instruments** are present:

{% endif %}

{{ inst }}
--------------------------

{% endif %}

{% set inst_data=facility_data[facility_data['Instrument']==inst] %}

.. list-table::
:header-rows: 1

* - {{ inst_data.index.name }}
{% for col_name in inst_data.columns.values %}
- {{ col_name }}
{% endfor %}

{% for filter_info in inst_data.itertuples() %}
{% for info in filter_info %}
{% if loop.first %}
* - {{ info }}
{% elif loop.last %}
- {{ info|replace('_ ','\_ ') }}
{% else %}
- {{ info }}
{% endif %}
{% endfor %}
{% endfor %}


<Plots>

{% endfor %}
52 changes: 52 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,55 @@

edit_on_github_source_root = ""
edit_on_github_doc_root = "docs"


# Render rst pages as a jinja template to be able
# to generate rst docs from data (i.e. passed to template context) ---------
def rst_jinja(app, docname, source):
if app.builder.format != 'html': # Make sure builder output is HTML
return
src = source[0]
context = app.config.html_context # context dictionary, passed for rendering
context.update(facility_context(docname))
rendered = app.builder.templates.render_string(src, context)
source[0] = rendered

def facility_context(docname):
dirs_in_path = docname.split(os.sep)
if '_facility_pages' in dirs_in_path[:-1]:
# doc file (.rst) lies in directory "_facility_pages"
facility_name = dirs_in_path[-1]
context = {'facility': facility_name}
else:
context = {}
return context

def setup(app):
app.connect("source-read", rst_jinja)


import wsynphot
import pandas as pd
import shutil

# Storing data into variables ------------------
try:
df = wsynphot.list_filters()
except IOError: # If filter_data.h5 not present
wsynphot.download_filter_data()
df = wsynphot.list_filters()
# Obtain list of Obsv. facilities from df
facility_list = df['Obs. Facility'].unique().tolist()

# Pass data variables to html_context for rendering templates ------
html_context = {
'data': df,
'facility_list': facility_list
}

# Automatically create(or overwrite) doc for filters of each obsv. facility
# by using facilty_page.rst as template file to populate all facilty pages
os.makedirs('_facility_pages', exist_ok=True)
for facility in facility_list:
shutil.copyfile('_templates/facility_page.rst',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that really necesary?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is absolutely necessary. See, we're building a static documentation of a very large dataset (~4500 filters) so we need to distribute that data across different pages - for which we're putting them hierarchically as per the facilities they belong to. Since we need ~78 facility HTML pages, thus we have to provide Sphinx ~78 RST pages from which it can build HTML by rendering them differently using Jinja Template variables.

This is achieved by a single template file facility_page.rst as I explained in 1st comment. Think of _facilty_pages dir hence created, equivalent to _build dir which are solely generated & controlled by Sphinx while building docs, without requiring any user intervention. The only difference is _facilty_pages dir is created as a part of pre-build step immediately after command to build docs is given, and _build dir when rst is read & rendered. So they are more or less same which make sure that docs can be build, while at the same time they doesn't affect our repo (gitignored).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand this - I mean can you create them in the right directory

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think is right directory?

We can't put them in _build or _template dir, Sphinx doesn't read files from them. We can't put them in _static dir i.e. meant for custom stylesheets and other static files (like images, etc.), not at all for storing .rst files. I've accounted all options then used it and it gives desired results.

Sphinx docs even say that, "Sphinx is highly customizable but that means all you can do with them is not documented". I understand what I've done, is quite new to grasp, but consider it as a customized way to achieve what we want to implement.

I might be missing something, could you please elaborate what wrong do you see in it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not very new to grasp 😉 - you somehow create the files earlier and then move them - why not create them directly where they should live.

os.path.join('_facility_pages', '{0}.rst'.format(facility)))
Loading