Skip to content

Commit

Permalink
🔧 Update configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
sjquant committed May 18, 2024
1 parent 435b355 commit 089fbd8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ exclude = [
".mypy_cache",
".ruff_cache",
]
target-version = "py311"
target-version = "py310"

[tool.ruff.lint]
select = [
Expand All @@ -43,11 +43,9 @@ select = [
]

[tool.pyright]
include = ["src"]
exclude = ["**/node_modules",
"**/__pycache__",
"src/experimental",
"src/typestubs"
include = ["sitemapr", "tests"]
exclude = [
"**/__pycache__"
]
pythonVersion = "3.11"
pythonVersion = "3.10"
typeCheckingMode = "strict"
20 changes: 5 additions & 15 deletions sitemapr/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ class SiteMapr:
sitemap_base_url: The base URL for the sitemap. Defaults to None, which uses the base_url.
"""

def __init__(
self, base_url: str, pages: list[Page], *, sitemap_base_url: str | None = None
):
def __init__(self, base_url: str, pages: list[Page], *, sitemap_base_url: str | None = None):
self._base_url = base_url
self._sitemap_base_url = sitemap_base_url or base_url
self._pages = pages
Expand Down Expand Up @@ -63,9 +61,7 @@ def _write_index_file(self, dirname: str, idx: int) -> None:
'<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'
)
for i in range(idx + 1):
f.write(
f"<sitemap><loc>{self._sitemap_base_url}/sitemap-{i}.xml</loc></sitemap>"
)
f.write(f"<sitemap><loc>{self._sitemap_base_url}/sitemap-{i}.xml</loc></sitemap>")
f.write("</sitemapindex>")

def _write_urls(self, f: TextIOWrapper, urls: list[SiteMapUrl]):
Expand Down Expand Up @@ -98,9 +94,7 @@ def _iter_page(self, page: Page) -> Iterator[SiteMapUrl]:
path_param_combinations: list[dict[str, str]] = self._get_param_combinations(
page.path_params
)
for query_params, path_params in product(
query_param_combinations, path_param_combinations
):
for query_params, path_params in product(query_param_combinations, path_param_combinations):
path = page.path.format(**path_params)
query_string = urlencode(query_params).replace("&", "&amp;")
loc = (
Expand Down Expand Up @@ -134,16 +128,12 @@ def _iter_page(self, page: Page) -> Iterator[SiteMapUrl]:
priority=priority,
)

def _get_param_combinations(
self, params: list[Param] | None
) -> list[dict[str, str]]:
def _get_param_combinations(self, params: list[Param] | None) -> list[dict[str, str]]:
if not params:
return [{}]

combinations: list[dict[str, str]] = []
for values in product(*[param.values for param in params if param.values]):
combination = {
param.name: value for param, value in zip(params, values, strict=False)
}
combination = {param.name: value for param, value in zip(params, values, strict=False)}
combinations.append(combination)
return combinations
4 changes: 1 addition & 3 deletions sitemapr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

T = TypeVar("T")

ChangeFreq = Literal[
"always", "hourly", "daily", "weekly", "monthly", "yearly", "never"
]
ChangeFreq = Literal["always", "hourly", "daily", "weekly", "monthly", "yearly", "never"]

CallbackFn = Callable[[str, dict[str, str], dict[str, str]], T | None]

Expand Down

0 comments on commit 089fbd8

Please sign in to comment.