๋ธ๋ก๊ทธ ๊ธ ์๋จ/ํ๋จ์ ๊ฐํ์ ์ผ๋ก ๋จ๋ ๊ด๊ณ ๋ ๋ธ๋ก๊ทธ ๊ฐ์ธ ์์ต๊ณผ ๊ด๋ จ ์๋ ํฐ์คํ ๋ฆฌ ์ธก ๊ด๊ณ ์ ๋๋ค
์๊ฐ
์๋ ํ์ธ์. ์ค๋์ javascript๋ก ์ฝ๋ฉ๋ ํ๋ก์ ํธ์ ๋ฌธ์ํ๋ฅผ ์ํ sphinx-js๋ฅผ ์ค๋ช ํด๋๋ฆฌ๋ ค๊ณ ํฉ๋๋ค.
sphinx๋ python ํ๋ก์ ํธ์ ๋ฌธ์ ์๋ํ๋ฅผ ์ํ ํด์ ๋๋ค. python ํ๋ก์ ํธ์ ํจ์, ๋ชจ๋๋ค์ ํน์ ๋ฌธ๋ฒ์ ๋ฐ๋ผ ์ฃผ์์ ์์ฑํด ๋๋ฉด ์๋์ผ๋ก latex ๋ฌธ์, html๋ก ๋น๋ํด ์ฃผ๋ ํด์ด์์. ์คํ ์์ค ํ๋ก์ ํธ์ ๋ฌธ์ํ ๋ฑ์ ๋ง์ด ์ฌ์ฉํฉ๋๋ค.
javascript์ฉ์ผ๋ก ์ ์ฌํ ํด jsdoc ์ด ์์ง๋ง, read-the-docs ์ ์ฐ๋ํด์ ๋น๋ํ๊ณ ์ถ์ด์ ์ฐพ๊ฒ ๋ ๊ฒ ๋ฐ๋ก sphinx-js์์.
GitHub - mozilla/sphinx-js: Autodoc-style extraction into Sphinx for your JS project
Autodoc-style extraction into Sphinx for your JS project - GitHub - mozilla/sphinx-js: Autodoc-style extraction into Sphinx for your JS project
github.com
sphinx-js๋ฅผ ์ฌ์ฉํ๋ฉด ๊ธฐ์กด์ python sphinx ํ๋ก์ ํธ๋ค ์ฒ๋ผ docs html์ ๋น๋ํ ์ ์๊ณ , ๋๋ถ์ด latex ๋ฌธ์๋ก๋ ๋น๋๊ฐ ๊ฐ๋ฅํฉ๋๋ค. docs ํด๋๋ฅผ ํ์ด์ง ๋ด์ ๋ฃ์ด๋์ผ๋ฉด github์์ ๋ฐ๋ก ํ์ด์ง๋ก redirection ์ํฌ ์ ์๋ค๋ ์ฅ์ ์ด ์์ต๋๋ค. sphinx์ ํจ๊ป ๋ง์ด ์ฐ์ด๋ Read-the-Docs (RTD)๋ sphinx๋ก ๋ง๋ค์ด์ง html ๋ฌธ์๋ฅผ ํธ์คํ ํ ์ ์๋ ๊ณณ์ ๋๋ค. ์ต๊ทผ python ๊ธฐ๋ฐ์ ๋ง์ open source ํ๋ก์ ํธ๋ค์ด ํ์ฉํ๊ณ ์๋ ์น ํธ์คํ ์ฌ์ดํธ์์.
์ ๋ฆฌํ์๋ฉด,
- sphinx๋ python์ผ๋ก ์์ฑ๋ ํ๋ก์ ํธ์ ์ฃผ์์ ์ฝ์ด ๋ค์ฌ html, latex ๋ฑ์ ํฌ๋งท์ผ๋ก ๋ฌธ์ํํด ์ค๋ค.
- RTD๋ sphinx๋ฅผ ํตํด ์์ฑ๋ html์ ์น ํธ์คํ ์ ๊น๋ํ๊ฒ ํด์ฃผ๋ ํด๋ก, ๋ค์ํ ํ ๋ง๋ค์ ์ง์ํ๊ณ ์๋ค.
- javascript ๊ธฐ๋ฐ ํ๋ก์ ํธ์ RTD ์น ํธ์คํ ์ ์ํด sphinx-js๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์๊ฐํด๋๋ฆฌ๊ฒ ์ต๋๋ค.
์ค์น
sphinx-js๋ jsdoc๊ณผ sphinx-js๋ฅผ ๋ชจ๋ ์ค์นํด์ผ ํฉ๋๋ค. ์ฐธ๊ณ ๋ก jsdoc์ javascript ๋ชจ๋์ด๊ณ sphinx-js๋ python ๋ชจ๋์ด์์. ๊ทธ๋ฌ๋ ๊ฐ๊ฐ ์๋ ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํด์ ์ค์นํด ์ค๋๋ค.
npm install -g jsdoc
pip install sphinx-js
(+) ์ถ๊ฐ๋ก sphinx๋ฅผ ์ ํ์ฉํ๊ธฐ ์ํ ํจํค์ง๋ค์ ์ค์นํด ์ฃผ๊ฒ ์ต๋๋ค. (sphinx-js๋ฅผ ์ํด์ ํ์๋ ์๋์ง๋ง, RTD์์ ์ฐ๋ ๋ฐ MD ํ์ผ์ ๋ฌธ์ํ๋ฅผ ์ํด์ ํ์ํ ํจํค์ง์ ๋๋ค.)
- sphinx์์ ๋งํฌ๋ค์ด์ ํ์ฉํ๊ธฐ ์ํ ํจํค์ง, myst_parser
- RTD ํ ๋ง ์ ์ฉํ๊ธฐ ์ํ ํจํค์ง, sphinx_rtd_theme
pip install sphinx_rtd_theme
pip install myst_parser
(+) ์๋ฌํธ๋ค๋ง
ImportError: cannot import name 'soft_unicode' from 'markupsafe' (~/opt/anaconda3/envs/sphinx/lib/python3.8/site-packages/markupsafe/init.py)
pip install markupsafe==2.0.1
์ค์
sphinx-js๋ sphinx์์ javascript๋ฅผ ์ง์ํ ์ ์๋๋ก ํ๋ ๋ชจ๋์ด๋ผ๊ณ ๋ณผ ์ ์์ต๋๋ค. ๊ทธ๋์ sphinx์ ๊ธฐ๋ณธ์ ์ธ ์ค์ ์ ๋ฐ๋ผ๊ฐ๋ sphinx-js ๋ชจ๋์ ์ถ๊ฐ๋ก ์ค์ ํด ์ฃผ๊ณ javascript ์ฝ๋ ๋ด์ ์ฃผ์ ๋ฌธ๋ฒ์ sphinx-js์์ ์ฌ์ฉํ๋ jsdoc ๋ช ๋ น์ด๋ฅผ, docs ๋ฌธ์์ ๋ฌธ๋ฒ์ sphinx์ RTD ํฌ๋งท์ ๋ฐ๋ฅด๋ฉด ๋ฉ๋๋ค.
| 1. sphinx ์ธํ ํ๊ธฐ (sphinx-quickstart)
์ด์ ํ๋ก์ ํธ ํ์ผ ๊ฒฝ๋ก๋ก ์ด๋ ํ sphinx-quickstart ๋ช ๋ น์ด๋ฅผ ์งํํฉ๋๋ค. ๋ช ๋ น์ด ์งํ ์ ์ค์ documentation ๊ด๋ จ ํ์ผ๋ค์ ์ ์ฅํ ๊ฒฝ๋ก๋ฅผ ์ง์ ํ ์ ์์ผ๋ฉฐ, ์ผ๋ฐ์ ์ผ๋ก docs๋ผ๋ ํด๋ ๋ด์ ๊ด๋ฆฌํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ผ๋ฏ๋ก ์ ๋ sphinx-quickstart docs๋ผ๋ ๋ช ๋ น์ด๋ฅผ ์ ๋ฌํด ์ค๊ฒ์.
cd my-project
sphinx-quickstart docs
๊ทธ๋ฌ๋ฉด ๊ธฐ๋ณธ์ ์ผ๋ก sphinx์ ํ์ํ ํด๋ ๋ฐ ํ์ผ๋ค์ด docs/ ํด๋ ๋ฐ์ ์์ฑ๋ฉ๋๋ค.
/my_project
|_/yourcodes
|_/docs
| |_Makefile
| |_Requirement.txt
| |_ build/
| |_ source/
| | |_ _static
| | |_ _templates
| | |_ conf.py
| | |_ index.rst
| |_ make.bat
|_jsdoc.json
| 2. sphinx_js๋ฅผ Requirement.txt์ ์ถ๊ฐํ๊ธฐ
sphinx๋ฅผ ์ฌ์ฉํด์ ๋น๋ํ ๋ sphinx_js๋ฅผ ์ฐ๋๋ก ์ค์ ํด์ฃผ์ด์ผ ํฉ๋๋ค. ์ด๋, sphinx์์ ํ์ํ ๋ชจ๋ (dependency)๋ฅผ ํ์ธํ๋ ํ์ผ์ด Requirement.txt์ ๋๋ค. ์ ๊ฐ์ ๊ฒฝ์ฐ์๋ sphinx-js ์ธ์๋ rtd ํ ๋ง, ๊ทธ๋ฆฌ๊ณ mark down ์๋ ํ์ฑ์ ์ํ parser๋ฅผ ์ถ๊ฐํด ์ฃผ์์ต๋๋ค.
myst-parser==0.18.0
sphinx_rtd_theme==1.1.1
sphinx-js==3.1.2
| 3. sphinx_js๋ก ์ค์ ํด ์ฃผ๊ธฐ
์ด์ sphinx_js extension์ ์ค์ ํด ์ค๋๋ค. docs/source/ ํด๋ ๋ด์ ์์ฑ๋ conf.py ํ์ผ์์ extensions์ "sphinx_js"๋ฅผ ์ถ๊ฐํด ์ฃผ๋ฉด ๋ฉ๋๋ค. ์ถ๊ฐ๋ก primary_domain ์ด๋ js_source_path ๊ทธ๋ฆฌ๊ณ jsdoc_config_path๋ฅผ ์ค์ ํด์ฃผ์ด์ผ ํฉ๋๋ค.
์ด๋ ๊ฒฝ๋ก๋ conf.py๊ฐ ์๋ source ๊ฒฝ๋ก๋ฅผ ๊ธฐ์ค์ผ๋ก ์ค์ ํด์ฃผ์ด์ผ ํด์ ์๋์ ๊ฐ์ด ์ค์ ํด ์ฃผ์์ต๋๋ค.
์ฐธ๊ณ ๋ก, sphinx_js extension ์ธ์ ๋ค๋ฅธ ์ต์ ๋ค (sphinx_rtd_theme, sphinx.ext.autodoc, myst_parser)์ sphinx ์ฌ์ฉ์์ ํ์์ ๋ฐ๋ผ ์ค์ ํด ์ค extension๋ค์ด์์. sphinx ๋ฌธ์ํ์์ ํ์ํ rtd_theme์ด๋ mark down import์ฉ extension๋ค์ sphinx ๋ฌธ์๋ค์ ์ฐธ๊ณ ํ์๋ฉด ๋ฉ๋๋ค.
์ฐธ๊ณ , sphinx ์ค์ ๊ฐ์ด๋ (python์ฉ)
| 4. jsdoc.json ํธ์งํ๊ธฐ
3๋ฒ ๋จ๊ณ๊น์ง ์ํํ docs/source/ ํด๋ ์๋์์ conf.py ํ์ผ ์ค์ ๋ค์ sphinx์ ๋ํ ์ค์ ์ ๋๋ค. sphinx ์ค์ ์ "java script๋ฅผ ์ธ ๊ฑฐ์ผ"๋ผ๊ณ extension์ ์ง์ ํด ์ฃผ๊ณ ์ด๋ ์ฝ์ด์ฌ jsdoc_conf_path๋ฅผ ์ค์ ํด์ฃผ๋ฉด sphinx๊ฐ ๋ฌธ์ํ๋ฅผ ์ํํ ๋ ์ง์ ๋ jsdoc.json ํ์ผ ๊ฒฝ๋ก๋ฅผ ์ฐธ๊ณ ํด์ javascript ํ์ผ๋ค์ ์ฃผ์์ ๋ถ์ํด์ ๋ฌธ์ํํด์ค๋๋ค. ์ด ๋ javascript์ ๋ฌธ์ํ๋ฅผ ์ํํ๊ธฐ ์ํ ํด๋ก jsdoc์ด ์ฌ์ฉ๋ฉ๋๋ค.
์ ์ฝ๋ ๊ฐ์ ๊ฒฝ์ฐ์๋ ํ๋์ main ํ์ผ์์ ๋ชจ๋ ํจํค์ง๋ฅผ import ํ๋ ํํ์ฌ์ ์๋์ฒ๋ผ ์ฃผ์ main ํ์ผ๋ง include๋ก ๋ฃ์ด์ฃผ์์ต๋๋ค (์๋๋ฉด ์ฌ๊ท์ ์ผ๋ก ๋ชจ๋ ํ์ผ๋ค์ด parsing ๋ผ์ ์๋ฌ๊ฐ ๋จ๋๋ผ๊ณ ์)
์ฌ๊ธฐ์๋ ์ฃผ์ํ ์ ์ sphinx ๊ฐ source ํด๋๋ฅผ ๊ธฐ์ค์ผ๋ก parsing ํ๊ธฐ ๋๋ฌธ์ ์๋ ๊ฒฝ๋ก๋ฅผ ์์ฑํด ์ค ๋ ์ ์ํด์ผ ํ๋ค๋ ์ ์ ๋๋ค. ์๋ฅผ ๋ค์ด include์ ๊ฒฝ์ฐ์๋ "../../yourcodes/main.js"๋ก ์ค์ ํด ์ฃผ์๊ณ destination๋ "../../docs"๋ก ์ค์ ํด ์ฃผ์์ด์.
{
"source": {
"include": ["../../yourcodes/main.js"],
"includePattern": ".js$",
"excludePattern": "(node_modules/|docs)"
},
"templates": {
"cleverLinks": true,
"monospaceLinks": true
},
"opts": {
"recurse": true,
"destination": "../../docs/"
}
}
๋ฌธ์ํ
๋์์์ด ์ค๋ช ํ์ง๋ง, ์ ๋ฆฌํ์๋ฉด sphinx-js๋ฅผ ์ฌ์ฉํ ์ฝ๋ ๋ฌธ์ํ๋ ๋ ๊ฐ์ ๋ชจ๋์ ์ฌ์ฉํฉ๋๋ค. 1. sphinx 2. jsdoc. ์ด ๋์ ์ฐ๊ฒฐ์์ผ ์ฃผ๋ ๋ชจ๋์ด sphinx-js์ธ ์ ์ ๋๋ค. ์ด์ ๊ฐ๊ฐ์ ํฌ๋งท์ ๋ง์ถฐ์ ๋ฌธ์ํ๋ฅผ ์ํ ์ถ๊ฐ ํ์ผ๋ค์ ์์ฑํด ์ค ๊ฒ๋๋ค.
sphinx์ ๋ฉ์ธ ๋ฌธ์๋ค์ ๊ธฐ๋ณธ์ ์ผ๋ก rst ํฌ๋งท์ ๋ฐ๋ฆ ๋๋ค. make html ๋ช ๋ น์ด๋ฅผ ๋ด๋ ธ์ ๋ ์ค์ ํ docs/ ํด๋ ๋ด์ ์๋ rst ํ์ผ๋ค์ ์ฝ์ด ๋ค์ฌ ๋ฌธ์ํ๋ฅผ ํด์ค๋๋ค.
์๋ฅผ ๋ค์ด, ๋ฌธ์์ ๊ตฌ์กฐ๊ฐ ๋ค์๊ณผ ๊ฐ๋ค๊ณ ๊ฐ์ ํด ๋ณด๊ฒ ์ต๋๋ค.
index
|_ Introduction
| |_ intro
|_ Modules
|_ module1
|_ module2
๊ทธ๋ ๋ค๋ฉด index.rst๋ ๋ค์๊ณผ ๊ฐ์ด ์์ฑํ ์ ์์ผ๋ฉฐ ์ด๋ source ํด๋ ๋ด์๋ ๊ฐ๊ฐ ๋์๋๋ rst ํ์ผ์ ์์ฑํด์ฃผ์ด์ผ ํฉ๋๋ค.
.. documentation master file, created by
sphinx-quickstart on Tue Nov 29 21:07:28 2022.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
ํ์ดํ
======================================
๋ฌธ์ ์ค๋ช
.. image:: _static/image.png
:alt: image example
:align: center
**Figure**. static image example
====================================================================================
.. toctree::
:maxdepth: 3
:caption: Introduction
intro
.. toctree::
:maxdepth: 3
:caption: Modules:
module1
module2
module3
.. Indices and tables
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
์ด๋, ๊ฐ๊ฐ์ ๋์๋๋ rstํ์ผ์ source ํด๋ ๋ด์ ๊ฐ์ ๋ ๋ฒจ์์ ์์ฑ๋๋ฉด ๋ฉ๋๋ค.
/my_project
|_/yourcodes
|_/docs
| |_Makefile
| |_Requirement.txt
| |_ build/
| |_ source/
| | |_ _static
| | |_ _templates
| | |_ conf.py
| | |_ index.rst
| | |_ intro.rst
| | |_ module1.rst
| | |_ module2.rst
| |_ make.bat
|_jsdoc.json
rst ํ์ผ ๋ด์์ javascript ์ฝ๋์ ์ฃผ์ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ค๋ ค๋ฉด.. js:autofunction:: someFunction๊ณผ ๊ฐ์ ๋ฌธ๋ฒ์ ๋ฐ๋ผ ๋ถ๋ฌ์ค๋ฉด ๋ฉ๋๋ค. ๊ฐ ํ์ ๋ณ ์ค์ ์ https://github.com/mozilla/sphinx-js์ ์ฐธ๊ณ ํด ์ฃผ์ธ์.
..js:autofunction::FunctionName
..js.autoclass:ClassName
:members:
:private-members:
rst ํ์ผ์์ ์์ jsDoc๋ฌธ๋ฒ์ ํตํด ์๋์ผ๋ก ๋ฌธ์ํํ๊ธฐ ์ํด์๋ javascript ์ฝ๋ ๋ด์ ์ฃผ์ ์ค๋ช ์ด ์ถ๊ฐ๋์ด์ผ ํฉ๋๋ค. ์ฃผ์์์ฑ์ ์ํ ๋ฌธ๋ฒ์ jsdoc ๋ฌธ๋ฒ์ ๋ฐ๋ฆ ๋๋ค. JSDoc syntax๋ฅผ ์ฐธ๊ณ ํ์๋ฉด ๋ฉ๋๋ค.
์)
/**
* Assign the project to an employee.
* @param {Object} employee - The employee who is responsible for the project.
* @param {string} employee.name - The name of the employee.
* @param {string} employee.department - The employee's department.
*/
Project.prototype.assign = function(employee) {
// ...
};
๋น๋
docs ํด๋ ๋ด์์ make ๋ช ๋ น์ด๋ฅผ ํตํด ๋น๋ํด ์ฃผ๋ฉด ๋ฉ๋๋ค.
make html
์ฐธ๊ณ
- https://github.com/mozilla/sphinx-js
GitHub - mozilla/sphinx-js: Autodoc-style extraction into Sphinx for your JS project
Autodoc-style extraction into Sphinx for your JS project - GitHub - mozilla/sphinx-js: Autodoc-style extraction into Sphinx for your JS project
github.com
- https://jsdoc.app/tags-param.html#parameters-with-properties
Use JSDoc: @param
@param Table of Contents Synonyms @arg @argument Overview The @param tag provides the name, type, and description of a function parameter. The @param tag requires you to specify the name of the parameter you are documenting. You can also include the parame
jsdoc.app
- https://www.sphinx-doc.org/en/master/usage/quickstart.html#defining-document-structure
Getting Started — Sphinx documentation
Getting Started Sphinx is a documentation generator or a tool that translates a set of plain text source files into various output formats, automatically producing cross-references, indices, etc. That is, if you have a directory containing a bunch of reStr
www.sphinx-doc.org
๋ โผ๏ธ