Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python plugin improvements #771

Merged
merged 34 commits into from Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
266bcc8
python3: make use of PYTHONUSERBASE
sergiusens Aug 31, 2016
1b6deb9
consolidate plugins
sergiusens Aug 31, 2016
c694348
Merge branch 'master' into python-plugin-improvements
sergiusens Aug 31, 2016
cbfa8a3
nicer additions
sergiusens Aug 31, 2016
e2202b4
Merge branch 'python-plugin-improvements' of github.com:sergiusens/sn…
sergiusens Aug 31, 2016
950503c
Merge branch 'master' into python-plugin-improvements
sergiusens Aug 31, 2016
4ac78b3
Merge branch 'python-plugin-improvements' of github.com:sergiusens/sn…
sergiusens Aug 31, 2016
b48fd56
glob everywhere in the python integration tests
sergiusens Aug 31, 2016
822023a
always set PYTHONPATH
sergiusens Aug 31, 2016
3425d8a
make integration pass
sergiusens Aug 31, 2016
e6a176b
moar fixes
sergiusens Aug 31, 2016
467d84f
units
sergiusens Sep 1, 2016
1ba2e1e
Merge branch 'master' into python-plugin-improvements
sergiusens Sep 1, 2016
b9b7a15
static
sergiusens Sep 1, 2016
017b443
Merge branch 'python-plugin-improvements' of github.com:sergiusens/sn…
sergiusens Sep 1, 2016
8ce3941
Python.h
sergiusens Sep 1, 2016
e094ccc
baseplugin coverage
sergiusens Sep 1, 2016
42308e7
Merge branch 'master' into python-plugin-improvements
sergiusens Sep 1, 2016
fb9ecff
consolidate python plugins
sergiusens Sep 1, 2016
2360107
list plugins ftw
sergiusens Sep 1, 2016
4e77dfe
add enum
sergiusens Sep 1, 2016
3f6d73d
pull properties
sergiusens Sep 1, 2016
54749b8
no if True
sergiusens Sep 1, 2016
249cc83
assert
sergiusens Sep 1, 2016
11418de
staged
sergiusens Sep 1, 2016
88d07bf
text
sergiusens Sep 1, 2016
2a867a5
python cwd dir
sergiusens Sep 1, 2016
653c716
remove rogue print
sergiusens Sep 1, 2016
c269058
static
sergiusens Sep 1, 2016
70d9f7a
static
sergiusens Sep 1, 2016
8928976
use the python plugin
sergiusens Sep 1, 2016
7a49eb5
change modes
sergiusens Sep 3, 2016
98b06d2
be less strict about pythonness
sergiusens Sep 6, 2016
e8615e9
Merge branch 'master' into python-plugin-improvements
sergiusens Sep 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions integration_tests/snaps/python-entry-point/snapcraft.yaml
Expand Up @@ -12,3 +12,13 @@ parts:
python3-test:
plugin: python3
source: python3/

python-test:
plugin: python
source: python3/
organize:
bin/python3_test: bin/python_test
stage:
- -lib/python3.5/site-packages/pip*
- -lib/python3.5/site-packages/setuptools*
- -lib/python3.5/site-packages/wheel*
22 changes: 22 additions & 0 deletions integration_tests/snaps/python-with-stage-packages/snapcraft.yaml
@@ -0,0 +1,22 @@
name: python-with-stage-packages
version: 0
summary: this will install yamllint from pypi
description: |
Install yamllint from pypi but use pyyaml as a stage-packages entry.
confinement: strict
grade: devel

parts:
python2:
plugin: python2
stage-packages: [python-yaml]
python-packages: ['yamllint']
stage:
- -bin/yamllint
snap:
- -bin/yamllint

python3:
plugin: python3
stage-packages: [python3-yaml]
python-packages: ['yamllint']
93 changes: 67 additions & 26 deletions integration_tests/test_python_plugin.py
Expand Up @@ -14,8 +14,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import glob
import os
from glob import glob

