Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
38e026e
Fix bug for scrapyd v1.5.0
my8100 Dec 1, 2024
6ee70fa
Fix bug for scrapyd v1.5.0 again
my8100 Dec 1, 2024
20b1ec6
Fix test_run for scrapyd v1.5.0
my8100 Dec 1, 2024
92405e5
Support last_modified in Logs and Items page
my8100 Dec 1, 2024
95d9dc5
Fix test_run for scrapyd v1.5.0 again
my8100 Dec 1, 2024
0a0145d
Support python 3.13 and test more with latest scrapyd
my8100 Dec 1, 2024
881db5b
Require logparser==0.8.3
my8100 Jan 2, 2025
b826a7e
Generate Allure report on CircleCI
my8100 Jan 2, 2025
2a15368
Update config.yml
my8100 Jan 2, 2025
e5ba7e2
Update config.yml
my8100 Jan 2, 2025
ba76a58
Update config.yml
my8100 Jan 2, 2025
4d53479
Update config.yml
my8100 Jan 2, 2025
0bafa0b
Update config.yml
my8100 Jan 2, 2025
3f80041
Update config.yml
my8100 Jan 2, 2025
6f398ae
Update config.yml
my8100 Jan 2, 2025
f6993fc
Update config.yml
my8100 Jan 2, 2025
ba2ce25
Update config.yml
my8100 Jan 2, 2025
2820219
Update config.yml
my8100 Jan 2, 2025
c0f6c3a
Update config.yml
my8100 Jan 2, 2025
d535e28
Update config.yml
my8100 Jan 2, 2025
1c259ab
Update config.yml
my8100 Jan 2, 2025
17ccd79
Update config.yml
my8100 Jan 2, 2025
1039f14
Update config.yml
my8100 Jan 2, 2025
557357b
Update config.yml
my8100 Jan 2, 2025
f1a8696
Update config.yml
my8100 Jan 2, 2025
2ae03c2
Update config.yml
my8100 Jan 2, 2025
5e78720
Revert "Update config.yml"
my8100 Jan 2, 2025
910c12b
Revert "Update config.yml"
my8100 Jan 2, 2025
9a30fdd
Revert "Update config.yml"
my8100 Jan 2, 2025
4a96eab
Revert "Update config.yml"
my8100 Jan 2, 2025
e62980f
Update config.yml
my8100 Jan 2, 2025
a11a4c5
Update config.yml
my8100 Jan 2, 2025
3e6708e
Update config.yml
my8100 Jan 2, 2025
88656ac
Update config.yml
my8100 Jan 2, 2025
5473766
Update config.yml
my8100 Jan 2, 2025
29e3364
Update config.yml
my8100 Jan 2, 2025
5ad3b67
Update config.yml
my8100 Jan 2, 2025
39b8e0a
Update config.yml
my8100 Jan 2, 2025
9c11eb8
Update config.yml
my8100 Jan 2, 2025
c9c9010
Update config.yml
my8100 Jan 2, 2025
6e7f49e
Update config.yml
my8100 Jan 2, 2025
24d03fa
Update config.yml
my8100 Jan 3, 2025
50c29bc
Require logparser>=0.8.4
my8100 Jan 5, 2025
c60cbb4
Update tests\utils.py
my8100 Jan 12, 2025
d71b238
Update test_schedule.py
my8100 Jan 12, 2025
cad06a8
Update config.yml
my8100 Jan 12, 2025
e063e8f
Update test_schedule.py
my8100 Jan 12, 2025
a053752
Update test_schedule.py
my8100 Jan 12, 2025
b81dec7
Update test_schedule.py
my8100 Jan 12, 2025
03d64fb
Update config.yml
my8100 Jan 12, 2025
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
110 changes: 100 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
version: 2.1
orbs:
codecov: codecov/codecov@1.0.2
allure: ayte/allure@0.1.3
jobs:
py39: &test-template
docker:
Expand All @@ -15,7 +16,7 @@ jobs:
default: false
use-scrapyd-v143:
type: boolean
default: true
default: false
use-git:
type: boolean
default: false
Expand All @@ -31,16 +32,46 @@ jobs:
use-mysql:
type: boolean
default: false
allure-version:
description: Allure version to use
type: string
default: 2.13.1
allure-configuration-path:
description: Path to Allure configuration, uses default one if omitted
type: string
default: /usr/local/share/allure/config/allure.yml
allure-target-path:
description: Path for report directory
type: string
default: allure-report
allure-results-path:
description: Path to directory with test results
type: string
default: allure-results
allure-artifact-path:
description: Path that will be used when storing result as artifact
type: string
default: Report/Allure
steps:
- run:
name: Install telnet
command: |
sudo apt-get update && sudo apt-get install telnet
- run:
name: Install Java 11
command: |
sudo apt-get update
sudo apt-get install -y openjdk-11-jdk
- run:
name: Set JAVA_HOME
command: |
echo "export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64" >> $BASH_ENV
source $BASH_ENV
- run:
name: Setup env
command: |
mkdir ~/logs
ls -l ~
ls -la ~
- checkout
- when:
condition: <<parameters.is-py27>>
Expand Down Expand Up @@ -154,11 +185,12 @@ jobs:
name: Run tests
command: |
pip list
ls -l
ls -la
. venv/bin/activate
flake8 . --count --exclude=./venv* --select=E9,F63,F7,F82 --show-source --statistics
coverage erase
coverage run --source=scrapydweb -m pytest tests -s -vv -l --disable-warnings
# tests/test_schedule.py
coverage run --source=scrapydweb -m pytest -s -vv -l --disable-warnings --alluredir=allure-results tests
- run:
name: Generate report
command: |
Expand All @@ -169,13 +201,66 @@ jobs:
coverage html
coverage xml
ls -la
ls -la allure-results || echo 'ignore error'
coveralls
# https://discuss.circleci.com/t/make-custom-command-run-always-with-when-always/38957
# https://circleci.com/docs/configuration-reference/#the-when-attribute
when: always
- store_artifacts:
path: htmlcov
- store_artifacts:
path: coverage.xml
- codecov/upload:
file: coverage.xml
# https://circleci.com/developer/orbs/orb/codecov/codecov
# - codecov/upload
# https://circleci.com/developer/orbs/orb/coveralls/coveralls
# - coveralls/upload
# https://discuss.circleci.com/t/how-can-we-publish-pytest-results-to-circleci-using-allure-reports/37830/2
# https://circleci.com/developer/orbs/orb/ayte/allure
# - allure/install
# - allure/report
# https://circleci.com/docs/configuration-reference/#the-when-step
- when:
condition:
equal: [ 1, 1 ]
steps:
- run:
name: Allure archive download
command: >-
curl -L https://github.com/allure-framework/allure2/releases/download/<<
parameters.allure-version >>/allure-commandline-<< parameters.allure-version >>.zip -o
/tmp/allure.zip
when: always
- run:
name: Archive extraction
command: unzip /tmp/allure.zip
when: always
- run:
name: Allure installation
command: sudo mv allure-<< parameters.allure-version >> /usr/local/share/allure
when: always
- run:
name: Allure binary symlinking
command: sudo ln -s /usr/local/share/allure/bin/allure /usr/local/bin/allure
when: always
- when:
condition:
equal: [ 1, 1 ]
steps:
- run:
name: >-
Allure report generation (<< parameters.allure-results-path >> -> <<
parameters.allure-target-path >>)
command: |
allure generate \
--config << parameters.allure-configuration-path >> \
--report-dir << parameters.allure-target-path >> \
<< parameters.allure-results-path >>
when: always
- store_artifacts:
path: << parameters.allure-target-path >>
destination: << parameters.allure-artifact-path >>
py27:
<<: *test-template
docker:
Expand All @@ -192,7 +277,7 @@ jobs:
<<: *test-template
docker:
- image: cimg/python:3.8
py39-scrapyd-latest:
py39-scrapyd-v143:
<<: *test-template
docker:
- image: cimg/python:3.9
Expand Down Expand Up @@ -274,10 +359,14 @@ jobs:
<<: *test-template
docker:
- image: cimg/python:3.12
py312-scrapyd-latest:
py312-scrapyd-v143:
<<: *test-template
docker:
- image: cimg/python:3.12
py313:
<<: *test-template
docker:
- image: cimg/python:3.13
workflows:
test:
jobs:
Expand All @@ -287,8 +376,8 @@ workflows:
# - py37
- py38
- py39
- py39-scrapyd-latest:
use-scrapyd-v143: false
- py39-scrapyd-v143:
use-scrapyd-v143: true
- py310-git-postgresql:
use-git: true
use-postgresql: true
Expand All @@ -304,5 +393,6 @@ workflows:
use-mysql: true
- py311
- py312
- py312-scrapyd-latest:
use-scrapyd-v143: false
- py312-scrapyd-v143:
use-scrapyd-v143: true
- py313
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ scrapydweb_settings_v*.py

