Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 7, 2023
1 parent aa25614 commit 6284e93
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 39 deletions.
19 changes: 14 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,20 @@
from pybtex.plugin import register_plugin
from pybtex.richtext import BaseText, Tag, Text
from pybtex.style.formatting.unsrt import Style as UnsrtStyle
from pybtex.style.template import (FieldIsMissing, Node, _format_list, field,
href, join, node, sentence, words)
from pybtex.style.template import (
FieldIsMissing,
Node,
_format_list,
field,
href,
join,
node,
sentence,
words,
)
from sphinx.application import Sphinx
from sphinx.util.typing import RoleFunction
from sphinxcontrib.bibtex.style.referencing.author_year import \
AuthorYearReferenceStyle
from sphinxcontrib.bibtex.style.referencing.author_year import AuthorYearReferenceStyle

if sys.version_info < (3, 8):
from importlib_metadata import PackageNotFoundError
Expand Down Expand Up @@ -211,8 +219,9 @@ def get_minor_version(package_name: str) -> str:
return installed_version
matches = re.match(r"^([0-9]+\.[0-9]+).*$", installed_version)
if matches is None:
msg = f"Could not find documentation for {package_name} v{installed_version}"
raise ValueError(
f"Could not find documentation for {package_name} v{installed_version}"
msg
)
return matches[1]

