Skip to content

Commit

Permalink
Black: run black over all the code base (Part 2) (#11013)
Browse files Browse the repository at this point in the history
Continues with the idea started in
#10619
  • Loading branch information
humitos authored Jan 9, 2024
1 parent 9e2e786 commit bde1f43
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 203 deletions.
34 changes: 11 additions & 23 deletions readthedocs/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ def __init__(self, **kwargs):
setattr(self, name, kwargs[name])

def as_dict(self):
return {
name: to_dict(getattr(self, name))
for name in self.__slots__
}
return {name: to_dict(getattr(self, name)) for name in self.__slots__}


# TODO: rename this class to `Build`
class BuildWithOs(Base):

__slots__ = ("os", "tools", "jobs", "apt_packages", "commands")

def __init__(self, **kwargs):
Expand All @@ -38,8 +34,7 @@ def __init__(self, **kwargs):


class BuildTool(Base):

__slots__ = ('version', 'full_version')
__slots__ = ("version", "full_version")


class BuildJobs(Base):
Expand Down Expand Up @@ -76,39 +71,32 @@ class Python(Base):


class PythonInstallRequirements(Base):

__slots__ = ('requirements',)
__slots__ = ("requirements",)


class PythonInstall(Base):

__slots__ = (
'path',
'method',
'extra_requirements',
"path",
"method",
"extra_requirements",
)


class Conda(Base):

__slots__ = ('environment',)
__slots__ = ("environment",)


class Sphinx(Base):

__slots__ = ('builder', 'configuration', 'fail_on_warning')
__slots__ = ("builder", "configuration", "fail_on_warning")


class Mkdocs(Base):

__slots__ = ('configuration', 'fail_on_warning')
__slots__ = ("configuration", "fail_on_warning")


class Submodules(Base):

__slots__ = ('include', 'exclude', 'recursive')
__slots__ = ("include", "exclude", "recursive")


class Search(Base):

__slots__ = ('ranking', 'ignore')
__slots__ = ("ranking", "ignore")
44 changes: 22 additions & 22 deletions readthedocs/doc_builder/backends/mkdocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class BaseMkdocs(BaseBuilder):
"""Mkdocs builder."""

# The default theme for mkdocs is the 'mkdocs' theme
DEFAULT_THEME_NAME = 'mkdocs'
DEFAULT_THEME_NAME = "mkdocs"

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand All @@ -57,13 +57,13 @@ def __init__(self, *args, **kwargs):
# for these project that were building with MkDocs in the Corporate
# site.
if self.project.has_feature(Feature.MKDOCS_THEME_RTD):
self.DEFAULT_THEME_NAME = 'readthedocs'
self.DEFAULT_THEME_NAME = "readthedocs"
log.warning(
"Project using readthedocs theme as default for MkDocs.",
project_slug=self.project.slug,
)
else:
self.DEFAULT_THEME_NAME = 'mkdocs'
self.DEFAULT_THEME_NAME = "mkdocs"

def get_final_doctype(self):
"""
Expand Down Expand Up @@ -119,10 +119,10 @@ def load_yaml_config(self):
except IOError:
raise MkDocsYAMLParseError(MkDocsYAMLParseError.NOT_FOUND)
except yaml.YAMLError as exc:
note = ''
if hasattr(exc, 'problem_mark'):
note = ""
if hasattr(exc, "problem_mark"):
mark = exc.problem_mark
note = ' (line %d, column %d)' % (
note = " (line %d, column %d)" % (
mark.line + 1,
mark.column + 1,
)
Expand All @@ -146,7 +146,7 @@ def append_conf(self):
MkDocsYAMLParseError.INVALID_DOCS_DIR_CONFIG,
)

user_config['docs_dir'] = docs_dir
user_config["docs_dir"] = docs_dir
static_url = self.project.proxied_static_path

# Set mkdocs config values.
Expand Down Expand Up @@ -201,14 +201,14 @@ def append_conf(self):

# Use Read the Docs' analytics setup rather than mkdocs'
# This supports using RTD's privacy improvements around analytics
user_config['google_analytics'] = None
user_config["google_analytics"] = None

# README: make MkDocs to use ``readthedocs`` theme as default if the
# user didn't specify a specific theme manually
if self.project.has_feature(Feature.MKDOCS_THEME_RTD):
if 'theme' not in user_config:
if "theme" not in user_config:
# mkdocs<0.17 syntax
user_config['theme'] = self.DEFAULT_THEME_NAME
user_config["theme"] = self.DEFAULT_THEME_NAME

# Write the modified mkdocs configuration
with safe_open(self.yaml_file, "w", encoding="utf-8") as f:
Expand All @@ -219,7 +219,7 @@ def append_conf(self):

# Write the mkdocs.yml to the build logs
self.run(
'cat',
"cat",
os.path.relpath(self.yaml_file, self.project_path),
cwd=self.project_path,
)
Expand All @@ -229,9 +229,9 @@ def generate_rtd_data(self, docs_dir, mkdocs_config):
# Use the analytics code from mkdocs.yml
# if it isn't set already by Read the Docs,
analytics_code = self.version.project.analytics_code
if not analytics_code and mkdocs_config.get('google_analytics'):
if not analytics_code and mkdocs_config.get("google_analytics"):
# http://www.mkdocs.org/user-guide/configuration/#google_analytics
analytics_code = mkdocs_config['google_analytics'][0]
analytics_code = mkdocs_config["google_analytics"][0]

commit = (
self.version.project.vcs_repo(
Expand Down Expand Up @@ -271,14 +271,14 @@ def generate_rtd_data(self, docs_dir, mkdocs_config):
"html_theme": readthedocs_data["theme"],
"pagename": None,
}
tmpl = template_loader.get_template('doc_builder/data.js.tmpl')
tmpl = template_loader.get_template("doc_builder/data.js.tmpl")
return tmpl.render(data_ctx)

def build(self):
build_command = [
self.python_env.venv_bin(filename='python'),
'-m',
'mkdocs',
self.python_env.venv_bin(filename="python"),
"-m",
"mkdocs",
self.builder,
"--clean",
"--site-dir",
Expand All @@ -287,7 +287,7 @@ def build(self):
os.path.relpath(self.yaml_file, self.project_path),
]
if self.config.mkdocs.fail_on_warning:
build_command.append('--strict')
build_command.append("--strict")
cmd_ret = self.run(
*build_command,
cwd=self.project_path,
Expand All @@ -305,19 +305,19 @@ def get_theme_name(self, mkdocs_config):
:see: http://www.mkdocs.org/about/release-notes/#theme-customization-1164
:returns: the name of the theme RTD will use
"""
theme_setting = mkdocs_config.get('theme')
theme_setting = mkdocs_config.get("theme")
if isinstance(theme_setting, dict):
# Full nested theme config (the new configuration)
return theme_setting.get('name') or self.DEFAULT_THEME_NAME
return theme_setting.get("name") or self.DEFAULT_THEME_NAME

if theme_setting:
# A string which is the name of the theme
return theme_setting

theme_dir = mkdocs_config.get('theme_dir')
theme_dir = mkdocs_config.get("theme_dir")
if theme_dir:
# Use the name of the directory in this project's custom theme directory
return theme_dir.rstrip('/').split('/')[-1]
return theme_dir.rstrip("/").split("/")[-1]

return self.DEFAULT_THEME_NAME

Expand Down
6 changes: 3 additions & 3 deletions readthedocs/doc_builder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def load_yaml_config(version, readthedocs_yaml_path=None):

def get_default_formats(project):
"""Get a list of the default formats for ``project``."""
formats = ['htmlzip']
formats = ["htmlzip"]
if project.enable_epub_build:
formats += ['epub']
formats += ["epub"]
if project.enable_pdf_build:
formats += ['pdf']
formats += ["pdf"]
return formats
1 change: 0 additions & 1 deletion readthedocs/doc_builder/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

"""Doc build constants."""

import re
Expand Down
Loading

0 comments on commit bde1f43

Please sign in to comment.