Skip to content

Commit 2cbf023

Browse files
authored
Merge pull request #2 from adamcupial/issue/1
Issue #1
2 parents ab41c87 + 93a0c25 commit 2cbf023

File tree

4 files changed

+52
-17
lines changed

4 files changed

+52
-17
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
All notable changes to this project will be documented in this file.
3+
4+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
## [Unreleased]
8+
-
9+
10+
## [1.0.1] - 2019-02-14
11+
### Changed
12+
- When error occurs during run the process should be stopped (issue #1)
13+
- Added changelog
14+
15+
## [1.0.0] - 2019-02-05
16+
### Added
17+
- Base runner
18+
19+
[Unreleased]: https://github.com/adamcupial/lighthouse-python/compare/1.0.1...HEAD
20+
[1.0.1]: https://github.com/adamcupial/lighthouse-python/compare/1.0.0...1.0.1

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
This library is a simple wrapper around lighthouse-cli runner that runs the audit and parses a result in friendly manner.
55

66
## Installation
7+
if lighthouse is not installed:
8+
```bash
9+
npm install -g lighthouse
10+
```
11+
712
```bash
813
pip install git+https://github.com/adamcupial/lighthouse-python.git#egg=lighthouse
914
```
@@ -26,4 +31,7 @@ report has 3 properties:
2631

2732
## Dependencies
2833
- python 2.7+
29-
- lighthouse installed
34+
- node package lighthouse installed
35+
36+
## Changes
37+
[You can find all changes in CHANGELOG!](CHANGELOG.md)

lighthouse/runner.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,34 @@ def __init__(self, url, form_factor='mobile', quiet=True):
2828
default is True
2929
"""
3030

31+
assert form_factor in ['mobile', 'desktop']
32+
3133
_, self.__report_path = tempfile.mkstemp(suffix='.json')
3234
self._run(url, form_factor, quiet)
3335
self.report = self._get_report()
3436
self._clean()
3537

3638
def _run(self, url, form_factor, quiet):
37-
subprocess.call([
38-
'lighthouse',
39-
url,
40-
'--quiet' if quiet else '',
41-
'--chrome-flags',
42-
'"--headless"',
43-
'--preset',
44-
'full',
45-
'--emulated-form-factor',
46-
form_factor,
47-
'--output',
48-
'json',
49-
'--output-path',
50-
'{0}'.format(self.__report_path),
51-
])
39+
report_path = self.__report_path
40+
41+
try:
42+
subprocess.check_call(' '.join([
43+
'lighthouse',
44+
url,
45+
'--quiet' if quiet else '',
46+
'--chrome-flags="--headless"',
47+
'--preset=full',
48+
'--emulated-form-factor={0}'.format(form_factor),
49+
'--output=json',
50+
'--output-path={0}'.format(report_path),
51+
]), shell=True)
52+
except subprocess.CalledProcessError as exc:
53+
msg = '''
54+
Command "{0}"
55+
returned an error code: {1},
56+
output: {2}
57+
'''.format(exc.cmd, exc.returncode, exc.output)
58+
raise RuntimeError(msg)
5259

5360
def _get_report(self):
5461
with open(self.__report_path, 'r') as fil:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='lighthouse',
7-
version='1.0',
7+
version='1.0.1',
88
description='Lightouse runner',
99
author='Adam Cupiał',
1010
author_email='cupial.adam@gmail.com',

0 commit comments

Comments
 (0)