Skip to content

Commit 2f6ede5

Browse files
authored
Generate manpage with sphinx and add it to package (#165)
1 parent 2d299c4 commit 2f6ede5

File tree

9 files changed

+122
-3
lines changed

9 files changed

+122
-3
lines changed

.github/workflows/publish.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ jobs:
1919
with:
2020
python-version: '3.7'
2121

22+
- name: Install sphinx toolset
23+
run: >-
24+
python -m
25+
pip install
26+
sphinx
27+
sphinx-argparse
28+
--user
29+
30+
- name: Install tldr dependencies
31+
run: >-
32+
python -m
33+
pip install
34+
-r
35+
requirements.txt
36+
--user
37+
38+
- name: Generate the manpage
39+
working-directory: docs
40+
run: make man
41+
2242
- name: Install pep517
2343
run: >-
2444
python -m

.github/workflows/test.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,31 @@ jobs:
1818
with:
1919
python-version: ${{ matrix.python-version }}
2020

21-
- name: Install Dependencies
21+
- name: Install developer dependencies
2222
run: |
2323
python3 -m pip install -U pip
2424
python3 -m pip install -U pytest pytest-runner flake8
2525
26+
- name: Install sphinx dependencies
27+
run: >-
28+
python -m
29+
pip install
30+
sphinx
31+
sphinx-argparse
32+
--user
33+
34+
- name: Install tldr dependencies
35+
run: >-
36+
python -m
37+
pip install
38+
-r
39+
requirements.txt
40+
--user
41+
42+
- name: Generate the manpage
43+
working-directory: docs
44+
run: make man
45+
2646
- name: Lint codebase
2747
run: python3 -m flake8
2848

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.doctrees

docs/Makefile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = .
9+
BUILDDIR = man
10+
11+
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
12+
$(error The '$(SPHINXBUILD)' command was not found.)
13+
endif
14+
15+
.PHONY: man Makefile clean
16+
17+
man:
18+
$(SPHINXBUILD) -b man $(SOURCEDIR) $(BUILDDIR)/
19+
20+
clean:
21+
rm -rf $(BUILDDIR)/*

docs/conf.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# This file only contains a selection of the most common options. For a full
4+
# list see the documentation:
5+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
6+
7+
# -- Path setup --------------------------------------------------------------
8+
9+
# If extensions (or modules to document with autodoc) are in another directory,
10+
# add these directories to sys.path here. If the directory is relative to the
11+
# documentation root, use os.path.abspath to make it absolute, like shown here.
12+
#
13+
import os
14+
import sys
15+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
16+
17+
# -- Project information -----------------------------------------------------
18+
19+
project = 'tldr'
20+
copyright = '2014, Felix Yan'
21+
author = 'Felix Yan'
22+
from tldr import __version__ # noqa: E402
23+
release = __version__
24+
25+
# -- General configuration ---------------------------------------------------
26+
27+
# Add any Sphinx extension module names here, as strings. They can be
28+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
29+
# ones.
30+
extensions = [
31+
'sphinxarg.ext'
32+
]

docs/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.. tldr documentation master file, created by
2+
sphinx-quickstart on Mon Oct 4 20:14:33 2021.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
Welcome to tldr's documentation!
7+
================================
8+
9+
.. argparse::
10+
:filename: ../tldr.py
11+
:func: create_parser
12+
:prog: tldr

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
termcolor
2+
colorama
3+
argcomplete

setup.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
raise SystemExit("Could not determine version to use")
1212
version = version.group(1)
1313

14+
with open('requirements.txt') as f:
15+
required = f.read().splitlines()
16+
1417
setup(
1518
name='tldr',
1619
author='Felix Yan',
@@ -26,7 +29,8 @@
2629
"tldr = tldr:cli"
2730
]
2831
},
29-
install_requires=['termcolor', 'colorama', 'argcomplete'],
32+
data_files=[('share/man/man1', ['docs/man/tldr.1'])],
33+
install_requires=required,
3034
tests_require=[
3135
'pytest',
3236
'pytest-runner',

tldr.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def update_cache(language=None):
376376
sys.exit("Error: Unable to update cache from " + DOWNLOAD_CACHE_LOCATION)
377377

378378

379-
def main():
379+
def create_parser():
380380
parser = ArgumentParser(
381381
prog="tldr",
382382
usage="tldr command [options]",
@@ -437,6 +437,12 @@ def main():
437437
'command', type=str, nargs='*', help="command to lookup", metavar='command'
438438
).completer = argcomplete.completers.ChoicesCompleter(get_commands())
439439

440+
return parser
441+
442+
443+
def main():
444+
parser = create_parser()
445+
440446
argcomplete.autocomplete(parser)
441447
options = parser.parse_args()
442448

0 commit comments

Comments
 (0)