Merge lp:~sergiusens/snapcraft/pypy-config-test into lp:~snappy-dev/snapcraft/core

Proposed by Sergio Schvezov on 2015-09-17
Status: Merged
Approved by: Leo Arias on 2015-09-17
Approved revision: 177
Merged at revision: 176
Proposed branch: lp:~sergiusens/snapcraft/pypy-config-test
Merge into: lp:~snappy-dev/snapcraft/core
Diff against target: 131 lines (+103/-0)
4 files modified
integration-tests/data/pypi-config/config.py (+57/-0)
integration-tests/data/pypi-config/setup.py (+16/-0)
integration-tests/data/pypi-config/snapcraft.yaml (+16/-0)
integration-tests/units/jobs.pxu (+14/-0)
To merge this branch: bzr merge lp:~sergiusens/snapcraft/pypy-config-test
Reviewer Review Type Date Requested Status
Leo Arias 2015-09-17 Approve on 2015-09-17
Review via email: mp+271529@code.launchpad.net

This proposal supersedes a proposal from 2015-09-17.

Commit Message

setup.py using pypy to setup a config integration test

To post a comment you must log in.
Leo Arias (elopio) wrote :

I find it a little confusing that the part is also called config. Not sure what to do about it. That's not required, right? You could define any name for the part?

The test passes and excercises the code, that's good.

+ test -f ./snap/meta/hooks/config

IMO, this check is not enough. The best test would be to try to configure the installed snap, but as we still have some things to figure out for that, it would be good to check that the config file contains the same line that was defined on the yaml.

Needs fixing to add a check for the content of snap/meta/hooks/config

review: Needs Fixing
176. By Sergio Schvezov on 2015-09-17

s/pypy/pypi/ and description and summary updated

177. By Sergio Schvezov on 2015-09-17

check hook

Leo Arias (elopio) wrote :

thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'integration-tests/data/pypi-config'
2=== added file 'integration-tests/data/pypi-config/config.py'
3--- integration-tests/data/pypi-config/config.py 1970-01-01 00:00:00 +0000
4+++ integration-tests/data/pypi-config/config.py 2015-09-17 20:34:40 +0000
5@@ -0,0 +1,57 @@
6+#!/usr/bin/env python3
7+
8+import os
9+import os.path
10+import sys
11+import yaml
12+
13+_CONFIG = 'configuration'
14+
15+_DEFAULT_INTERVAL = 10
16+
17+
18+def main():
19+ config_file = os.path.join(os.environ['SNAP_APP_DATA_PATH'], _CONFIG)
20+
21+ config_yaml = yaml.load(sys.stdin)
22+ if config_yaml:
23+ set_config(config_file, config_yaml)
24+
25+ yaml.dump(get_config(config_file), stream=sys.stdout, default_flow_style=False)
26+
27+
28+def set_config(config_file, config_yaml={}):
29+ with open(config_file, 'w') as f:
30+ yaml.dump(_config(config_yaml), stream=f, default_flow_style=False)
31+
32+ return config_yaml
33+
34+
35+def get_config(config_file):
36+ try:
37+ with open(config_file) as f:
38+ return yaml.load(f)
39+ except FileNotFoundError:
40+ return _config()
41+
42+
43+def _config(config_yaml={}):
44+ try:
45+ interval_value = config_yaml['config'][os.environ['SNAP_NAME']]['interval']
46+ if not isinstance(interval_value, int):
47+ config_yaml['config'][os.environ['SNAP_NAME']]['interval'] = _DEFAULT_INTERVAL
48+ except KeyError:
49+ interval = {
50+ 'config': {
51+ os.environ['SNAP_NAME']: {
52+ 'interval': _DEFAULT_INTERVAL
53+ }
54+ }
55+ }
56+ config_yaml.update(interval)
57+
58+ return config_yaml
59+
60+
61+if __name__ == '__main__':
62+ main()
63
64=== added file 'integration-tests/data/pypi-config/icon.png'
65Binary files integration-tests/data/pypi-config/icon.png 1970-01-01 00:00:00 +0000 and integration-tests/data/pypi-config/icon.png 2015-09-17 20:34:40 +0000 differ
66=== added file 'integration-tests/data/pypi-config/setup.py'
67--- integration-tests/data/pypi-config/setup.py 1970-01-01 00:00:00 +0000
68+++ integration-tests/data/pypi-config/setup.py 2015-09-17 20:34:40 +0000
69@@ -0,0 +1,16 @@
70+#!/usr/bin/env python3
71+
72+from setuptools import setup
73+
74+setup(
75+ name='config',
76+ description='config for webcam-webui',
77+ author='Sergio Schvezov <sergio.schvezov@canonical.com>',
78+ license='GPLv3',
79+ install_requires=[
80+ 'pyyaml',
81+ ],
82+ scripts=[
83+ 'config.py',
84+ ],
85+)
86
87=== added file 'integration-tests/data/pypi-config/snapcraft.yaml'
88--- integration-tests/data/pypi-config/snapcraft.yaml 1970-01-01 00:00:00 +0000
89+++ integration-tests/data/pypi-config/snapcraft.yaml 2015-09-17 20:34:40 +0000
90@@ -0,0 +1,16 @@
91+name: pypi-config
92+version: 1
93+vendor: Vendor <email@example.com>
94+summary: Create a snappy config hook using setup.py
95+description: |
96+ The object is to setup a snappy config hook to setup configuration based
97+ on python code.
98+
99+ This package will download its dependencies from pypi.
100+icon: icon.png
101+config: python3 usr/bin/config.py
102+
103+parts:
104+ config:
105+ type: python3-project
106+ source: .
107
108=== modified file 'integration-tests/units/jobs.pxu'
109--- integration-tests/units/jobs.pxu 2015-09-17 18:07:51 +0000
110+++ integration-tests/units/jobs.pxu 2015-09-17 20:34:40 +0000
111@@ -81,6 +81,20 @@
112 test -e stage/slash
113 test "$(./stage/bin/test)" = "tarproject"
114
115+id: snapcraft/normal/pypi-config
116+plugin: shell
117+estimated_duration: 0.3
118+command:
119+ set -ex
120+ cp -rT $PLAINBOX_PROVIDER_DATA/pypi-config .
121+ ${SNAPCRAFT} snap
122+ test -f ./stage/usr/bin/config.py
123+ test -f ./stage/usr/bin/python3
124+ test -f ./snap/usr/bin/config.py
125+ test -f ./snap/usr/bin/python3
126+ test -f ./snap/meta/hooks/config
127+ grep -q 'exec "python3" usr/bin/config.py $*' ./snap/meta/hooks/config
128+
129 id: snapcraft/normal/simple-make
130 plugin: shell
131 estimated_duration: 0.3

Subscribers

People subscribed via source and target branches