Python plugin improvements #771

Merged
merged 34 commits into from Sep 7, 2016

Conversation

Projects
None yet
4 participants
Collaborator

sergiusens commented Aug 31, 2016

The unit tests still need updating, what do people think about this approach?

The demos still work btw.

sergiusens added some commits Aug 31, 2016

python3: make use of PYTHONUSERBASE
Signed-off-by: Sergio Schvezov <sergio.schvezov@ubuntu.com>
Merge branch 'python-plugin-improvements' of github.com:sergiusens/sn…
…apcraft into python-plugin-improvements
Merge branch 'python-plugin-improvements' of github.com:sergiusens/sn…
…apcraft into python-plugin-improvements
snapcraft/plugins/python2.py
logger = logging.getLogger(__name__)
-class Python2Plugin(snapcraft.BasePlugin):
+class Python2Plugin(python3.Python3Plugin):
@elopio

elopio Sep 1, 2016

Member

this is not a great idea, conceptually. Python3 is not a parent of python2, so inheritance could cause problems in the future. A better approach might be to make a common BasePythonPlugin, and inherit both Python2 and Python3 plugins from it.

@kyrofa

kyrofa Sep 1, 2016

Member

+1, agreed.

@sergiusens

sergiusens Sep 1, 2016

Collaborator

and where would BasePythonPlugin live? in the python3 module or the python2 one?

@elopio

elopio Sep 1, 2016

Member

neither. In a common module.

@sergiusens

sergiusens Sep 1, 2016

Collaborator

El 01/09/16 a las 11:04, Leo Arias escribió:

In snapcraft/plugins/python2.py
#771 (comment):

logger = logging.getLogger(name)

-class Python2Plugin(snapcraft.BasePlugin):
+class Python2Plugin(python3.Python3Plugin):

neither. In a common module.

I don't know, this gives the plugins we write special treatment, this
module would have to be a plugin as well and we risk having a useless
plugin like the jdk one.

sergiusens added some commits Sep 1, 2016

snapcraft/_baseplugin.py
@@ -237,17 +237,15 @@ 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:
@elopio

elopio Sep 1, 2016

Member

you can just remove the if True, and leave the print for now.

@sergiusens

sergiusens Sep 1, 2016

Collaborator

yeah, sounds good

snapcraft/plugins/python.py
+"""The python plugin can be used for python 2 or 3 based parts.
+
+The python plugin can be used for python projects where you would
+want to do:
@elopio

elopio Sep 1, 2016

Member

s/The python plugin/It

snapcraft/plugins/python.py
+ 'python-setuptools',
+ ]
+ else:
+ return []
@elopio

elopio Sep 1, 2016

Member

raise an exception? This should never happen.
Now this is a good use for assert :p

+ }
+ schema['properties']['python-version'] = {
+ 'type': 'string',
+ 'default': 'python3',
@elopio

elopio Sep 1, 2016

Member

is there a way to enforce the two valid values?

@sergiusens

sergiusens Sep 1, 2016

Collaborator

El 01/09/16 a las 12:56, Leo Arias escribió:

In snapcraft/plugins/python.py
#771 (comment):

  •    schema['properties']['python-packages'] = {
    
  •        'type': 'array',
    
  •        'minitems': 1,
    
  •        'uniqueItems': True,
    
  •        'items': {
    
  •            'type': 'string'
    
  •        },
    
  •        'default': [],
    
  •    }
    
  •    schema['properties']['process-dependency-links'] = {
    
  •        'type': 'boolean',
    
  •        'default': False,
    
  •    }
    
  •    schema['properties']['python-version'] = {
    
  •        'type': 'string',
    
  •        'default': 'python3',
    

is there a way to enforce the two valid values?

yes I added an enum

+ 'constraints',
+ 'python-packages',
+ 'python-version',
+ ])
@elopio

elopio Sep 1, 2016

Member

What about the build properties?
I'm not sure how does this work. If the pull properties are changed, and snapcraft build is executed, will it run pull again?

@sergiusens

sergiusens Sep 1, 2016

Collaborator

@kyrofa why was build-properties not originally added here?

snapcraft/plugins/python.py
+ elif self.options.python_version == 'python2':
+ return ['python2']
+ else:
+ return []
@elopio

elopio Sep 1, 2016

Member

this too should never happen

@@ -1,6 +1,6 @@
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
#
-# Copyright (C) 2015 Canonical Ltd
+# Copyright (C) 2015-2016 Canonical Ltd
@elopio

elopio Sep 1, 2016

Member

2015, 2016

@sergiusens

sergiusens Sep 1, 2016

Collaborator

El 01/09/16 a las 13:01, Leo Arias escribió:

In snapcraft/plugins/python3.py
#771 (comment):

@@ -1,6 +1,6 @@

-- Mode:Python; indent-tabs-mode:nil; tab-width:4 --

-# Copyright (C) 2015 Canonical Ltd
+# Copyright (C) 2015-2016 Canonical Ltd

2015, 2016

we already had this discussion ;-)

@elopio

elopio Sep 1, 2016

Member

yes, and as far as I remember, I won ^_^

@@ -16,6 +16,8 @@
"""The python3 plugin can be used for python 3 based parts.
+This plugin is DEPRECATED in favor of the python plugin.
@elopio