Expand Down
8 changes: 6 additions & 2 deletions docs/software.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,12 @@
"source": [
"from IPython.display import HTML\n",
"\n",
"from pwa_pages.project_inventory import (ProjectInventory, fix_html_alignment,\n",
" load_yaml, to_html_table)\n",
"from pwa_pages.project_inventory import (\n",
" ProjectInventory,\n",
" fix_html_alignment,\n",
" load_yaml,\n",
" to_html_table,\n",
")\n",
"\n",
"inventory_dict = load_yaml(\"software/amplitude-analysis-projects.yml\")\n",
"html_src = to_html_table(\n",
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# noqa: D100
from setuptools import setup

setup(
Expand Down
12 changes: 6 additions & 6 deletions src/pwa_pages/project_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def fix_html_alignment(src: str) -> str:
src,
)
src = src.replace('align="left"', left_align_style)
src = src.replace("<th>", f"<th {left_align_style}>")
return src
return src.replace("<th>", f"<th {left_align_style}>")


class SubProject(BaseModel):
Expand Down Expand Up @@ -104,7 +103,8 @@ def _check_collaboration_exists(cls, values: dict) -> dict: # noqa: N805
collaborations = project.collaboration
for col in collaborations:
if col not in defined_collaborations:
raise ValueError(f"No collaboration defined for {col}")
msg = f"No collaboration defined for {col}"
raise ValueError(msg)
return values


Expand Down Expand Up @@ -226,7 +226,8 @@ def _format_collaboration(project: Project, inventory: "ProjectInventory") -> st
def _form_collaboration_link(inventory: ProjectInventory, name: str) -> str:
collaboration_url = inventory.collaborations.get(name)
if collaboration_url is None:
raise KeyError(f'Collaboration entry "{name}" not found')
msg = f'Collaboration entry "{name}" not found'
raise KeyError(msg)
return _form_html_link(name=name, url=collaboration_url)


Expand All @@ -240,8 +241,7 @@ def _enumerate_html_links(list_of_entries: Sequence[str]) -> str:
if len(list_of_entries) == 1:
return list_of_entries[0]
html = "<li>".join(list_of_entries)
html = "<li>" + html
return html
return "<li>" + html


def export_json_schema(argv: Optional[Sequence[str]] = None) -> int:
Expand Down
3 changes: 1 addition & 2 deletions src/pwa_pages/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import attr

from . import _github, _gitlab
from ._github import (GithubRepository, extract_github_repo_name,
get_github_repo)
from ._github import GithubRepository, extract_github_repo_name, get_github_repo
from ._gitlab import GitlabProject, get_gitlab_repo, split_gitlab_repo_url


Expand Down
19 changes: 12 additions & 7 deletions src/pwa_pages/repo/_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
import re
from datetime import datetime
from functools import lru_cache
from typing import Dict, Optional
from typing import TYPE_CHECKING, Dict, Optional

from dateutil.parser import parse as parse_date
from github import Github
from github.Commit import Commit
from github.Repository import Repository as GithubRepository

if TYPE_CHECKING:
from github.Commit import Commit


@lru_cache()
def get_github_repo(url: str) -> GithubRepository:
github = __get_github()
repo_name = extract_github_repo_name(url)
if not repo_name:
raise ValueError(f"Not a GitHub repo URL: {url}")
msg = f"Not a GitHub repo URL: {url}"
raise ValueError(msg)
return github.get_repo(repo_name)


Expand All @@ -34,8 +37,9 @@ def get_first_commit_date(repo: GithubRepository) -> datetime:
first_commit: Commit = commits[0]
timestamp = first_commit.last_modified
if timestamp is None:
msg = f"First commit on of GitHub repo {repo.full_name} has no timestamp"
raise ValueError(
f"First commit on of GitHub repo {repo.full_name} has no timestamp"
msg
)
return parse_date(timestamp)

Expand All @@ -46,16 +50,17 @@ def get_latest_commit_date(repo: GithubRepository) -> datetime:
latest_commit = repo.get_commit(default_branch)
timestamp = latest_commit.last_modified
if timestamp is None:
msg = f"Last commit on default branch {default_branch} of {repo.url} has no timestamp"
raise ValueError(
f"Last commit on default branch {default_branch} of"
f" {repo.url} has no timestamp"
msg
)
return parse_date(timestamp)


def get_last_modified(repo: GithubRepository) -> datetime:
if repo.last_modified is None:
raise ValueError(f"GitHub repo {repo.full_name} has no last modified timestamp")
msg = f"GitHub repo {repo.full_name} has no last modified timestamp"
raise ValueError(msg)
return parse_date(repo.last_modified)


Expand Down
12 changes: 8 additions & 4 deletions tests/repo/test_github.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import pytest

from pwa_pages.repo._github import (extract_github_repo_name,
get_first_commit_date, get_github_repo,
get_languages, get_last_modified,
get_latest_commit_date)
from pwa_pages.repo._github import (
extract_github_repo_name,
get_first_commit_date,
get_github_repo,
get_languages,
get_last_modified,
get_latest_commit_date,
)


def test_get_first_commit_date():
Expand Down
10 changes: 7 additions & 3 deletions tests/repo/test_gitlab.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# pylint: disable=redefined-outer-name
import pytest

from pwa_pages.repo._gitlab import (get_first_commit_date, get_gitlab_repo,
get_last_modified, get_latest_commit_date,
split_gitlab_repo_url)
from pwa_pages.repo._gitlab import (
get_first_commit_date,
get_gitlab_repo,
get_last_modified,
get_latest_commit_date,
split_gitlab_repo_url,
)


def test_get_gitlab_repo():
Expand Down
24 changes: 15 additions & 9 deletions tests/test_project_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@
import yaml
from pydantic import ValidationError

from pwa_pages.project_inventory import (Project, ProjectInventory, SubProject,
_checkmark_language,
_create_project_entry,
_fetch_languages,
_get_subproject_timestamps,
export_json_schema,
fix_html_alignment, load_yaml,
to_html_table)
from pwa_pages.project_inventory import (
Project,
ProjectInventory,
SubProject,
_checkmark_language,
_create_project_entry,
_fetch_languages,
_get_subproject_timestamps,
export_json_schema,
fix_html_alignment,
load_yaml,
to_html_table,
)

__MAX_PROJECTS = 4

Expand Down Expand Up @@ -168,4 +173,5 @@ def test_get_subproject_timestamps(project_inventory: ProjectInventory):
)
assert len(timestamps) == 3
return
raise ValueError(f"Project {project_name} not found")
msg = f"Project {project_name} not found"
raise ValueError(msg)

0 comments on commit 6284e93

Please sign in to comment.