from testtools.matchers import (
DirExists,
Expand All @@ -31,38 +31,38 @@ def test_pull_with_pip_requirements_file(self):
project_dir = 'pip-requirements-file'
self.run_snapcraft('pull', project_dir)
self.assertThat(
os.path.join(
project_dir, 'parts', 'python2', 'install', 'usr', 'lib',
'python2.7', 'argparse.py'),
glob(os.path.join(
project_dir, 'parts', 'python2', 'install', 'lib',
'python2*', 'site-packages', 'argparse.py'))[0],
FileExists())
self.assertThat(
glob.glob(os.path.join(
project_dir, 'parts', 'python3', 'install', 'usr', 'lib',
'python3*', 'argparse.py'))[0],
glob(os.path.join(
project_dir, 'parts', 'python3', 'install', 'lib',
'python3*', 'site-packages', 'argparse.py'))[0],
FileExists())

def test_pull_with_pip_requirements_list(self):
project_dir = 'pip-requirements-list'
self.run_snapcraft('pull', project_dir)
self.assertThat(
os.path.join(
project_dir, 'parts', 'python2', 'install', 'usr', 'lib',
'python2.7', 'argparse.py'),
glob(os.path.join(
project_dir, 'parts', 'python2', 'install', 'lib',
'python2*', 'site-packages', 'argparse.py'))[0],
FileExists())
self.assertThat(
os.path.join(
project_dir, 'parts', 'python2', 'install', 'usr', 'lib',
'python2.7', 'dist-packages', 'jsonschema'),
glob(os.path.join(
project_dir, 'parts', 'python2', 'install', 'lib',
'python2*', 'site-packages', 'jsonschema'))[0],
DirExists())
self.assertThat(
glob.glob(os.path.join(
project_dir, 'parts', 'python3', 'install', 'usr', 'lib',
'python3*', 'argparse.py'))[0],
glob(os.path.join(
project_dir, 'parts', 'python3', 'install', 'lib',
'python3*', 'site-packages', 'argparse.py'))[0],
FileExists())
self.assertThat(
os.path.join(
project_dir, 'parts', 'python3', 'install', 'usr', 'lib',
'python3', 'dist-packages', 'jsonschema'),
glob(os.path.join(
project_dir, 'parts', 'python3', 'install', 'lib',
'python3*', 'site-packages', 'jsonschema'))[0],
DirExists())

def test_build_rewrites_shebangs(self):
Expand All @@ -71,17 +71,22 @@ def test_build_rewrites_shebangs(self):
project_dir = 'python-entry-point'
self.run_snapcraft('stage', project_dir)
python2_entry_point = os.path.join(
project_dir, 'stage', 'usr', 'bin', 'python2_test')
project_dir, 'stage', 'bin', 'python2_test')
python3_entry_point = os.path.join(
project_dir, 'stage', 'usr', 'bin', 'python3_test')
project_dir, 'stage', 'bin', 'python3_test')
python_entry_point = os.path.join(
project_dir, 'stage', 'bin', 'python_test')

with open(python2_entry_point) as f:
python2_shebang = f.readline().strip()
with open(python3_entry_point) as f:
python3_shebang = f.readline().strip()
with open(python_entry_point) as f:
python_shebang = f.readline().strip()

self.assertEqual('#!/usr/bin/env python2', python2_shebang)
self.assertEqual('#!/usr/bin/env python', python2_shebang)
self.assertEqual('#!/usr/bin/env python3', python3_shebang)
self.assertEqual('#!/usr/bin/env python3', python_shebang)

def test_build_does_not_keep_pyc_or_pth_files_in_install(self):
# .pyc and .pyc files collide between parts.
Expand All @@ -106,12 +111,48 @@ def test_build_doesnt_get_bad_install_directory_lp1586546(self):
project_dir = 'python-pyyaml'
self.run_snapcraft('stage', project_dir)
self.assertThat(
os.path.join(
glob(os.path.join(
project_dir, 'parts', 'python2', 'install', 'lib',
'python2*', 'site-packages', 'yaml'))[0],
DirExists())
self.assertThat(
glob(os.path.join(
project_dir, 'parts', 'python3', 'install', 'lib',
'python3*', 'site-packages', 'yaml'))[0],
DirExists())

def test_pypi_package_dep_satisfied_by_stage_package(self):
"""yamllint depends on yaml which is a stage-package."""
project_dir = 'python-with-stage-packages'
self.run_snapcraft('stage', project_dir)
self.assertThat(
glob(os.path.join(
project_dir, 'parts', 'python2', 'install', 'lib',
'python2*', 'site-packages', 'yamllint'))[0],
DirExists())
self.assertThat(
glob(os.path.join(
project_dir, 'parts', 'python2', 'install', 'usr', 'lib',
'python2.7', 'dist-packages', 'yaml'),
'python2*', 'dist-packages', 'yaml'))[0],
DirExists())
self.assertEqual(
glob(os.path.join(
project_dir, 'parts', 'python2', 'install', 'lib',
'python2*', 'site-packages', 'yaml')),
[])

self.assertThat(
glob(os.path.join(
project_dir, 'parts', 'python3', 'install', 'lib',
'python3*', 'site-packages', 'yamllint'))[0],
DirExists())
self.assertThat(
os.path.join(
glob(os.path.join(
project_dir, 'parts', 'python3', 'install', 'usr', 'lib',
'python3', 'dist-packages', 'yaml'),
'python3*', 'dist-packages', 'yaml'))[0],
DirExists())
self.assertEqual(
glob(os.path.join(
project_dir, 'parts', 'python3', 'install', 'lib',
'python3*', 'site-packages', 'yaml')),
[])
9 changes: 3 additions & 6 deletions snapcraft/_baseplugin.py
Expand Up @@ -237,17 +237,14 @@ def parallel_build_count(self):

# Helpers
def run(self, cmd, cwd=None, **kwargs):
if cwd is None:
if not cwd:
cwd = self.builddir
if True:
print(' '.join(cmd))
print(' '.join(cmd))
os.makedirs(cwd, exist_ok=True)
return common.run(cmd, cwd=cwd, **kwargs)

def run_output(self, cmd, cwd=None, **kwargs):
if cwd is None:
if not cwd:
cwd = self.builddir
if True:
print(' '.join(cmd))
os.makedirs(cwd, exist_ok=True)
return common.run_output(cmd, cwd=cwd, **kwargs)