Skip to content

Commit

Permalink
Update: docstrings in folder commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas-Moliterno committed Nov 10, 2024
1 parent 46ab55a commit b8c0fee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion scrapy/commands/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,34 @@


class Command(ScrapyCommand):
"""Run a quick benchmark test by initiating a crawler process."""
default_settings = {
"LOG_LEVEL": "INFO",
"LOGSTATS_INTERVAL": 1,
"CLOSESPIDER_TIMEOUT": 10,
}

def short_desc(self) -> str:
"""Return a brief description of the command."""
return "Run quick benchmark test"

def run(self, args: list[str], opts: argparse.Namespace) -> None:
"""Execute the benchmark test with specified arguments and options.
Args:
args (list[str]): Command-line arguments for the command.
opts (argparse.Namespace): Parsed command-line options.
"""
with _BenchServer():
assert self.crawler_process
self.crawler_process.crawl(_BenchSpider, total=100000)
self.crawler_process.start()


class _BenchServer:
"""Context manager for starting and stopping a benchmark server subprocess."""
def __enter__(self) -> None:
"""Start the benchmark server as a subprocess."""
from scrapy.utils.test import get_testenv

pargs = [sys.executable, "-u", "-m", "scrapy.utils.benchserver"]
Expand All @@ -47,13 +57,14 @@ def __enter__(self) -> None:
self.proc.stdout.readline()

def __exit__(self, exc_type, exc_value, traceback) -> None:
"""Terminate the benchmark server subprocess and wait for it to finish."""
self.proc.kill()
self.proc.wait()
time.sleep(0.2)


class _BenchSpider(scrapy.Spider):
"""A spider that follows all links"""
"""Spider that follows all links on a given page and extracts further links."""

name = "follow"
total = 10000
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sonar.projectKey=MO827_scrapy
sonar.projectName=MO827 Scrapy Project
sonar.sources=scrapy/commands
sonar.sources=scrapy

0 comments on commit b8c0fee

Please sign in to comment.