Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use requests session #48

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions build_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import tomllib
from collections.abc import Iterator

import requests
from requests import Session


def get_languages() -> Iterator[tuple[str, bool]]:
def get_languages(requests: Session) -> Iterator[tuple[str, bool]]:
data = requests.get(
'https://raw.githubusercontent.com/'
'python/docsbuild-scripts/refs/heads/main/config.toml',
Expand All @@ -25,7 +25,9 @@ def get_languages() -> Iterator[tuple[str, bool]]:


def main() -> None:
languages = {language: in_switcher for language, in_switcher in get_languages()}
languages = {
language: in_switcher for language, in_switcher in get_languages(Session())
}
print(languages)
for code in ('en', 'pl', 'ar', 'zh-cn', 'id'):
print(f'{code}: {code in languages} {languages.get(code)}')
Expand Down
7 changes: 5 additions & 2 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from pathlib import Path
from tempfile import TemporaryDirectory

from requests import Session
from git import Repo
from jinja2 import Template

Expand Down Expand Up @@ -44,12 +45,14 @@ def get_completion_progress() -> Iterator['LanguageProjectData']:
)
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'venv'], check=True)
subprocess.run(['make', '-C', cpython_dir / 'Doc', 'gettext'], check=True)
languages_built = dict(build_status.get_languages())
languages_built = dict(build_status.get_languages(session := Session()))
for language, repo in get_languages_and_repos(devguide_dir):
built = language.code in languages_built
if repo:
completion, translators_data = get_completion(clones_dir, repo)
visitors_num = get_number_of_visitors(language.code) if built else 0
visitors_num = (
get_number_of_visitors(language.code, session) if built else 0
)
else:
completion = 0.0
translators_data = TranslatorsData(0, False)
Expand Down
4 changes: 2 additions & 2 deletions visitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import urllib
import zipfile

import requests
from requests import Session


def get_number_of_visitors(language: str) -> int:
def get_number_of_visitors(language: str, requests: Session) -> int:
params = urllib.parse.urlencode(
{'filters': f'[["contains","event:page",["/{language}/"]]]', 'period': 'all'}
)
Expand Down
Loading