Skip to content

Commit

Permalink
fix(scraper): Fix bulk analyzis helper to return a sync Generator (#99)
Browse files Browse the repository at this point in the history
* fix(scraper): Fix bulk analyzis helper to return a sync Generator

* fix(scraper): Fix tests

* refactor(cli): Update dockerfile
  • Loading branch information
vvatelot authored Aug 30, 2024
1 parent 7525267 commit 974aba3
Show file tree
Hide file tree
Showing 5 changed files with 956 additions and 828 deletions.
17 changes: 7 additions & 10 deletions bases/ecoindex/cli/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from asyncio import run
from datetime import datetime
from multiprocessing import cpu_count
from os.path import dirname
Expand Down Expand Up @@ -225,15 +224,13 @@ def analyze(
count_errors = 0
task = progress.add_task("Processing", total=len(urls) * len(window_sizes))

analysis_results = run(
bulk_analysis(
max_workers=max_workers,
urls=urls,
window_sizes=window_sizes,
wait_after_scroll=wait_after_scroll,
wait_before_scroll=wait_before_scroll,
logger=logger,
)
analysis_results = bulk_analysis(
max_workers=max_workers,
urls=urls,
window_sizes=window_sizes,
wait_after_scroll=wait_after_scroll,
wait_before_scroll=wait_before_scroll,
logger=logger,
)

for result, success in analysis_results:
Expand Down
6 changes: 3 additions & 3 deletions components/ecoindex/scraper/helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from asyncio import run
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import AsyncGenerator
from typing import Generator

from ecoindex.models.compute import Result, WindowSize
from ecoindex.scraper.scrap import EcoindexScraper
Expand Down Expand Up @@ -40,14 +40,14 @@ def run_page_analysis(
)


async def bulk_analysis(
def bulk_analysis(
max_workers,
urls,
window_sizes,
wait_after_scroll: int = 0,
wait_before_scroll: int = 0,
logger=None,
) -> AsyncGenerator[tuple[Result, bool], None]:
) -> Generator[tuple[Result, bool], None, None]:
with ThreadPoolExecutor(max_workers=max_workers) as executor:
future_to_analysis = {}

Expand Down
4 changes: 2 additions & 2 deletions projects/ecoindex_cli/dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.12-slim as requirements-stage
FROM python:3.12-slim AS requirements-stage

WORKDIR /tmp

Expand All @@ -8,7 +8,7 @@ RUN poetry export --output=requirements.txt --without-hashes


FROM python:3.12-slim

ARG wheel=ecoindex_cli-2.26.0a0-py3-none-any.whl
ENV DOCKER_CONTAINER=True

Expand Down
Loading

1 comment on commit 974aba3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage PR

Branch coverage •
FileStmtsMissCoverMissing
bases/ecoindex/cli
   app.py944354%138–141, 143, 158–159, 171, 204–205, 207, 215, 224–225, 227, 236–239, 241, 243–244, 249, 253–254, 256, 258, 261, 263–265, 267–268, 271–273, 281, 285, 317, 319, 327, 331, 335
components/ecoindex/scraper
   helper.py201335%17, 24–27, 29, 51–52, 54–56, 73–74
TOTAL69722767% 

Please sign in to comment.