Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Python{2,3} plugins: Make site-packages link relative. #169
Merged
sergiusens
merged 1 commit into
snapcore:master
from
kyrofa:bugfix/1523384/make_site_packages_relative_link
Dec 18, 2015
Jump to file or symbol
Failed to load files and symbols.
| @@ -97,11 +97,11 @@ def _pip(self): | ||
| site_packages_dir = os.path.join( | ||
| prefix, 'lib', self.python_version, 'site-packages') | ||
| + # If site-packages doesn't exist, make sure it points to the | ||
| + # dist-packages in the same directory (this is a relative link so that | ||
| + # it's still valid when the .snap is installed). | ||
| if not os.path.exists(site_packages_dir): | ||
| - os.symlink( | ||
| - os.path.join(prefix, 'lib', self.python_version, | ||
| - 'dist-packages'), | ||
| - site_packages_dir) | ||
| + os.symlink('dist-packages', site_packages_dir) | ||
kyrofa
Member
|
||
| self.run(['python2', easy_install, '--prefix', prefix, 'pip']) | ||
| @@ -0,0 +1,55 @@ | ||
| +# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
| +# | ||
| +# Copyright (C) 2015 Canonical Ltd | ||
| +# | ||
| +# This program is free software: you can redistribute it and/or modify | ||
| +# it under the terms of the GNU General Public License version 3 as | ||
| +# published by the Free Software Foundation. | ||
| +# | ||
| +# This program is distributed in the hope that it will be useful, | ||
| +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| +# GNU General Public License for more details. | ||
| +# | ||
| +# 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 os | ||
| + | ||
| +from unittest import mock | ||
| + | ||
| +from snapcraft import tests | ||
| +from snapcraft.plugins import python2 | ||
| + | ||
| + | ||
| +class Python2PluginTestCase(tests.TestCase): | ||
| + | ||
| + def setUp(self): | ||
| + super().setUp() | ||
| + | ||
| + class Options: | ||
| + requirements = '' | ||
| + python_packages = [] | ||
| + | ||
| + self.options = Options() | ||
| + | ||
| + @mock.patch.object(python2.Python2Plugin, 'run') | ||
| + @mock.patch.object(python2.Python2Plugin, 'run_output', | ||
| + return_value='python2.7') | ||
| + def test_pip_relative_site_packages_symlink(self, run_output_mock, | ||
| + run_mock): | ||
| + plugin = python2.Python2Plugin('test-part', self.options) | ||
| + os.makedirs(plugin.sourcedir) | ||
| + os.makedirs(os.path.join(plugin.installdir, 'usr', 'lib', 'python2.7', | ||
| + 'dist-packages')) | ||
| + | ||
| + open(os.path.join(plugin.sourcedir, 'setup.py'), 'w').close() | ||
| + | ||
| + plugin._pip() | ||
| + | ||
| + link = os.readlink(os.path.join(plugin.installdir, 'usr', 'lib', | ||
| + 'python2.7', 'site-packages')) | ||
| + self.assertEqual(link, 'dist-packages', | ||
| + 'Expected site-packages to be a relative link to ' | ||
| + '"dist-packages", but it was a link to "{}"' | ||
| + .format(link)) |
| @@ -0,0 +1,57 @@ | ||
| +# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
| +# | ||
| +# Copyright (C) 2015 Canonical Ltd | ||
| +# | ||
| +# This program is free software: you can redistribute it and/or modify | ||
| +# it under the terms of the GNU General Public License version 3 as | ||
| +# published by the Free Software Foundation. | ||
| +# | ||
| +# This program is distributed in the hope that it will be useful, | ||
| +# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| +# GNU General Public License for more details. | ||
| +# | ||
| +# 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 os | ||
| + | ||
| +from unittest import mock | ||
| + | ||
| +from snapcraft import tests | ||
| +from snapcraft.plugins import python3 | ||
| + | ||
| + | ||
| +class Python3PluginTestCase(tests.TestCase): | ||
| + | ||
| + def setUp(self): | ||
| + super().setUp() | ||
| + | ||
| + class Options: | ||
| + requirements = '' | ||
| + python_packages = [] | ||
| + | ||
| + self.options = Options() | ||
| + | ||
| + @mock.patch.object(python3.Python3Plugin, 'run') | ||
| + @mock.patch.object(python3.Python3Plugin, 'run_output', | ||
| + return_value='python3.4') | ||
| + def test_pip_relative_site_packages_symlink(self, run_output_mock, | ||
| + run_mock): | ||
| + plugin = python3.Python3Plugin('test-part', self.options) | ||
| + os.makedirs(plugin.sourcedir) | ||
| + os.makedirs(os.path.join(plugin.installdir, 'usr', 'lib', 'python3.4')) | ||
| + os.makedirs(os.path.join(plugin.installdir, 'usr', 'lib', 'python3', | ||
| + 'dist-packages')) | ||
| + | ||
| + open(os.path.join(plugin.sourcedir, 'setup.py'), 'w').close() | ||
| + | ||
| + plugin._pip() | ||
| + | ||
| + link = os.readlink(os.path.join(plugin.installdir, 'usr', 'lib', | ||
| + 'python3.4', 'site-packages')) | ||
| + expected = os.path.join('..', 'python3', 'dist-packages') | ||
| + self.assertEqual(link, expected, | ||
| + 'Expected site-packages to be a relative link to ' | ||
| + '"{}", but it was a link to "{}"'.format(expected, | ||
| + link)) |
Should we do the same for python3?