~longsleep/snapcraft/snapcraft-debs-plugin

« back to all changes in this revision

Viewing changes to snapcraft/plugins/python2.py

  • Committer: Snappy Tarmac
  • Author(s): Sergio Schvezov
  • Date: 2015-10-26 15:25:06 UTC
  • mfrom: (250.2.4 work)
  • Revision ID: snappy_tarmac-20151026152506-7hqsn1kftvqcuncl
Plugins raise exception instead of true/false by sergiusens approved by elopio

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
            root, 'usr', 'lib', self.python_version, 'dist-packages')]
46
46
 
47
47
    def pull(self):
48
 
        if not super().pull():
49
 
            return False
50
 
 
51
 
        return self._pip()
 
48
        super().pull()
 
49
        self._pip()
52
50
 
53
51
    def _pip(self):
54
52
        setup = 'setup.py'
59
57
            requirements = os.path.join(os.getcwd(), self.options.requirements)
60
58
 
61
59
        if not os.path.exists(setup) and not self.options.requirements:
62
 
            return True
 
60
            return
63
61
 
64
62
        easy_install = os.path.join(
65
63
            self.installdir, 'usr', 'bin', 'easy_install')
73
71
                             'dist-packages'),
74
72
                site_packages_dir)
75
73
 
76
 
        if not self.run(['python2', easy_install, '--prefix', prefix, 'pip']):
77
 
            return False
 
74
        self.run(['python2', easy_install, '--prefix', prefix, 'pip'])
78
75
 
79
76
        pip2 = os.path.join(self.installdir, 'usr', 'bin', 'pip2')
80
77
        pip_install = ['python2', pip2, 'install', '--target',
81
78
                       site_packages_dir]
82
79
 
83
 
        if self.options.requirements and not self.run(
84
 
                pip_install + ['--requirement', requirements]):
85
 
            return False
86
 
 
87
 
        if os.path.exists(setup) and not self.run(pip_install + ['.', ]):
88
 
            return False
89
 
 
90
 
        return True
 
80
        if self.options.requirements:
 
81
            self.run(pip_install + ['--requirement', requirements])
 
82
 
 
83
        if os.path.exists(setup):
 
84
            self.run(pip_install + ['.', ])
91
85
 
92
86
    def build(self):
93
87
        # If setuptools is used, it tries to create files in the
96
90
        # used.
97
91
 
98
92
        if not os.path.exists(os.path.join(self.builddir, 'setup.py')):
99
 
            return True
 
93
            return
100
94
 
101
95
        os.makedirs(self.dist_packages_dir, exist_ok=True)
102
96
        setuptemp = self.copy_setup()
103
 
        return self.run(
 
97
        self.run(
104
98
            ['python2', setuptemp.name, 'install', '--install-layout=deb',
105
99
             '--prefix={}/usr'.format(self.installdir)], cwd=self.builddir)
106
100