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

enable pre-commit #12

Merged
merged 12 commits into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from 11 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
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.21.2
hooks:
- id: pyupgrade
args: ["--py36-plus"]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8

- repo: https://github.com/asottile/yesqa
rev: v1.2.3
hooks:
- id: yesqa

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: mixed-line-ending

- repo: https://github.com/pycqa/isort
rev: 5.9.2
hooks:
- id: isort
1 change: 0 additions & 1 deletion requirements/default.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Sphinx>=2.0.0
six
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ where = sphinx_celery/tests

[wheel]
universal = 1

[isort]
profile=black
24 changes: 13 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from setuptools import setup, find_packages

import codecs
import os
import re
import sys
import codecs

from setuptools import find_packages, setup

NAME = 'sphinx_celery'
extra = {}
Expand Down Expand Up @@ -43,6 +42,7 @@ def add_default(m):
def add_doc(m):
return (('doc', m.groups()[0]),)


pats = {re_meta: add_default, re_doc: add_doc}
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'sphinx_celery', '__init__.py')) as meta_fh:
Expand All @@ -62,8 +62,8 @@ def add_doc(m):
is_pypy = hasattr(sys, 'pypy_version_info')


def strip_comments(l):
return l.split('#', 1)[0].strip()
def strip_comments(line):
return line.split('#', 1)[0].strip()


def _pip_requirement(req):
Expand All @@ -74,18 +74,20 @@ def _pip_requirement(req):


def _reqs(*f):
return [
_pip_requirement(r) for r in (
strip_comments(l) for l in open(
os.path.join(os.getcwd(), 'requirements', *f)).readlines()
) if r]
with open(os.path.join(os.getcwd(), "requirements", *f)) as fp:
return [
_pip_requirement(r) for r in (
strip_comments(line) for line in fp
) if r
]


def reqs(*f):
return [req for subreq in _reqs(*f) for req in subreq]

# -*- Long Description -*-


if os.path.exists('README.rst'):
long_description = codecs.open('README.rst', 'r', 'utf-8').read()
else:
Expand Down
9 changes: 5 additions & 4 deletions sphinx_celery/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Sphinx Celery Theme."""
from __future__ import absolute_import, unicode_literals

import os
import re

from collections import namedtuple

__version__ = '2.0.0'
Expand Down Expand Up @@ -36,10 +34,13 @@ def get_html_theme_path():

def get_html_templates_path():
return os.path.join(
os.path.abspath(os.path.dirname((__file__))),
os.path.abspath(os.path.dirname(__file__)),
'templates',
)


def setup(app):
app.add_html_theme('sphinx_celery', os.path.abspath(os.path.dirname(__file__)))
app.add_html_theme(
'sphinx_celery',
os.path.abspath(os.path.dirname(__file__)),
)
7 changes: 2 additions & 5 deletions sphinx_celery/apicheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,10 @@
Default is ``['py']`` and Python is the only domain currently supported.

"""
from __future__ import absolute_import, unicode_literals

import importlib
import os

from collections import defaultdict
from six import string_types

import sphinx
from sphinx.ext import autodoc
Expand Down Expand Up @@ -99,7 +96,7 @@ class ModuleDocumenter(autodoc.ModuleDocumenter):
missing_modules = set()

def import_object(self):
if not super(ModuleDocumenter, self).import_object():
if not super().import_object():
self.missing_modules.add(self.modname)
return False
return True
Expand All @@ -118,7 +115,7 @@ def header(s, sep=SUBHEADER):


def find_python_modules(package):
if isinstance(package, string_types):
if isinstance(package, str):
package = importlib.import_module(package)
name, path = package.__name__, package.__file__
current_dist_depth = len(name.split('.')) - 1
Expand Down
2 changes: 0 additions & 2 deletions sphinx_celery/autodocargspec.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, unicode_literals

from sphinx.ext import autodoc as _autodoc
from sphinx.util import inspect

Expand Down
8 changes: 3 additions & 5 deletions sphinx_celery/builders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, unicode_literals

import os
import pickle
import re
Expand All @@ -12,7 +10,7 @@
class BaseBuilder(Builder):

def get_outdated_docs(self):
return '{0} overview'.format(self.name)
return f'{self.name} overview'

def finish(self):
picklepath = os.path.join(self.outdir, self.pickle_filename)
Expand All @@ -21,9 +19,9 @@ def finish(self):

def compile_regex(self, regex):
if not regex.startswith('^'):
regex = '^{0}'.format(regex)
regex = f'^{regex}'
if not regex.endswith('$'):
regex = '{0}$'.format(regex)
regex = f'{regex}$'
try:
return re.compile(regex)
except Exception as exc:
Expand Down
33 changes: 13 additions & 20 deletions sphinx_celery/conf.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals

