Skip to content

Commit

Permalink
Merge pull request #2 from adamcupial/issue/1
Browse files Browse the repository at this point in the history
Issue #1
  • Loading branch information
adamcupial authored Feb 14, 2019
2 parents ab41c87 + 93a0c25 commit 2cbf023
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
-

## [1.0.1] - 2019-02-14
### Changed
- When error occurs during run the process should be stopped (issue #1)
- Added changelog

## [1.0.0] - 2019-02-05
### Added
- Base runner

[Unreleased]: https://github.com/adamcupial/lighthouse-python/compare/1.0.1...HEAD
[1.0.1]: https://github.com/adamcupial/lighthouse-python/compare/1.0.0...1.0.1
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
This library is a simple wrapper around lighthouse-cli runner that runs the audit and parses a result in friendly manner.

## Installation
if lighthouse is not installed:
```bash
npm install -g lighthouse
```

```bash
pip install git+https://github.com/adamcupial/lighthouse-python.git#egg=lighthouse
```
Expand All @@ -26,4 +31,7 @@ report has 3 properties:

## Dependencies
- python 2.7+
- lighthouse installed
- node package lighthouse installed

## Changes
[You can find all changes in CHANGELOG!](CHANGELOG.md)
37 changes: 22 additions & 15 deletions lighthouse/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,34 @@ def __init__(self, url, form_factor='mobile', quiet=True):
default is True
"""

assert form_factor in ['mobile', 'desktop']

_, self.__report_path = tempfile.mkstemp(suffix='.json')
self._run(url, form_factor, quiet)
self.report = self._get_report()
self._clean()

def _run(self, url, form_factor, quiet):
subprocess.call([
'lighthouse',
url,
'--quiet' if quiet else '',
'--chrome-flags',
'"--headless"',
'--preset',
'full',
'--emulated-form-factor',
form_factor,
'--output',
'json',
'--output-path',
'{0}'.format(self.__report_path),
])
report_path = self.__report_path

try:
subprocess.check_call(' '.join([
'lighthouse',
url,
'--quiet' if quiet else '',
'--chrome-flags="--headless"',
'--preset=full',
'--emulated-form-factor={0}'.format(form_factor),
'--output=json',
'--output-path={0}'.format(report_path),
]), shell=True)
except subprocess.CalledProcessError as exc:
msg = '''
Command "{0}"
returned an error code: {1},
output: {2}
'''.format(exc.cmd, exc.returncode, exc.output)
raise RuntimeError(msg)

def _get_report(self):
with open(self.__report_path, 'r') as fil:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='lighthouse',
version='1.0',
version='1.0.1',
description='Lightouse runner',
author='Adam Cupiał',
author_email='[email protected]',
Expand Down

0 comments on commit 2cbf023

Please sign in to comment.