Skip to content
This repository has been archived by the owner on Mar 21, 2023. It is now read-only.

Commit

Permalink
fix: use mkdocs instead of sphinx docs
Browse files Browse the repository at this point in the history
* build(setup): extras_require mkdocs

* build(setup): extras_require mkdocs

- package mkdocstrings-python-legacy

* refactor: check sys.stdout.encoding once

also isort module

* docs: mkdocs

- skip_files for test files

* docs(CONTRIBUTING): mkdocs
  • Loading branch information
rachmadaniHaryono authored Feb 28, 2022
1 parent 28eadb7 commit 32a2e9c
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 30 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ is preferred.

* Ensure all functions and classes have a PEP257 compliant docstring and the
code is PEP8 compliant.

## Documentation

Install required extra docs package to setup mkdocs: `pip install -e ".[docs]"`

To run built-in dev server: `mkdocs serve`

To deploy documentation to github page: `mkdocs gh-deploy`
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "CHANGELOG.md"
1 change: 1 addition & 0 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "CONTRIBUTING.md"
33 changes: 33 additions & 0 deletions docs/css/mkdocstrings.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Indentation. */
div.doc-contents:not(.first) {
padding-left: 25px;
border-left: 4px solid rgba(230, 230, 230);
margin-bottom: 80px;
}

/* Don't capitalize names. */
h5.doc-heading {
text-transform: none !important;
}

/* Don't use vertical space on hidden ToC entries. */
.hidden-toc::before {
margin-top: 0 !important;
padding-top: 0 !important;
}

/* Don't show permalink of hidden ToC entries. */
.hidden-toc a.headerlink {
display: none;
}

/* Avoid breaking parameters name, etc. in table cells. */
td code {
word-break: normal !important;
}

/* For pieces of Markdown rendered in table cells. */
td p {
margin-top: 0 !important;
margin-bottom: 0 !important;
}
34 changes: 34 additions & 0 deletions docs/gen_ref_nav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Generate the code reference pages and navigation."""

from pathlib import Path

import mkdocs_gen_files

nav = mkdocs_gen_files.Nav()

skip_files = [
(Path("mps_youtube") / "config.py"),
(Path("mps_youtube") / "mpris.py"),
]
skip_files.extend((Path("mps_youtube") / "test").glob("*.py"))
for path in sorted(Path("mps_youtube").glob("**/*.py")):
if path in skip_files:
continue
module_path = path.with_suffix("")
doc_path = path.relative_to("mps_youtube").with_suffix(".md")
full_doc_path = Path("reference", doc_path)

parts = list(module_path.parts)
parts[-1] = f"{parts[-1]}.py"
nav[parts] = doc_path

with mkdocs_gen_files.open(full_doc_path, "w") as fd:
ident = ".".join(module_path.parts)
print("::: " + ident, file=fd)

mkdocs_gen_files.set_edit_path(full_doc_path, path)

with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--8<-- "README.md"
3 changes: 3 additions & 0 deletions docs/license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```
--8<-- "LICENSE"
```
49 changes: 49 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
site_name: Yewtube
site_description: Terminal based YouTube player and downloader.
site_url: https://iamtalhaasghar.github.io/yewtube
repo_url: https://github.com/iamtalhaasghar/yewtube
repo_name: iamtalhaasghar/yewtube

nav:
- Home:
- Overview: index.md
- Changelog: changelog.md
- License: license.md
- Code Reference: reference/
- Development:
- Contributing: contributing.md

theme:
name: material
features:
- navigation.tabs
palette:
scheme: slate
primary: teal
accent: purple

extra_css:
- css/mkdocstrings.css

markdown_extensions:
- admonition
- pymdownx.emoji
- pymdownx.magiclink
- pymdownx.snippets:
check_paths: true
- pymdownx.superfences
- pymdownx.tabbed
- pymdownx.tasklist
- toc:
permalink: true

plugins:
- search
- mkdocstrings:
watch:
- mps_youtube
- gen-files:
scripts:
- docs/gen_ref_nav.py
- literate-nav:
nav_file: SUMMARY.md
20 changes: 9 additions & 11 deletions mps_youtube/player.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import os
import sys
import random
import logging
import math
import time
import os
import random
import shlex
import subprocess
import socket
from urllib.error import HTTPError, URLError
import subprocess
import sys
import time
from abc import ABCMeta, abstractmethod
from urllib.error import HTTPError, URLError


from . import g, screen, c, streams, history, content, config, util
from . import c, config, content, g, history, screen, streams, util
from .commands import lastfm

from .util import not_utf8_environment

mswin = os.name == "nt"
not_utf8_environment = mswin or "UTF-8" not in sys.stdout.encoding

class BasePlayer:
_playbackStatus = "Paused"
Expand Down Expand Up @@ -138,7 +136,7 @@ def _playsong(self, failcount=0, softrepeat=False):
screen.writestatus(self.songdata)

self._launch_player()

if config.HISTORY.get:
history.add(self.song)

Expand Down
2 changes: 1 addition & 1 deletion mps_youtube/players/mplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

from .. import c, config, g, paths, screen, util
from ..player import CmdPlayer
from ..util import not_utf8_environment

mswin = os.name == "nt"
not_utf8_environment = mswin or "UTF-8" not in sys.stdout.encoding


class mplayer(CmdPlayer):
Expand Down
13 changes: 6 additions & 7 deletions mps_youtube/players/mpv.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import os
import sys
import tempfile
import subprocess
import json
import os
import re
import socket
import subprocess
import sys
import tempfile
import time

from .. import g, screen, c, paths, config, util

from .. import c, config, g, paths, screen, util
from ..player import CmdPlayer
from ..util import not_utf8_environment

mswin = os.name == "nt"
not_utf8_environment = mswin or "UTF-8" not in sys.stdout.encoding


class mpv(CmdPlayer):
Expand Down
22 changes: 11 additions & 11 deletions mps_youtube/util.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import collections
import ctypes
import json
import logging
import os
import platform
import re
import subprocess
import sys
import ctypes
import logging
import time
import subprocess
import collections
import unicodedata
import urllib
import json
import platform
from datetime import datetime, timezone
from importlib import import_module


from . import g, c, terminalsize, description_parser
from . import c, description_parser, g, terminalsize
from .playlist import Video

from importlib import import_module

macos = platform.system() == "Darwin"

mswin = os.name == "nt"
not_utf8_environment = mswin or "UTF-8" not in sys.stdout.encoding
not_utf8_environment = mswin or (
"UTF-8" not in sys.stdout.encoding if sys.stdout.encoding else False
)

XYTuple = collections.namedtuple('XYTuple', 'width height max_results')

Expand Down
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
"dbus-python>=1.2.18",
"PyGObject>=3.42.0",
],
"docs": [
"mkdocs-gen-files>=0.3.4",
"mkdocs-literate-nav>=0.4.1",
"mkdocs-macros-plugin>=0.6.4",
"mkdocs-material>=8.2.1",
"mkdocstrings-python-legacy>=0.2.2",
"mkdocstrings>=0.18.0",
],
},
classifiers=[
"Topic :: Utilities",
Expand Down

0 comments on commit 32a2e9c

Please sign in to comment.