-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
scrapy-spider-metadata support. (#75)
* scrapy-spider-metadata support. * Fixes. * get_metadata_for_spider was renamed. * Add tests for shub-image-info. * Fix tests without scrapy-spider-metadata. * Remove scraoy-spider-metadata from requirements. * Cleanup.
- Loading branch information
Showing
4 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
from typing import Tuple, Optional, Union | ||
|
||
|
||
def call_command(cwd: Union[str, os.PathLike], *args: str) -> Tuple[str, str]: | ||
result = subprocess.run( | ||
args, | ||
cwd=str(cwd), | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
universal_newlines=True, | ||
) | ||
assert result.returncode == 0, result.stderr | ||
return result.stdout, result.stderr | ||
|
||
|
||
def call_scrapy_command(cwd: Union[str, os.PathLike], *args: str) -> Tuple[str, str]: | ||
args = (sys.executable, "-m", "scrapy.cmdline") + args | ||
return call_command(cwd, *args) | ||
|
||
|
||
def create_project(topdir: Path, spider_text: Optional[str] = None) -> Path: | ||
project_name = "foo" | ||
cwd = topdir | ||
call_scrapy_command(str(cwd), "startproject", project_name) | ||
cwd /= project_name | ||
(cwd / project_name / "spiders" / "spider.py").write_text(spider_text or """ | ||
from scrapy import Spider | ||
class MySpider(Spider): | ||
name = "myspider" | ||
""") | ||
return cwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters