Skip to content

Commit

Permalink
Build readthedoc (#701)
Browse files Browse the repository at this point in the history
* change version limitation in mminstall.txt

* change version limitation in mminstall.txt

* add config files for readthedocs

* chmod 774 docs/en/stat.py

* change .readthedocs/yml

* fix typo
  • Loading branch information
GT9505 authored Aug 31, 2022
1 parent 1a074e5 commit 2d02bbe
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 5 deletions.
1 change: 0 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ python:
- requirements: requirements/docs.txt
- requirements: requirements/runtime.txt
- requirements: requirements/readthedocs.txt
- requirements: requirements/mminstall.txt
20 changes: 20 additions & 0 deletions docs/en/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
6 changes: 6 additions & 0 deletions docs/en/_static/css/readthedocs.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.header-logo {
background-image: url("../image/mmtrack-logo.png");
background-size: 145px 40px;
height: 40px;
width: 145px;
}
Binary file added docs/en/_static/image/mmtrack-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
135 changes: 135 additions & 0 deletions docs/en/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# Copyright (c) OpenMMLab. All rights reserved.
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import subprocess
import sys

import pytorch_sphinx_theme

sys.path.insert(0, os.path.abspath('../..'))

# -- Project information -----------------------------------------------------

project = 'MMTracking'
copyright = '2018-2021, OpenMMLab'
author = 'MMTracking Authors'
version_file = '../../mmtrack/version.py'


def get_version():
with open(version_file, 'r') as f:
exec(compile(f.read(), version_file, 'exec'))
return locals()['__version__']


# The full version, including alpha/beta/rc tags
release = get_version()

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

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
'recommonmark',
'sphinx_markdown_tables',
'sphinx_copybutton',
]

autodoc_mock_imports = [
'matplotlib', 'pycocotools', 'terminaltables', 'mmtrack.version',
'seaborn', 'motmetrics', 'torchvision', 'pandas', 'scipy'
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
source_suffix = {
'.rst': 'restructuredtext',
'.md': 'markdown',
}

# The master toctree document.
master_doc = 'index'

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'sphinx_rtd_theme'
html_theme = 'pytorch_sphinx_theme'
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
# 'logo_url': 'https://mmtracking.readthedocs.io/en/latest/',
'menu': [
{
'name': 'GitHub',
'url': 'https://github.com/open-mmlab/mmtracking'
},
{
'name':
'Upstream',
'children': [
{
'name': 'MMCV',
'url': 'https://github.com/open-mmlab/mmcv',
},
{
'name': 'MMDetection',
'url': 'https://github.com/open-mmlab/mmdetection',
},
]
},
],
# Specify the language of shared menu
'menu_lang':
'en'
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_css_files = ['css/readthedocs.css']

language = 'en'

# Enable ::: for my_st
myst_enable_extensions = ['colon_fence']
myst_heading_anchors = 3


def builder_inited_handler(app):
subprocess.run(['./stat.py'])


def setup(app):
app.connect('builder-inited', builder_inited_handler)
35 changes: 35 additions & 0 deletions docs/en/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
61 changes: 61 additions & 0 deletions docs/en/stat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python
# Copyright (c) OpenMMLab. All rights reserved.
import functools as func
import glob
import os.path as osp
import re

import numpy as np

url_prefix = 'https://github.com/open-mmlab/mmtracking/blob/master/'

files = sorted(glob.glob('../../configs/*/*/README.md'))

stats = []
titles = []
num_ckpts = 0

for f in files:
url = osp.dirname(f.replace('../../', url_prefix))

with open(f, 'r') as content_file:
content = content_file.read()

title = content.split('\n')[0].replace('#', '').strip()
ckpts = set(x.lower().strip()
for x in re.findall(r'https?://download.*\.pth', content)
if 'mmtracking' in x)
if len(ckpts) == 0:
continue

_papertype = [x for x in re.findall(r'\s*\[([A-Z]*?)\]\s*', content)]
assert len(_papertype) > 0
papertype = _papertype[0]

paper = set([(papertype, title)])

titles.append(title)
num_ckpts += len(ckpts)
statsmsg = f"""
\t* [{papertype}] [{title}]({url}) ({len(ckpts)} ckpts)
"""
stats.append((paper, ckpts, statsmsg))

allpapers = func.reduce(lambda a, b: a.union(b), [p for p, _, _ in stats])
msglist = '\n'.join(x for _, _, x in stats)

papertypes, papercounts = np.unique([t for t, _ in allpapers],
return_counts=True)
countstr = '\n'.join(
[f' - {t}: {c}' for t, c in zip(papertypes, papercounts)])

modelzoo = f"""
# Model Zoo Statistics
* Number of papers: {len(set(titles))}
{countstr}
* Number of checkpoints: {num_ckpts}
{msglist}
"""

with open('modelzoo_statistics.md', 'w') as f:
f.write(modelzoo)
2 changes: 1 addition & 1 deletion requirements/mminstall.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
mmcls>=1.0.0rc0, <1.0.0
mmcls>=1.0.0rc0,<1.0.0
mmcv-full>=2.0.0rc0,<2.0.0
mmdet>=3.0.0rc0,<3.0.0
6 changes: 3 additions & 3 deletions requirements/readthedocs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mmcls
mmcv
mmdet
mmcls>=0.16.0,<1.0.0
mmcv-full>=1.3.17,<1.7.0
mmdet>=2.19.1,<3.0.0
torch
torchvision

0 comments on commit 2d02bbe

Please sign in to comment.