tests/*.html
tests/data/
allure-results/


scrapydweb/data/*
Expand Down
1 change: 1 addition & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ coverage
pytest
# pytest-cov
coveralls
allure-pytest

scrapy
scrapyd
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Flask-SQLAlchemy==2.4.0
idna==2.7
itsdangerous==2.0.0
Jinja2==3.0.0
logparser==0.8.2
logparser>=0.8.4
MarkupSafe==2.0.0
pexpect==4.7.0
ptyprocess==0.6.0
Expand Down
2 changes: 1 addition & 1 deletion scrapydweb/templates/scrapydweb/jobs.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<h2>
<a class="link" target="_blank" href="{{ url }}">Get the list of jobs of all projects in database.</a>
<label title="switch to non-database view">
<a class="button normal" href="{{ url_jobs_classic }}">Classic</a>
<a class="button normal" href="{{ url_jobs_classic }}">Classic View</a>
</label>
<label title="schedule a spider run">
<a class="button safe narrow" href="{{ url_schedule }}">+</a>
Expand Down
4 changes: 2 additions & 2 deletions scrapydweb/templates/scrapydweb/jobs_classic.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<h2>
<a class="link" target="_blank" href="{{ url }}">Get the list of jobs of all projects after Scrapyd server started.</a>
<label title="switch to database view">
<a class="button normal" href="{{ url_jobs_database }}">Database</a>
<a class="button normal" href="{{ url_jobs_database }}">Database View</a>
</label>
<label title="schedule a spider run">
<a class="button safe narrow" href="{{ url_schedule }}">+</a>
Expand Down Expand Up @@ -140,7 +140,7 @@ <h3>Running ({{ running_jobs|length }}) <strong id="logparser_last_update" style


<div class="table wrap">
<h3>Finished ({{ finished_jobs|length }}) <strong style="color: red;">DESC</strong></h3>
<h3>Finished ({{ finished_jobs|length }}) <strong style="color: green;">ORDER BY finish DESC</strong></h3>
<table>
<thead>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion scrapydweb/templates/scrapydweb/jobs_mobileui.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@

<tr>
<th colspan="{{ colspan }}" class="category-head">Finished ({{ finished_jobs|length }})
<strong style="color: red;">DESC</strong>
<strong style="color: red;">sorted DESC</strong>
</th>
</tr>
{% for job in finished_jobs %}
Expand Down
2 changes: 2 additions & 0 deletions scrapydweb/templates/scrapydweb/logs_items.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ <h2>
<el-table-column prop="content_type" label="Content type" sortable width="135" align="center"></el-table-column>
<el-table-column prop="content_encoding" label="Encoding" sortable width="95" align="center"></el-table-column>
<el-table-column prop="size" label="Size" sortable width="100" align="center" :sort-method="sortSize" :sort-orders=['descending','ascending',null]></el-table-column>
<el-table-column prop="last_modified" label="Last modified" sortable width="140" align="center"></el-table-column>

{% if project and spider %}
<el-table-column prop="stats" label="Stats" sortable width="{% if SCRAPYD_SERVERS_AMOUNT > 1 %}105{% else %}65{% endif %}" align="center">
Expand Down Expand Up @@ -87,6 +88,7 @@ <h2>
content_type: '{{ row["content_type"] }}',
content_encoding: '{{ row["content_encoding"] }}',
size: '{{ row["size"] }}',
last_modified: '{{ row["last_modified"] }}',

{% if project and spider %}
url_clusterreports: '{{ row["url_clusterreports"] }}',
Expand Down
21 changes: 11 additions & 10 deletions scrapydweb/utils/poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@
logger.addHandler(_handler)

IN_WINDOWS = platform.system() == 'Windows'
# See also scrapydweb/views/dashboard/jobs.py
JOB_PATTERN = re.compile(r"""
<tr>
<td>(?P<Project>.*?)</td>
<td>(?P<Spider>.*?)</td>
<td>(?P<Job>.*?)</td>
(?:<td>(?P<PID>.*?)</td>)?
(?:<td>(?P<Start>.*?)</td>)?
(?:<td>(?P<Runtime>.*?)</td>)?
(?:<td>(?P<Finish>.*?)</td>)?
(?:<td>(?P<Log>.*?)</td>)?
(?:<td>(?P<Items>.*?)</td>)?
<tr>\s*
<td>(?P<Project>.*?)</td>\s*
<td>(?P<Spider>.*?)</td>\s*
<td>(?P<Job>.*?)</td>\s*
(?:<td>(?P<PID>.*?)</td>\s*)?
(?:<td>(?P<Start>.*?)</td>\s*)?
(?:<td>(?P<Runtime>.*?)</td>\s*)?
(?:<td>(?P<Finish>.*?)</td>\s*)?
(?:<td>(?P<Log>.*?)</td>\s*)?
(?:<td>(?P<Items>.*?)</td>\s*)?
[\w\W]*? # Temp support for Scrapyd v1.3.0 (not released)
</tr>
""", re.X)
Expand Down
3 changes: 2 additions & 1 deletion scrapydweb/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@
<tr\sclass="(?P<odd_even>odd|even)">\n
\s+<td>(?P<filename>.*?)</td>\n
\s+<td>(?P<size>.*?)</td>\n
(?:\s+<td>(?P<last_modified>.*?)</td>\n)?
\s+<td>(?P<content_type>.*?)</td>\n
\s+<td>(?P<content_encoding>.*?)</td>\n
</tr>
""", re.X)
DIRECTORY_KEYS = ['odd_even', 'filename', 'size', 'content_type', 'content_encoding']
DIRECTORY_KEYS = ['odd_even', 'filename', 'size', 'last_modified', 'content_type', 'content_encoding']
HREF_NAME_PATTERN = re.compile(r'href="(.+?)">(.+?)<')

# For JobsView
Expand Down
6 changes: 3 additions & 3 deletions scrapydweb/views/dashboard/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
NOT_DELETED = '0'
DELETED = '1'
HREF_PATTERN = re.compile(r"""href=['"](.+?)['"]""") # Temp support for Scrapyd v1.3.0 (not released)
# See also scrapydweb/utils/poll.py
JOB_PATTERN = re.compile(r"""
<tr>\s*
<td>(?P<Project>.*?)</td>\s*
Expand Down Expand Up @@ -426,10 +427,9 @@
))
return

self.finished_jobs.sort(key=lambda x: (x['finish'], x['start']), reverse=True) # Finished DESC
if self.JOBS_FINISHED_JOBS_LIMIT > 0:
self.finished_jobs = self.finished_jobs[::-1][:self.JOBS_FINISHED_JOBS_LIMIT]
else:
self.finished_jobs = self.finished_jobs[::-1]
self.finished_jobs = self.finished_jobs[:self.JOBS_FINISHED_JOBS_LIMIT]

Check warning on line 432 in scrapydweb/views/dashboard/jobs.py

View check run for this annotation

Codecov / codecov/patch

scrapydweb/views/dashboard/jobs.py#L432

Added line #L432 was not covered by tests
self.kwargs.update(dict(
colspan=14,
url_jobs_database=url_for('jobs', node=self.node, style='database'),
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"idna==2.7", # Jun 11, 2018
"itsdangerous==2.0.0", # May 12, 2021
"Jinja2==3.0.0", # May 12, 2021
"logparser==0.8.2",
"logparser>=0.8.4",
"MarkupSafe==2.0.0", # May 12, 2021
"pexpect==4.7.0", # Apr 7, 2019
"ptyprocess==0.6.0", # Jun 22, 2018
Expand Down Expand Up @@ -71,5 +71,6 @@
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
)
24 changes: 16 additions & 8 deletions tests/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,29 @@ def test_run(app, client):
kws=dict(node=node, opt='forcestop', project=cst.PROJECT, version_spider_job=cst.JOBID))
sleep()
__, js = req(app, client, view='api', kws=dict(node=node, opt='listjobs', project=cst.PROJECT))
# Note that finished jobs are DESC in scrapyd v1.5.0
js['finished'].sort(key=lambda x: x['end_time'], reverse=False)
last_but_two_finished_job = js['finished'][-2]
last_but_two_finished_job_start = last_but_two_finished_job['start_time'][:19]
last_finished_job = js['finished'][-1]
last_finished_job_start = last_finished_job['start_time'][:19]
assert last_but_two_finished_job['id'] == last_finished_job['id'] == cst.JOBID
# Ignore seen finished job: ScrapydWeb_demo/test/2018-01-01T01_01_02, started at 2019-03-01 20:27:22
flash = "Ignore seen finished job: %s, started at %s" % (KEY, last_but_two_finished_job_start)
req(app, client, view='jobs', kws=dict(node=node, style='database'),
ins=[flash, "Vue.extend(Main)", "start: '%s'," % last_finished_job_start],
nos=['class="table wrap"', "start: '%s'," % last_but_two_finished_job_start])
# flash only once
req(app, client, view='jobs', kws=dict(node=node, style='database'),
ins=["Vue.extend(Main)", "start: '%s'," % last_finished_job_start],
nos=[flash, 'class="table wrap"', "start: '%s'," % last_but_two_finished_job_start])

# TODO: It's a temp workaround for scrapyd > '1.4.3'
try:
req(app, client, view='jobs', kws=dict(node=node, style='database'),
ins=["Vue.extend(Main)", "start: '%s'," % last_finished_job_start, flash],
nos=['class="table wrap"', "start: '%s'," % last_but_two_finished_job_start])
# flash only once
req(app, client, view='jobs', kws=dict(node=node, style='database'),
ins=["Vue.extend(Main)", "start: '%s'," % last_finished_job_start],
nos=[flash, 'class="table wrap"', "start: '%s'," % last_but_two_finished_job_start])
except AssertionError as err:
from scrapyd import version_info
scrapyd_version = '.'.join(version_info)
if scrapyd_version > '1.4.3':
print("Temp ignore error for scrapyd %s: %s" % (scrapyd_version, err))

# Note that in LogParser is enabled in test_enable_logparser(), with PARSE_ROUND_INTERVAL defaults to 10.
# And LOGSTATS_INTERVAL is set to 10 in test_check() above.
Expand Down
Loading