diff options
Diffstat (limited to '')
| -rw-r--r-- | docs/changelog.rst | 3 | ||||
| -rw-r--r-- | docs/conf.py | 8 | ||||
| -rw-r--r-- | docs/netlify_build.py | 4 | ||||
| -rw-r--r-- | docs/utils.py | 17 | 
4 files changed, 17 insertions, 15 deletions
| diff --git a/docs/changelog.rst b/docs/changelog.rst index d9075d47..1817102e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,6 +3,9 @@  Changelog  ========= +- :feature:`176` Migrate repo to use ruff for linting + +  - :release:`9.6.0 <6th May 2023>`  - :feature:`175` Log when waiting for the guild to be available before loading cogs  - :support:`175` Bump Discord.py to :literal-url:`2.2.3 <https://github.com/Rapptz/discord.py/releases/tag/v2.2.3>`. diff --git a/docs/conf.py b/docs/conf.py index 2fea7264..23636774 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,6 +1,7 @@  # Configuration file for the Sphinx documentation builder.  # https://www.sphinx-doc.org/en/master/usage/configuration.html +import contextlib  import functools  import os.path  import shutil @@ -16,7 +17,7 @@ from sphinx.application import Sphinx  logger = sphinx.util.logging.getLogger(__name__)  # Handle the path not being set correctly in actions. -sys.path.insert(0, os.path.abspath('..')) +sys.path.insert(0, os.path.abspath(".."))  from docs import utils  # noqa: E402 @@ -209,10 +210,9 @@ smv_latest_version = "main"  smv_branch_whitelist = "main"  if os.getenv("BUILD_DOCS_FOR_HEAD", "False").lower() == "true":      if not (branch := os.getenv("BRANCH_NAME")): -        try: +        with contextlib.suppress(git.InvalidGitRepositoryError):              branch = git.Repo(PROJECT_ROOT).active_branch.name -        except git.InvalidGitRepositoryError: -            pass +      if branch:          logger.info(f"Adding branch {branch} to build whitelist.") diff --git a/docs/netlify_build.py b/docs/netlify_build.py index 1704eece..a6da74df 100644 --- a/docs/netlify_build.py +++ b/docs/netlify_build.py @@ -22,5 +22,5 @@ OUTPUT.write_text(build_script.text, encoding="utf-8")  if __name__ == "__main__":      # Run the build script -    print("Build started") -    subprocess.run([sys.executable, OUTPUT.absolute()]) +    print("Build started")  # noqa: T201 +    subprocess.run([sys.executable, OUTPUT.absolute()])  # noqa: S603 diff --git a/docs/utils.py b/docs/utils.py index 3f58e767..3a20b87f 100644 --- a/docs/utils.py +++ b/docs/utils.py @@ -30,16 +30,15 @@ def get_build_root() -> Path:  def is_attribute(module: types.ModuleType, parameter: str) -> bool:      """Returns true if `parameter` is an attribute of `module`."""      docs = docstring_parser.parse(inspect.getdoc(module), docstring_parser.DocstringStyle.GOOGLE) -    for param in docs.params: +    for param in docs.params:  # noqa: SIM110          # The docstring_parser library can mis-parse arguments like `arg (:obj:`str`)` as `arg (`          # which would create a false-negative below, so we just strip away the extra parenthesis.          if param.args[0] == "attribute" and param.arg_name.rstrip(" (") == parameter:              return True -      return False -def linkcode_resolve(repo_link: str, domain: str, info: dict[str, str]) -> typing.Optional[str]: +def linkcode_resolve(repo_link: str, domain: str, info: dict[str, str]) -> str | None:      """      Function called by linkcode to get the URL for a given resource. @@ -79,8 +78,7 @@ def linkcode_resolve(repo_link: str, domain: str, info: dict[str, str]) -> typin              # This could be caused by trying to link a class attribute              if is_attribute(symbol[-1], name):                  break -            else: -                raise e +            raise e          symbol_name = name @@ -97,8 +95,8 @@ def linkcode_resolve(repo_link: str, domain: str, info: dict[str, str]) -> typin          pos = _global_assign_pos(source, symbol_name)          if pos is None:              raise Exception(f"Could not find symbol `{symbol_name}` in {module.__name__}.") -        else: -            start, end = pos + +        start, end = pos          _, offset = inspect.getsourcelines(symbol[-2])          if offset != 0:              offset -= 1 @@ -126,7 +124,7 @@ class NodeWithBody(typing.Protocol):      body: list[ast.AST] -def _global_assign_pos(ast_: NodeWithBody, name: str) -> typing.Union[tuple[int, int], None]: +def _global_assign_pos(ast_: NodeWithBody, name: str) -> tuple[int, int] | None:      """      Find the first instance where the `name` global is defined in `ast_`. @@ -149,6 +147,7 @@ def _global_assign_pos(ast_: NodeWithBody, name: str) -> typing.Union[tuple[int,              pos_in_if = _global_assign_pos(ast_obj, name)              if pos_in_if is not None:                  return pos_in_if +    return None  def cleanup() -> None: @@ -200,7 +199,7 @@ def build_api_doc() -> None:          logger.info(f"Skipping api-doc for {output_folder.as_posix()} as it already exists.")          return -    result = subprocess.run(cmd, cwd=build_root, stdout=subprocess.PIPE, check=True, env=os.environ) +    result = subprocess.run(cmd, cwd=build_root, stdout=subprocess.PIPE, check=True, env=os.environ)  # noqa: S603      logger.debug("api-doc Output:\n" + result.stdout.decode(encoding="utf-8") + "\n")      cleanup() | 