elopio Sep 1, 2016

Member

print a deprecation warning when it's used?

snapcraft/plugins/python2.py
return schema
def __init__(self, name, options, project):
+ setattr(options, 'python_version', 'python2')
@elopio

elopio Sep 1, 2016

Member

why setattr instead of options.python_version = ... ?

@sergiusens

sergiusens Sep 1, 2016

Collaborator

Because it doesn't exist, options gets created from the plugin's schema

Member

elopio commented Sep 1, 2016

oh, yes! /me approves.

sergiusens added some commits Sep 1, 2016

snapcraft/plugins/python.py
+ elif self.options.python_version == 'python2':
+ return ['python']
+ else:
+ raise AssertionError('python-version has a value of {!r}'.format(
@SamYaple

SamYaple Sep 1, 2016

Contributor

no reason to do this. just don't pop 'required' from the options schema. enforce the requirement of python_version (and specific values with enum so we dont have to validate it either)

@elopio

elopio Sep 1, 2016

Member

yup, and this could be a dictionary. return self._python_stage_packages[self.options.python_version]

Then an exception would be raised anyway if there is a programmer error somewhere.

@sergiusens

sergiusens Sep 1, 2016

Collaborator

the problem is on inheritance. Adding the schema makes the option visible to the python2 and python3 plugins

@sergiusens

sergiusens Sep 1, 2016

Collaborator

IOW this is here more for the children than the parent itself

@SamYaple

SamYaple Sep 3, 2016

Contributor

Hmmm. I suppose schema could be added to the children too if that a problem.

I just don't like the idea of checking python versions in multiple places. Perhaps abstract the else to another function so we don't have to change exceptions in multiple places should this need to be handled differently in the future? (I'm seeing potential uses for python3.4 vs python3.5 maybe). I just don't like violating DRY in this way.

@sergiusens

sergiusens Sep 5, 2016

Collaborator

Seems like something that can be decorated.

Member

elopio commented Sep 1, 2016

I think this is very good. I left some minor ignorable comments, so you'll have my +1...
after you add an integration test running the prime command on a snap with "plugin: python" 😆

Contributor

SamYaple commented Sep 1, 2016

You beat me to it! Glad you also like the approach of python2 and python3 inheriting a 'python' plugin for deprecation. I could think of no other way to do it

sergiusens added some commits Sep 1, 2016

Collaborator

sergiusens commented Sep 2, 2016

LP: #1616032

@sergiusens sergiusens self-assigned this Sep 2, 2016

sergiusens added some commits Sep 3, 2016

be less strict about pythonness
Signed-off-by: Sergio Schvezov <sergio.schvezov@ubuntu.com>
Collaborator

sergiusens commented Sep 6, 2016

LP: #1616407

Collaborator

sergiusens commented Sep 6, 2016

LP: #1606894

Collaborator

sergiusens commented Sep 6, 2016

LP: #1602079

Collaborator

sergiusens commented Sep 6, 2016

retest this please

Collaborator

sergiusens commented Sep 6, 2016

LP: #1594809

Collaborator

sergiusens commented Sep 6, 2016

retest this please

Collaborator

sergiusens commented Sep 6, 2016

LP: #1607297

snapcraft/plugins/python.py
@@ -235,3 +245,16 @@ def snap_fileset(self):
elif self.options.python_version == 'python2':
fileset.append('-**/*.pyc')
return fileset
+
+
+def _replicate_owner_mode(path):
@elopio

elopio Sep 7, 2016

Member

would you mind explaining in a docstring what is this doing?

Contributor

SamYaple commented Sep 7, 2016

Merge merge merge 👍

Patchset looks good. I have been using it exclusively for a few days now. Possibly some docs/testing stuff that is needed, but functionally it is solid.

Member

elopio commented Sep 7, 2016

when trying to snap integration_tests/snaps/pip-requirements-list, it results in a conflict with bin/jsonschema. This is known, right? It's part of the change you commented in the mailing list about entry points?

Collaborator

sergiusens commented Sep 7, 2016

El 07/09/16 a las 00:32, Leo Arias escribió:

when trying to snap integration_tests/snaps/pip-requirements-list, it
results in a conflict with bin/jsonschema. This is known, right? It's
part of the change you commented in the mailing list about entry points?

There is a fileset the takes this into account, integration tests pass,
so I don't see what the problem is. This means entry point work now btw!

Collaborator

sergiusens commented Sep 7, 2016

LP: #1619104

@sergiusens sergiusens merged commit bb7bd40 into snapcore:master Sep 7, 2016

4 checks passed

autopkgtest integration Success
Details
autopkgtest snaps Success
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.005%) to 97.908%
Details

@sergiusens sergiusens deleted the sergiusens:python-plugin-improvements branch Sep 7, 2016

kalikiana pushed a commit to kalikiana/snapcraft that referenced this pull request Apr 6, 2017

Python plugin improvements (#771)
LP: #1594809
LP: #1602079
LP: #1606894
LP: #1607297
LP: #1616407
LP: #1619104

Signed-off-by: Sergio Schvezov <sergio.schvezov@ubuntu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment