Skip to content

Commit 186bf16

Browse files
authored
Merge pull request #1 from mahos/merging
Add system to build from split content
2 parents 48907d0 + 4e94fb6 commit 186bf16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+6085
-1837
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010
_build/
1111
_static/thumbs/
1212
site/
13+
build-all/
14+
build-local/
15+
loc_built_site/
16+
full_site/
17+
version-menu.html
18+
build_config.py
19+
1320

1421
# Byte-compiled / optimized / DLL files
1522
__pycache__/

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ site:
2323
rm -rf site
2424
make clean
2525
make html
26+
make latex
2627
cp -r $(BUILDDIR)/html site
2728
@echo "Build finished. The HTML pages are in site/html."
2829

30+
31+

README.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,48 @@ largely based on the [Read The Doc theme](https://github.com/rtfd/sphinx_rtd_the
88
# License
99
The documentation can be distributed for free use under the [Creative Commons Attribution-ShareAlike 4.0 International Public License](https://creativecommons.org/licenses/by-sa/4.0/). Any copy or derivation of the documentation must include attribution to "DataJoint contributors" and include the URL reference https://docs.datajoint.io
1010

11-
# Building locally
12-
1. Fork and clone the repository to your local machine.
13-
2. Install requirements using `pip3 install -r requirements.txt`
14-
3. Build the website by running `make site`. This will build and generate the static website in the `site` directory. (Windows users should run `sphinx-build . _build` from the `contents` directory.)
15-
4. Move inside the `site` folder (or the `_build` folder on Windows) and run the following command to launch a locally web server:
11+
12+
# In-Development: Building All Versions (Full Site)
13+
1. Clone the repository to your local machine.
14+
2. Currently this will build using `testDocMain.git`, `testDocMatlab.git` and `testDocPython.git` repo. This will eventually need to be switched out to the actual official DJ documentation repositories.
15+
3. Build the website by running `python build-all.py`. This will build and generate the static website in the `full_site` directory.
16+
- Note for Windows users: Please manually remove the `build-all` folder before running `python build-all.py` for building second time and on...
17+
4. Move inside the `full_site` folder and run the following command to launch a local web server:
18+
```bash
19+
$ python3 -m http.server
20+
```
21+
This should launch a HTTP server locally serving files from the `full_site` directory.
22+
5. Finally open up a web browser and navigate to `http://localhost:8000` - you should see the built documentation page. The port (i.e. the number after the colon `:`) may differ - refer to the output of the command from the step above for the actual port to use.
23+
6. If you made changes to the documentation source but you're not seeing the changes reflected, that is because this command builds from contents that are already pushed and tagged in the git repository. Please build locally to test, and then push with updated version numbers to see the changes in the full_site building.
24+
7. To stop the server, hit `Ctrl+C` in the terminal window that's running the server.
25+
26+
# In-Development: Building Locally/Partially
27+
1. Fork and clone the repository to your local machine. Note: datajoint-docs now only contains the common documentions. If you are writing for a specific language, you also need to clone the datajoint-matlab or datajoint-python repository and make sure they are placed on the same level as the datajoint-docs folder.
28+
2. Rename the cloned folder to `datajoint-docs`. If you cloned the Python/MATLAB repository for local development and building, make sure to rename the folders to `datajoint-python` and `datajoint-matlab` respectively.
29+
3. Build the website by running `python build-local.py`. This will build and generate the static website in the `loc_built_site` directory.
30+
31+
- Note for Windows users: Please manually remove the `build-local` folder before running `python build-local.py` for building second time and on...
32+
- Note 1: `python build-local.py` defaults to building the most updated local common documentation. If you have both `datajoint-matlab` or `datajoint-python` folder locally on the same level, then this will build using those local folders (check and edit the `build-config.py` to make sure the local language folders are correctly placed). If you don't have a local language-specific folder, then it will still build using the most current lang-specific documentation on its respective git repository.
33+
- Note 2: If you want to test-build a specific language version locally, then add `python/matlab_tag=(version)` after the `python build-local.py`. For example, `python build-local.py matlab_tag=v3.2.5` or `python build-local.py python_tag=v0.9.4` and this should automatically grab the matching common version for building. Make sure you are specifying the full version tag (and not the abbreviated v3.2 in this case).
34+
Note 3: If for some reason, you don't want to build using the local common version, you can also build using the most updated common version on the git repository by running `python build-local.py False` or `python build-local.py loc_comm=False`. This is mostly likely not going to work well if you already have a pre-existing local language-specific folder.
35+
4. Move inside the `loc_built_site` folder and run the following command to launch a local web server:
1636
```bash
1737
$ python3 -m http.server
1838
```
19-
This should launch a HTTP server locally serving files from the `site` directory.
20-
5. Finally open up a web browser and navigate to `http://localhost:8000` - you should see the built documentation page. The port (i.e. the number after the color `:`) may differ - refer to the output of the command from the step above for the actual port to use.
21-
6. If you made changes to the documentation source, rerun `make site` in a separate terminal window, and then refresh the page in the browser - you should see the changes reflected.
22-
7. To stop the server, hit `Ctrl+C` in the termianl window that's running the server.
39+
This should launch a HTTP server locally serving files from the `loc_built_site` directory.
40+
5. Finally open up a web browser and navigate to `http://localhost:8000` - you should see the built documentation page. The port (i.e. the number after the colon `:`) may differ - refer to the output of the command from the step above for the actual port to use.
41+
6. To stop the server, hit `Ctrl+C` in the terminal window that's running the server.
42+
43+
# Notes on Tagging
44+
1. Before you tag anything, please `git tag` to make sure you see the current tag status.
45+
2. In the `datajoint-docs` folder, `build-version.json` specifies which language versions to build in the build-all/full-build-mode. If you specify v3.2 in matlab, then the site will be built using the most recent tag (ex. v3.2.5 will be used to build, not v3.2.4).
46+
3. In the language-specific folder, all documentation contents are inside the `/docs` directory. Inside, you will see a `_version_common.json` file, which should only contain one corresponding common version tag for this language folder to be build alongside. Note that this file specifies the full-tag version (ex. v0.0.3) for the common version.
47+
(Not sure about how we will coordinate this with the team yet: When you update content in the lang-specific documentation and you also have made changes in the common version to reflect the change, make sure you give a new tag to the common version, update this `_version_common.json` with the new tag, then also add a new tag (should we?) for the specific language version.)
48+
4. to add a tag: `git tag -a v3.2.5 -m "some message"`
49+
to delete local tag: `git tag -d v3.2.5`
50+
to delete already-pushed tag: `git push origin :refs/tags/v3.2.5`
51+
to push with tag `git push origin v3.2.5`
52+
2353
2454
# Guidelines for Writing
2555
- For inserting a SQL code-block, be sure to use `.. code-block:: mysql` (and NOT `SQL`)

build-all.py

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
import os
2+
from os import path
3+
import json
4+
import glob
5+
import shutil
6+
import subprocess
7+
import platform
8+
from util import get_newest_tag
9+
from util import copy_contents
10+
11+
# default values in case the build config file is missing
12+
git_urls = {
13+
'common': "https://github.com/datajoint/datajoint-docs.git",
14+
'matlab': "https://github.com/datajoint/datajoint-matlab.git",
15+
'python': "https://github.com/datajoint/datajoint-python.git"
16+
}
17+
18+
def create_build_folders(lang):
19+
"""
20+
Prepares the necessary parts for full-versioned documentation site building by
21+
cloning and checking out appropriate tags from the `lang` respective repositories.
22+
Prepared parts will be inside `build-all` directory
23+
"""
24+
raw_tags = subprocess.Popen(["git", "tag"], cwd= path.join("build-all", "datajoint-" + lang), stdout=subprocess.PIPE).communicate()[0].decode("utf-8").split()
25+
26+
with open("build_versions.json") as f:
27+
print(f)
28+
min_tags = json.load(f)
29+
30+
tags = [get_newest_tag(t, raw_tags) for t in min_tags[lang]]
31+
32+
for tag in tags:
33+
subprocess.Popen(["git", "checkout", tag],
34+
cwd=path.join("build-all", "datajoint-" + lang), stdout=subprocess.PIPE).wait()
35+
dsrc_lang = path.join("build-all", "datajoint-" + lang, "docs-parts")
36+
dst_build_folder = path.join("build-all", lang + "-" + tag)
37+
dst_main = path.join(dst_build_folder, "contents")
38+
dst_temp = path.join(dst_main, "comm")
39+
40+
if path.exists(dst_build_folder):
41+
shutil.rmtree(dst_build_folder)
42+
43+
# copy over the lang source doc contents into the build folder
44+
shutil.copytree(dsrc_lang, dst_main)
45+
46+
# grab which version of the common folder the lang doc needs to be merged with
47+
with open(path.join(dsrc_lang, "version_common.json")) as f:
48+
# expected in this format { "comm_version" : "v0.0"}
49+
version_info = json.load(f)
50+
51+
raw_tags_comm = subprocess.Popen(["git", "tag"], cwd=path.join("build-all", "datajoint-docs"), stdout=subprocess.PIPE).communicate()[0].decode("utf-8").split()
52+
comm_to_build = get_newest_tag(version_info['comm_version'], raw_tags_comm)
53+
54+
subprocess.Popen(["git", "checkout", comm_to_build],cwd=path.join("build-all", "datajoint-docs"), stdout=subprocess.PIPE).wait()
55+
dsrc_comm = path.join("build-all", "datajoint-docs", "contents")
56+
# copy over the cmmon source doc contents into the build folder
57+
shutil.copytree(dsrc_comm, dst_temp)
58+
59+
# unpacking the content of common into lang-specific build folder
60+
copy_contents(dst_temp, dst_main)
61+
62+
# removing the temporary comm folder because that shouldn't get build
63+
shutil.rmtree(dst_temp)
64+
65+
# copy the datajoint_theme folder, conf.py and makefile for individual lang-ver folder building
66+
shutil.copytree("datajoint_theme", path.join(dst_build_folder, "datajoint_theme"))
67+
shutil.copy2("Makefile", path.join(dst_build_folder, "Makefile"))
68+
shutil.copy2(path.join("contents", "conf.py"), path.join(dst_build_folder, "contents", "conf.py"))
69+
shutil.copy2("report.txt", path.join(dst_build_folder, "report.txt"))
70+
71+
# add current_version <p> tag into the datajoint_theme folder
72+
with open(path.join(dst_build_folder, 'datajoint_theme', 'this_version.html'), 'w+') as f:
73+
f.write('<p class="thisVersion">' + lang + "-" + ".".join(tag.split(".")[:-1]) + '</p>')
74+
75+
# add current_version as release into the conf.py file (for pdf generation)
76+
with open(path.join(dst_build_folder, "contents", "conf.py"), 'a+') as f:
77+
f.write('release = "' + lang + "-" + ".".join(tag.split(".")[:-1]) + '"')
78+
79+
80+
# generate site folder with all contents using the above build folders
81+
def make_full_site():
82+
"""
83+
Builds the full-versioned site using the `build-all` directory and puts the resulting html/pdf into `full_site` directory.
84+
"""
85+
86+
if path.exists('full_site'):
87+
shutil.rmtree('full_site')
88+
os.makedirs('full_site')
89+
90+
# build individual lang-ver folder
91+
to_make = [folder for folder in glob.glob(path.join('build-all', '**')) if not path.basename(folder).startswith('datajoint')]
92+
93+
with open("build_versions.json") as f:
94+
min_tags = json.load(f)
95+
# min_tags look like this {'python': ['v0.9'], 'matlab': ['v3.2']}
96+
97+
# create full version-menu listing using the built folders from above
98+
with open(path.join('datajoint_theme', 'version-menu.html'), 'w+') as f:
99+
for lang in min_tags:
100+
for ver in min_tags[lang]:
101+
# f.write('<li class="version-menu"><a href="/' + lang + "/" + ver + '">' + lang + "-" + ver + '</a></li>\n')
102+
f.write('<li class="version-menu"><a href="/{lang}/{ver}">{lang}-{ver}</a></li>\n'.format(lang=lang, ver=ver))
103+
104+
# copy over the full version-menu listing to datajoint_theme FIRST,
105+
# then build individual folders, and copy to full_site folder
106+
107+
for folder in to_make:
108+
shutil.copy2(path.join('datajoint_theme', 'version-menu.html'), path.join(folder, "datajoint_theme", "version-menu.html"))
109+
if platform.system() == "Windows":
110+
subprocess.Popen(["sphinx-build", ".", "..\_build\html"], cwd=path.join(folder, "contents")).wait() # builds html by default
111+
subprocess.Popen(["sphinx-build", "-b", "latex", ".", "..\_build\latex"], cwd=path.join(folder, "contents")).wait()
112+
if path.exists(path.join(folder, "site")):
113+
shutil.rmtree(path.join(folder, "site"))
114+
os.makedirs(path.join(folder, "site"))
115+
copy_contents(path.join(folder, "_build", "html"), path.join(folder, "site"))
116+
else:
117+
subprocess.Popen(["make", "site"], cwd=folder).wait()
118+
119+
# making pdf out of the latex directory only if pdflatex runs
120+
try:
121+
subprocess.Popen(["pdflatex", "DataJointDocs.tex"], cwd=path.join(folder, '_build', 'latex')).wait()
122+
subprocess.Popen(["pdflatex", "DataJointDocs.tex"], cwd=path.join(folder, '_build', 'latex')).wait()
123+
except:
124+
print("Latex environment not set up - no pdf will be generated")
125+
126+
lang_version = folder.split(os.sep)[1] # 'matlab-v3.2.2'
127+
lang, version = lang_version.split("-") # e.g. 'matlab', 'v3.2.2'
128+
abbr_ver = '.'.join(version.split('.')[:-1]) # e.g. 'v3.2'
129+
abbr_lang_ver = lang + '-' + abbr_ver
130+
131+
shutil.copytree(path.join(folder, "site"), path.join('full_site', lang_version.split("-")[0], abbr_ver))
132+
133+
if path.exists(path.join(folder, '_build', 'latex', 'DataJointDocs.pdf')):
134+
os.rename(path.join(folder, '_build', 'latex', 'DataJointDocs.pdf'), path.join(folder, '_build', 'latex', 'DataJointDocs_{}.pdf'.format(abbr_lang_ver)))
135+
shutil.copy2(path.join(folder, '_build', 'latex', 'DataJointDocs_{}.pdf'.format(abbr_lang_ver)), path.join('full_site', lang_version.split("-")[0], abbr_ver))
136+
137+
for lang in min_tags:
138+
ver_list=[]
139+
for to_sort in glob.glob(path.join('full_site', lang, '**')):
140+
ver_list.append(float((path.basename(to_sort).strip("v"))))
141+
# ensure clean format in case float above produces something like 3.70000000000001
142+
newest_ver = 'v{:.1f}'.format(max(ver_list))
143+
src_path = path.join('full_site', lang, newest_ver)
144+
copy_contents(src_path, path.join('full_site', lang))
145+
146+
copy_contents('dj_root_theme', 'full_site')
147+
copy_contents(path.join('full_site', 'python', '_static'), path.join('full_site', '_static'))
148+
149+
150+
##########################################################
151+
####====== begin building full version doc here ======####
152+
if __name__ == "__main__":
153+
# if build_config file exists, override the default git_url values with config values
154+
try:
155+
import build_config as config
156+
git_urls = dict(git_urls, **config.config_urls)
157+
except:
158+
print("build_config.py file missing - will use default values for git repo")
159+
160+
# ensure build folder is clean before the build
161+
if path.exists('build-all'):
162+
shutil.rmtree('build-all')
163+
os.makedirs('build-all')
164+
165+
subprocess.Popen(
166+
["git", "clone", git_urls['common'], "datajoint-docs"], cwd="build-all").wait()
167+
168+
subprocess.Popen(
169+
["git", "clone", git_urls['matlab'], "datajoint-matlab"], cwd="build-all").wait()
170+
171+
subprocess.Popen(
172+
["git", "clone", git_urls['python'], "datajoint-python"], cwd="build-all").wait()
173+
174+
create_build_folders("matlab")
175+
create_build_folders("python")
176+
make_full_site()

0 commit comments

Comments
 (0)