Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework of internals #246

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repos:
- id: stylelint
additional_dependencies: ['stylelint@14.9.1', 'stylelint-config-standard@26.0.0']
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.1
rev: v3.0.2
hooks:
- id: prettier
types_or: [css, scss, javascript]
Expand Down
8 changes: 4 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ stages:
- pandoc
- graphviz
envs:
- linux: py311-sphinx6
- linux: py311-sphinx7

- stage: SecondPhaseTests
displayName: Stage 2 Tests
Expand All @@ -67,8 +67,8 @@ stages:
- pandoc
- graphviz
envs:
- linux: py310-sphinx5
- macos: py39-sphinx5
- linux: py310-sphinx6
- macos: py310-sphinx6
- windows: py39-sphinx5

- stage: ThirdPhaseTests
Expand All @@ -84,6 +84,6 @@ stages:
- pandoc
- graphviz
envs:
- linux: py310-sphinxdev
- linux: py311-sphinxdev
- linux: py310-docs
- linux: py310-conda
31 changes: 14 additions & 17 deletions src/ablog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from sphinx.jinja2glue import BuiltinTemplateLoader, SphinxFileSystemLoader
from sphinx.locale import get_translation

from .blog import CONFIG, Blog
from .post import (
from ablog.blog import CONFIG, Blog
from ablog.post import (
CheckFrontMatter,
PostDirective,
PostListDirective,
Expand All @@ -24,11 +24,11 @@
process_posts,
purge_posts,
)
from .version import version as __version__
from ablog.version import version as __version__

__all__ = ["setup", "__version__"]

PKGDIR = os.path.abspath(os.path.dirname(__file__))
PKG_DIR = os.path.abspath(os.path.dirname(__file__))
# Name used for the *.pot, *.po and *.mo files
MESSAGE_CATALOG_NAME = "sphinx"
_ = get_translation(MESSAGE_CATALOG_NAME) # NOQA
Expand All @@ -38,8 +38,7 @@ def get_html_templates_path():
"""
Return path to ABlog templates folder.
"""
pkgdir = os.path.abspath(os.path.dirname(__file__))
return os.path.join(pkgdir, "templates")
return os.path.join(PKG_DIR, "templates")


def anchor(post):
Expand All @@ -48,8 +47,7 @@ def anchor(post):
"""
if post.section:
return "#" + post.section
else:
return ""
return ""


def builder_support(builder):
Expand All @@ -70,7 +68,7 @@ def html_page_context(app, pagename, templatename, context, doctree):
if builder_support(app):
context["ablog"] = blog = Blog(app)
context["anchor"] = anchor
# following is already available for archive pages
# The following is already available for archive pages
if blog.blog_baseurl and "feed_path" not in context:
context["feed_path"] = blog.blog_path
context["feed_title"] = blog.blog_title
Expand All @@ -83,7 +81,7 @@ def config_inited(app, config):
matched_patterns = []
for pattern in config.blog_post_pattern:
pattern = os.path.join(app.srcdir, pattern)
# make sure that blog post paths have forward slashes even on windows
# Make sure that blog post paths have forward slashes even on windows
matched_patterns.extend(
PurePath(ii).relative_to(app.srcdir).with_suffix("").as_posix() for ii in glob(pattern, recursive=True)
)
Expand All @@ -99,15 +97,15 @@ def builder_inited(app):
"template bridges. You can use `ablog.get_html_templates_path()` to "
"get the path to add in your custom template bridge and set "
"`skip_injecting_base_ablog_templates = False` in your "
"`conf.py` file."
"'conf.py' file."
)
if get_html_templates_path() in app.config.templates_path:
raise Exception(
"Found the path from `ablog.get_html_templates_path()` in the "
"`templates_path` variable from `conf.py`. Doing so interferes "
"with Ablog's ability to stay compatible with Sphinx themes that "
"`templates_path` variable from 'conf.py'. Doing so interferes "
"with ABlog's ability to stay compatible with Sphinx themes that "
"support it out of the box. Please remove `get_html_templates_path` "
"from `templates_path` in your `conf.py` to resolve this."
"from `templates_path` in your 'conf.py' to resolve this."
)
theme = app.builder.theme
loaders = app.builder.templates.loaders
Expand Down Expand Up @@ -148,7 +146,6 @@ def setup(app):
html=(lambda s, n: s.visit_admonition(n), lambda s, n: s.depart_admonition(n)),
latex=(lambda s, n: s.visit_admonition(n), lambda s, n: s.depart_admonition(n)),
)
pkgdir = os.path.abspath(os.path.dirname(__file__))
locale_dir = os.path.join(pkgdir, "locales")
locale_dir = os.path.join(PKG_DIR, "locales")
app.add_message_catalog(MESSAGE_CATALOG_NAME, locale_dir)
return {"version": __version__} # identifies the version of our extension
return {"version": __version__}
95 changes: 89 additions & 6 deletions src/ablog/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ def read_conf(confdir):

def cmd(func=None, **kwargs):
if func is None:

def cmd_inner(func):
return cmd(func, **kwargs)

return cmd_inner
else:
command = commands.add_parser(**kwargs)
Expand Down Expand Up @@ -458,12 +456,97 @@ def ablog_deploy(
print("No place to deploy.")


def ablog_main():
"""
Ablog Main.
"""
def get_parser() -> argparse.ArgumentParser:
description = __(
"\n"
"Generate required files for a Sphinx project.\n"
"\n"
"sphinx-quickstart is an interactive tool that asks some questions about your\n"
"project and then generates a complete documentation directory and sample\n"
"Makefile to be used with sphinx-build.\n",
)
parser = argparse.ArgumentParser(
usage='%(prog)s [OPTIONS] <PROJECT_DIR>',
epilog=__("For more information, visit <https://www.sphinx-doc.org/>."),
description=description)

parser.add_argument('-q', '--quiet', action='store_true', dest='quiet',
default=None,
help=__('quiet mode'))
parser.add_argument('--version', action='version', dest='show_version',
version='%%(prog)s %s' % __display_version__)

parser.add_argument('path', metavar='PROJECT_DIR', default='.', nargs='?',
help=__('project root'))

group = parser.add_argument_group(__('Structure options'))
group.add_argument('--sep', action='store_true', dest='sep', default=None,
help=__('if specified, separate source and build dirs'))
group.add_argument('--no-sep', action='store_false', dest='sep',
help=__('if specified, create build dir under source dir'))
group.add_argument('--dot', metavar='DOT', default='_',
help=__('replacement for dot in _templates etc.'))

group = parser.add_argument_group(__('Project basic options'))
group.add_argument('-p', '--project', metavar='PROJECT', dest='project',
help=__('project name'))
group.add_argument('-a', '--author', metavar='AUTHOR', dest='author',
help=__('author names'))
group.add_argument('-v', metavar='VERSION', dest='version', default='',
help=__('version of project'))
group.add_argument('-r', '--release', metavar='RELEASE', dest='release',
help=__('release of project'))
group.add_argument('-l', '--language', metavar='LANGUAGE', dest='language',
help=__('document language'))
group.add_argument('--suffix', metavar='SUFFIX', default='.rst',
help=__('source file suffix'))
group.add_argument('--master', metavar='MASTER', default='index',
help=__('master document name'))
group.add_argument('--epub', action='store_true', default=False,
help=__('use epub'))

group = parser.add_argument_group(__('Extension options'))
for ext in EXTENSIONS:
group.add_argument('--ext-%s' % ext, action='append_const',
const='sphinx.ext.%s' % ext, dest='extensions',
help=__('enable %s extension') % ext)
group.add_argument('--extensions', metavar='EXTENSIONS', dest='extensions',
action='append', help=__('enable arbitrary extensions'))

group = parser.add_argument_group(__('Makefile and Batchfile creation'))
group.add_argument('--makefile', action='store_true', dest='makefile', default=True,
help=__('create makefile'))
group.add_argument('--no-makefile', action='store_false', dest='makefile',
help=__('do not create makefile'))
group.add_argument('--batchfile', action='store_true', dest='batchfile', default=True,
help=__('create batchfile'))
group.add_argument('--no-batchfile', action='store_false',
dest='batchfile',
help=__('do not create batchfile'))
group.add_argument('-m', '--use-make-mode', action='store_true',
dest='make_mode', default=True,
help=__('use make-mode for Makefile/make.bat'))
group.add_argument('-M', '--no-use-make-mode', action='store_false',
dest='make_mode',
help=__('do not use make-mode for Makefile/make.bat'))

group = parser.add_argument_group(__('Project templating'))
group.add_argument('-t', '--templatedir', metavar='TEMPLATEDIR',
dest='templatedir',
help=__('template directory for template files'))
group.add_argument('-d', metavar='NAME=VALUE', action='append',
dest='variables',
help=__('define a template variable'))

return parser


if __name__ == '__main__':
from ablog.start import start_ablog

if len(sys.argv) == 1:
parser.print_help()
else:
namespace = parser.parse_args()
namespace.func(**namespace.__dict__)
raise SystemExit(start_ablog(sys.argv[1:]))
Loading
Loading