Skip to content

Commit

Permalink
chore: Template upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed May 16, 2023
1 parent ee59c8c commit d35f2d7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 0.15.6
_commit: 0.15.7
_src_path: gh:pawamoy/copier-pdm
author_email: pawamoy@pm.me
author_fullname: Timothée Mazzucotelli
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Changelog = "https://mkdocstrings.github.io/python/changelog"
Repository = "https://github.com/mkdocstrings/python"
Issues = "https://github.com/mkdocstrings/python/issues"
Discussions = "https://github.com/mkdocstrings/python/discussions"
Gitter = "https://gitter.im/python/community"
Funding = "https://github.com/sponsors/mkdocstrings"
Gitter = "https://gitter.im/mkdocstrings/python"
Funding = "https://github.com/sponsors/pawamoy"

[tool.pdm]
version = {source = "scm"}
Expand Down
43 changes: 29 additions & 14 deletions scripts/insiders.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,32 @@ def load_goals(data: str, funding: int = 0, project: Project | None = None) -> d
}


def funding_goals(source: str | list[tuple[str, str, str]], funding: int = 0) -> dict:
def _load_goals_from_disk(path: str, funding: int = 0) -> dict[int, Goal]:
try:
data = Path(path).read_text()
except OSError as error:
raise RuntimeError(f"Could not load data from disk: {path}") from error
return load_goals(data, funding)


def _load_goals_from_url(source_data: tuple[str, str, str], funding: int = 0) -> dict[int, Goal]:
project_name, project_url, data_fragment = source_data
data_url = urljoin(project_url, data_fragment)
try:
with urlopen(data_url) as response: # noqa: S310
data = response.read()
except HTTPError as error:
raise RuntimeError(f"Could not load data from network: {data_url}") from error
return load_goals(data, funding, project=Project(name=project_name, url=project_url))


def _load_goals(source: str | tuple[str, str, str], funding: int = 0) -> dict[int, Goal]:
if isinstance(source, str):
return _load_goals_from_disk(source, funding)
return _load_goals_from_url(source, funding)


def funding_goals(source: str | list[str | tuple[str, str, str]], funding: int = 0) -> dict[int, Goal]:
"""Load funding goals from a given data source.
Parameters:
Expand All @@ -123,20 +148,10 @@ def funding_goals(source: str | list[tuple[str, str, str]], funding: int = 0) ->
A dictionaries of goals, keys being their target monthly amount.
"""
if isinstance(source, str):
try:
data = Path(source).read_text()
except OSError as error:
raise RuntimeError(f"Could not load data from disk: {source}") from error
return load_goals(data, funding)
return _load_goals_from_disk(source, funding)
goals = {}
for project_name, project_url, data_fragment in source:
data_url = urljoin(project_url, data_fragment)
try:
with urlopen(data_url) as response: # noqa: S310
data = response.read()
except HTTPError as error:
raise RuntimeError(f"Could not load data from network: {data_url}") from error
source_goals = load_goals(data, funding, project=Project(name=project_name, url=project_url))
for src in source:
source_goals = _load_goals(src)
for amount, goal in source_goals.items():
if amount not in goals:
goals[amount] = goal
Expand Down

0 comments on commit d35f2d7

Please sign in to comment.