Skip to content

Commit cd75201

Browse files
committed
Update from 5cf8de1
1 parent 5451b79 commit cd75201

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

simple_repository_browser/__main__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ def main():
6969

7070

7171
if __name__ == '__main__':
72-
logging.basicConfig(level=logging.INFO)
72+
logging.basicConfig(level=logging.WARNING)
7373
main()

simple_repository_browser/crawler.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async def crawl_recursively(
6464
while packages_for_reindexing - seen:
6565
remaining_packages = packages_for_reindexing - seen
6666
pkg_name = remaining_packages.pop()
67-
print(
67+
logging.info(
6868
f"Index iteration loop. Looking at {pkg_name}, with {len(remaining_packages)} remaining ({len(seen)} having been completed)",
6969
)
7070
seen.add(pkg_name)
@@ -93,7 +93,7 @@ async def crawl_recursively(
9393
)
9494
except InvalidRequirement as err:
9595
# See https://discuss.python.org/t/pip-supporting-non-pep508-dependency-specifiers/23107.
96-
print(f"Problem handling package {pkg_name}: {err}")
96+
logging.warning(f"Problem handling package {pkg_name}: {err}")
9797
continue
9898

9999
for dist in pkg_info.requires_dist:
@@ -126,13 +126,13 @@ async def refetch_hook(self) -> None:
126126
for _, row in zip(range(100), s['rows']):
127127
popular_projects.append(row['project'])
128128
except Exception as err:
129-
print(f'Problem fetching popular projects ({err})')
129+
logging.warning(f'Problem fetching popular projects ({err})')
130130
pass
131131

132132
await self.crawl_recursively(packages_w_dist_info | set(popular_projects))
133133

134134
async def run_reindex_periodically(self) -> None:
135-
print("Starting the reindexing loop")
135+
logging.info("Starting the reindexing loop")
136136
while True:
137137
try:
138138
await self.refetch_hook()
@@ -163,7 +163,7 @@ async def fetch_pkg_info(
163163
return info_file, pkg_info
164164

165165
if force_recache:
166-
print('Recaching')
166+
logging.info('Recaching')
167167

168168
fetch_projects.insert_if_missing(
169169
self._projects_db,

simple_repository_browser/fetch_projects.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# or submit itself to any jurisdiction.
77

88
import datetime
9+
import logging
910

1011
from simple_repository import SimpleRepository
1112

@@ -46,13 +47,13 @@ def update_summary(conn, name: str, summary: str, release_date: datetime.datetim
4647

4748
async def fully_populate_db(connection, index: SimpleRepository):
4849
con = connection
49-
print('Fetching names from index')
50+
logging.info('Fetching names from index')
5051

5152
project_list = await index.get_project_list()
5253
project_names = [
5354
(project.normalized_name, project.name) for project in project_list.projects
5455
]
55-
print('Inserting all new names (if any)')
56+
logging.info('Inserting all new names (if any)')
5657
with con as cursor:
5758
for canonical_name, name in project_names:
5859
cursor.execute(
@@ -66,12 +67,12 @@ async def fully_populate_db(connection, index: SimpleRepository):
6667
index_canonical_names = {normed_name for normed_name, _ in project_names}
6768

6869
if not index_canonical_names:
69-
print("No names found on the index. Not removing from the database, as this is likely a problem with the index.")
70+
logging.warning("No names found on the index. Not removing from the database, as this is likely a problem with the index.")
7071
return
7172

7273
names_in_db_no_longer_in_index = db_canonical_names - index_canonical_names
7374
if names_in_db_no_longer_in_index:
74-
print(
75+
logging.warning(
7576
f'Removing the following { len(names_in_db_no_longer_in_index) } names from the database:\n '
7677
"\n ".join(list(names_in_db_no_longer_in_index)[:2000]),
7778
)
@@ -84,4 +85,4 @@ async def fully_populate_db(connection, index: SimpleRepository):
8485
''',
8586
(name,),
8687
)
87-
print('DB synchronised with index')
88+
logging.info('DB synchronised with index')

simple_repository_browser/view.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import fastapi
1212
import jinja2
1313
from packaging.requirements import Requirement
14+
from starlette.datastructures import URL
1415

1516
from . import model
1617

@@ -26,14 +27,14 @@ def create_templates_environment(self) -> jinja2.Environment:
2627
templates = jinja2.Environment(loader=loader, autoescape=True, undefined=jinja2.StrictUndefined)
2728

2829
@jinja2.pass_context
29-
def url_for(context: typing.Mapping[str, typing.Any], name: str, **path_params: typing.Any) -> str:
30+
def url_for(context: typing.Mapping[str, typing.Any], name: str, **path_params: typing.Any) -> URL:
3031
request: fastapi.Request = context["request"]
3132
# We don't use request.url_for, as it always returns an absolute URL.
3233
# This prohibits running behind a proxy which doesn't correctly set
3334
# X-Forwarded-Proto / X-Forwarded-Prefix, such as the OpenShift ingress.
3435
# See https://github.com/encode/starlette/issues/538#issuecomment-1135096753 for the
3536
# proposed solution.
36-
return str(request.app.url_path_for(name, **path_params))
37+
return URL(str(request.app.url_path_for(name, **path_params)))
3738

3839
def sizeof_fmt(num: float, suffix: str = "B"):
3940
for unit in ("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi"):

0 commit comments

Comments
 (0)