import os
import sys

from . import get_html_templates_path

PY3 = sys.version_info[0] >= 3

LINKCODE_URL = 'https://github.com/{proj}/tree/{branch}/{filename}.py'
GITHUB_BRANCH = 'master'

Expand Down Expand Up @@ -54,8 +49,6 @@
'tox': ('https://tox.readthedocs.io/en/latest', None),
}

string_types = (str,) if PY3 else (basestring,)


def add_paths(config_file, path_additions):
this = os.path.dirname(os.path.abspath(config_file))
Expand All @@ -69,7 +62,7 @@ def configure_django(django_settings, **config):
if django_settings:
os.environ['DJANGO_SETTINGS_MODULE'] = django_settings
else:
from django.conf import settings # noqa
from django.conf import settings
if not settings.configured:
settings.configure(**config)
try:
Expand All @@ -81,17 +74,17 @@ def configure_django(django_settings, **config):


def import_package(package):
if isinstance(package, string_types):
if isinstance(package, str):
return __import__(package)
return package


def prepare_intersphinx_mapping(project, mapping,
include, exclude, **extra):
if include:
mapping = dict((k, v) for k, v in mapping.items() if k in include)
mapping = {k: v for k, v in mapping.items() if k in include}
if exclude:
mapping = dict((k, v) for k, v in mapping.items() if k not in exclude)
mapping = {k: v for k, v in mapping.items() if k not in exclude}
mapping = dict(mapping, **extra)

# Remove project itself from intersphinx
Expand Down Expand Up @@ -157,11 +150,11 @@ def build_config(
extlinks = extlinks or {}

extlinks.setdefault('sha', (
'https://github.com/{0}/commit/%s'.format(github_project),
f'https://github.com/{github_project}/commit/%s',
'GitHub SHA@',
))
extlinks.setdefault('github_branch', (
'https://github.com/{0}/tree/%s'.format(github_project),
f'https://github.com/{github_project}/tree/%s',
'GitHub branch',
))
extlinks.setdefault('github_user', (
Expand Down Expand Up @@ -212,7 +205,7 @@ def build_config(
# The master toctree document.
master_doc=master_doc,

copyright='{0}, {1}'.format(copyright, author),
copyright=f'{copyright}, {author}',

# The short X.Y version.
version=version,
Expand Down Expand Up @@ -270,22 +263,22 @@ def build_config(

man_pages=[
(master_doc, project.lower(),
u'{0} Documentation'.format(project), [author_name], 1)
f'{project} Documentation', [author_name], 1)
],

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents=[
(master_doc, project, u'{0} Documentation'.format(project),
(master_doc, project, f'{project} Documentation',
author_name, project, description,
'Miscellaneous'),
],
latex_logo=latex_logo or html_logo,

latex_documents=[
('index', '{0}.tex'.format(project),
'{0} Documentation'.format(project), author, 'manual'),
('index', f'{project}.tex',
f'{project} Documentation', author, 'manual'),
],
html_theme='sphinx_celery',
html_sidebars={
Expand All @@ -300,7 +293,7 @@ def build_config(
],
},
# Bibliographic Dublin Core info.
epub_title='{0} Manual, Version {1}'.format(project, version),
epub_title=f'{project} Manual, Version {version}',
epub_author=author_name,
epub_publisher=publisher or author_name,
epub_copyright=copyright,
Expand All @@ -317,7 +310,7 @@ def build_config(
epub_identifier=webdomain,

# A unique identification for the text.
epub_uid='{0} Manual, Version {0}'.format(project, version),
epub_uid='{0} Manual, Version {0}'.format(project),
graingert marked this conversation as resolved.
Show resolved Hide resolved

# A list of files that should not be packed into the epub file.
epub_exclude_files=['search.html'],
Expand Down
8 changes: 3 additions & 5 deletions sphinx_celery/configcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ def configcheck_should_ignore(setting):


"""
from __future__ import absolute_import, unicode_literals

from six import iterkeys as keys

from sphinx.util.console import bold, green, red

Expand Down Expand Up @@ -98,9 +95,10 @@ def write(self, *ignored):
self.check_missing()

def documented_settings(self):
domaindata_std_objects = self.app.env.domaindata['std']['objects']
return {
name for reftype, name in keys(
self.app.env.domaindata['std']['objects'])
name
for reftype, name in domaindata_std_objects.keys()
if reftype == 'setting'
}

Expand Down
Loading