-
Notifications
You must be signed in to change notification settings - Fork 441
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: do the right thing with classic. #1093
python plugin: do the right thing with classic. #1093
Conversation
Will this allow a successful installation of snaps on trusty as well? |
494b754
to
57d7255
Compare
@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] |
snapcraft/internal/meta.py
Outdated
# 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has _parts_dir
been sanitized to not have regexpish things in it? otherwise you want re.escape(self._parts_dir)
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is sanitized but good idea
snapcraft/plugins/python.py
Outdated
package_dir=self._python_package_dir, env=env, | ||
extra_install_args=['--ignore-installed']) | ||
|
||
if download: | ||
pip.download(args) | ||
pip.wheel(args) | ||
# pip.wheel(args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# leftover? Or ...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, already removed locally, didn't want to stress the weak infra ;-)
snapcraft/internal/meta.py
Outdated
'$LD_LIBRARY_PATH\n') | ||
if cwd: | ||
f.write('{}\n'.format(cwd)) | ||
f.write('exec {} {}\n'.format(executable, args)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your use of f.write
is entertaining :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change to print
😉
11469f6
to
e2f26c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
snapcraft/internal/meta.py
Outdated
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used a few times. re.compile()
might be a good idea.
'$LD_LIBRARY_PATH', file=f) | ||
if cwd: | ||
print('{}'.format(cwd), file=f) | ||
print('exec {} {}'.format(executable, args), file=f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just collect all the lines in a list and finally f.write('\n'.join(lines))
at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this boils down to personal preference, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it does. Feel free to ignore.
snapcraft/plugins/python.py
Outdated
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be clarified
|
||
env['PATH'] = '{}:{}'.format( | ||
os.path.join(self.installdir, 'usr', 'bin'), | ||
os.path.expandvars('$PATH')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I didn't know about os.path.expandvars()
, nice.
snapcraft/shutil.py
Outdated
from snapcraft.internal import common | ||
|
||
|
||
def which(command, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a common practice though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, we want the specific env to take precedence (PATH)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assembled_env
's PATH
is a list with multiple entries of PATH
b58e16c
to
73425ee
Compare
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:
|
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>
73425ee
to
9adcfb5
Compare
I've successfully tested this branch and was able to build https://github.com/conjure-up/conjure-up on Trusty with huge success. |
snapcraft/internal/meta.py
Outdated
else: | ||
assembled_env = common.assemble_env() | ||
assembled_env = assembled_env.replace(self._snap_dir, '$SNAP') | ||
assembled_env = re.sub(replace_path, '$SNAP', assembled_env) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want replace_path.sub('$SNAP', assembled_env)
here, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, you should of been more specific; the current mechanism works though :-P
snapcraft/internal/meta.py
Outdated
|
||
if shebang: | ||
if shebang.startswith('/usr/bin/env '): | ||
shebang = shell_utils.which(shebang.split()[1]) | ||
new_shebang = re.sub(replace_path, '$SNAP', shebang) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right here too.
snapcraft/plugins/python.py
Outdated
# 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thank you. Though the typo is still there: s/python_command it is not/python_command is not/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job on this, looks great!
To fully enable classic confinement 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>
To fully enable classic confinement 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>
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