Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
python plugin: do the right thing with classic. #1093
Conversation
This was referenced Jan 30, 2017
battlemidget
commented
Jan 30, 2017
|
Will this allow a successful installation of snaps on trusty as well? |
|
@battlemidget yes; there is only one last thing for trusty support being tracked on https://bugs.launchpad.net/bugs/1657504 There is however one last issue involving core on comment https://bugs.launchpad.net/snapd/+bug/1657504/comments/15 For classic, you will need to provide an interpreter, a quick way is like name: asciinema
version: '1.3.0'
summary: Record and share your terminal sessions, the right way.
description: |
Forget screen recording apps and blurry video. Enjoy a lightweight,
purely text-based approach to terminal recording.
grade: devel
confinement: classic
apps:
asciinema:
command: bin/asciinema
parts:
asciinema:
plugin: python
python-packages: [$SNAPCRAFT_PROJECT_NAME==$SNAPCRAFT_PROJECT_VERSION]
after: [python3]
python3:
source: https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
plugin: autotools
configflags: [--prefix=/usr]
build-packages: [libssl-dev] |
| + # binaries are linked with `nodefaultlib` but we still do | ||
| + # not want to leak PATH or other environment variables | ||
| + # that would affect the applications view of the classic | ||
| + # environment it is dropped into. | ||
| replace_path = r'{}/[a-z0-9][a-z0-9+-]*/install'.format( | ||
| self._parts_dir) |
chipaca
Jan 30, 2017
Member
has _parts_dir been sanitized to not have regexpish things in it? otherwise you want re.escape(self._parts_dir) here
| + '$LD_LIBRARY_PATH\n') | ||
| + if cwd: | ||
| + f.write('{}\n'.format(cwd)) | ||
| + f.write('exec {} {}\n'.format(executable, args)) |
| package_dir=self._python_package_dir, env=env, | ||
| extra_install_args=['--ignore-installed']) | ||
| if download: | ||
| pip.download(args) | ||
| - pip.wheel(args) | ||
| + # pip.wheel(args) |
sergiusens
Jan 30, 2017
Collaborator
yeah, already removed locally, didn't want to stress the weak infra ;-)
kyrofa
requested changes
Jan 31, 2017
This looks mostly good to me. I'll be honest and say I'm not familiar with the site package fiddling we're doing here, but I looked into it and it seems sane. I have a few niggly comments, the bigger one is the shutil.which() duplication that's happening here. In addition to not being sure if it's necessary, I'm worried about naming confusion.
| replace_path = r'{}/[a-z0-9][a-z0-9+-]*/install'.format( | ||
| - self._parts_dir) | ||
| - assembled_env = re.sub(replace_path, '$SNAP', assembled_env) | ||
| + re.escape(self._parts_dir)) |
| + '$LD_LIBRARY_PATH', file=f) | ||
| + if cwd: | ||
| + print('{}'.format(cwd), file=f) | ||
| + print('exec {} {}'.format(executable, args), file=f) |
kyrofa
Jan 31, 2017
Member
Why not just collect all the lines in a list and finally f.write('\n'.join(lines)) at the end?
| args = ['pip', 'setuptools', 'wheel'] | ||
| + pip_command = [self._get_python_command(), '-m', 'pip'] | ||
| + | ||
| + # if python_command it is not from stage we don't have pip |
kyrofa
Jan 31, 2017
Member
s/if python_command it is/if python_command is/. Although from the comment I'm not sure how that relates to the setting of PYTHONHOME.
| + | ||
| + env['PATH'] = '{}:{}'.format( | ||
| + os.path.join(self.installdir, 'usr', 'bin'), | ||
| + os.path.expandvars('$PATH')) |
| +from snapcraft.internal import common | ||
| + | ||
| + | ||
| +def which(command, **kwargs): |
kyrofa
Jan 31, 2017
Member
Why not use the real shutil.which() with assemble_env()'s PATH? If we want to keep this, can we name the file something else? I'm afraid shutil will cause confusion later.
battlemidget
commented
Feb 1, 2017
•
|
I attempted to get my conjure-up snap working with this branch on trusty. This is the packaged snap contents of that: http://paste.ubuntu.com/23907436/ I was able to install without an issue this time, however, here is the error i received:
which goes inline with the contents of the snap. On a plus though, my original issue with the systemd services not being installed have been resolved \o/ For reference here is my snapcraft im using https://github.com/conjure-up/conjure-up/blob/master/snap/snapcraft.yaml Update After adding the python part the build succeeded, however, I am getting another error when trying to start the systemd service:
|
sergiusens
added some commits
Jan 26, 2017
battlemidget
commented
Feb 2, 2017
|
I've successfully tested this branch and was able to build https://github.com/conjure-up/conjure-up on Trusty with huge success. |
| + else: | ||
| + assembled_env = common.assemble_env() | ||
| + assembled_env = assembled_env.replace(self._snap_dir, '$SNAP') | ||
| + assembled_env = re.sub(replace_path, '$SNAP', assembled_env) |
sergiusens
Feb 2, 2017
Collaborator
ah, you should of been more specific; the current mechanism works though :-P
| + | ||
| + if shebang: | ||
| + if shebang.startswith('/usr/bin/env '): | ||
| + shebang = shell_utils.which(shebang.split()[1]) | ||
| new_shebang = re.sub(replace_path, '$SNAP', shebang) |
| + # If python_command it is not from stage we don't have pip, which means | ||
| + # we are going to need to resort to the pip installed on the system | ||
| + # that came from build-packages. This shouldn't be a problem as | ||
| + # stage-packages and build-packages should match. |
sergiusens commentedJan 30, 2017
To fully enable classic confinment for python based snaps, there are
two big things that need to get done; no env var leaking and
use a python interpreter with the classic compilation flags.
LP: #1657504
Signed-off-by: Sergio Schvezov sergio.schvezov@canonical.com