Skip to content
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

Add new "python_versions" attribute to the pack metadata file #4474

Merged
merged 20 commits into from
Jan 9, 2019

Conversation

Kami
Copy link
Member

@Kami Kami commented Dec 14, 2018

This pull request adds new python_version attribute to the pack metadata file.

This attribute uses semver notation to specify which Python versions pack works with (e.g. >= 2.7.0, <= 3.7.0).

The goal is to utilize this attribute for various things:

  1. On pack installation, check if to be installed pack is compatible with Python version under which StackStorm is running
  2. Advertise Python 2.x / Python 3.x compatibility on pack exchange
  3. Utilize this attribute in the pack CI - only runs tests and checks for Python version pack is compatible with and consider failures as fatal

Once we agree on the attribute "design", I / we will go and manually populate this field for various most commonly used pack based on manual and automated testing (StackStorm-Exchange/ci#61).

Related PR: StackStorm-Exchange/ci#61

Open Questions

I went with semver approach because we already use that for stackstorm_version attribute (consistency).

After more thought, I think it's too complicated - we could make it simpler by only advertising general python 2 and python 3 compatibility by adding {"python_versions": "python2": true, "python3": false} or similar attribute to pack metadata.

This attribute is different from stackstorm_version one - in StackStorm version case, you might want to specify different minor and patch versions and this should rarely be the case with Python version.

What do others think?

@Kami Kami added this to the 3.0.0 milestone Dec 14, 2018
@jeking3
Copy link

jeking3 commented Dec 17, 2018

Use semver - it's standard.

@lakshmi-kannan
Copy link
Contributor

Although semver is standard and which is what we use for st2 version, the python version really doesn't need the level of details. We are really interested in the python major versions. So something like "python_major_versions": [2, 3] is an option too.

@Kami
Copy link
Member Author

Kami commented Jan 8, 2019

@jeking3 Thanks for your input, but after more thinking about it, I agree with @lakshmi-kannan here.

semver is too complicated in this specific scenario. We only care about the major version (so Python 2.x or Python 3.x) and complex semver expression would just confuse end users and pack developers.

@Kami Kami changed the title [WIP] Add new "python_version" attribute to the pack metadata file Add new "python_versions" attribute to the pack metadata file Jan 8, 2019
@Kami
Copy link
Member Author

Kami commented Jan 8, 2019

Another thing worth noting - packs will only work with with Python 2.x and Python 3.x versions supported by the platform (aka StackStorm packages and components).

This means it makes no sense for pack to also specify Python version beyond the major one (aka also specifying minor and patch version).

Minor and patch versions will always be dictated by the platform.

Right now that is 2.7.x and 3.6.x. That means that packs which declare support for Python 2 are tested and work with Python 2.7.x and same goes for Python 3.

@Kami Kami added the python3 label Jan 8, 2019
Kami added 4 commits January 8, 2019 14:13
make it a list.

This attribute specifies which major Python versions the pack works with
(2, 3).

If this attribute is not specified in pack.yaml, we perform no Python
version compatibility check when installing and registering the pack.

The check can also be skipped by using --force install flag, but that
is at user's own risk and packs are not guaranteed to work.

Update affected tests.
@Kami
Copy link
Member Author

Kami commented Jan 8, 2019

I've pushed necessary changes which add new python_versions attribute which is a list (as discussed above).

Valid values for that field are "2", "3: and combination of those two. I made it a string, but if other think it makes more sense, I can also make it an integer (I didn't make it an integer because we will never do number like comparisons on it).

Copy link

@jeking3 jeking3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small comments.

@@ -100,6 +100,22 @@ class PackAPI(BaseAPI):
'">=1.8.0, <2.2.0"',
'pattern': ST2_VERSION_REGEX,
},
'python_versions': {
'type': 'array',
'description': ('Major Python versiosn supported by this pack. E.g. '
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo "versiosn".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will fix it.

'python_versions': {
'type': 'array',
'description': ('Major Python versiosn supported by this pack. E.g. '
'"2" for Python 2.7.x and "3" for Python 3.6.x'),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will change over time, is it wise to put the minor versions in here? I could see this getting stale.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned here (#4474 (comment)), the minor and patch version itself are dictated by the StackStorm platform and the packages we ship.

We could also store it here, but I don't think it would serve any good purpose - the information itself would be duplicated and provide no additional value, just potential confusion.

The idea is if you are using official StackStorm packages under Python 2 and pack metadata says it works under Python 2, it should work. Same goes for Python 3.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point was that the string on line 106 will become incorrect over time.

'maxItems': 2,
'uniqueItems': True,
'additionalItems': True
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the default for packs that do not specify it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't specify required=True which means it's an optional attribute. If it's not provided, we don't perform any checks during pack install and register phase (we just assume it works with the version under which StackStorm is currently running).

That's done for backward compatibility reasons.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why maxItems here? This means we have to update this code whenever a new major version of Python is released. Which, granted, doesn't happen all that often, but if packs want to specify a bunch of different values, I don't see how that is a problem.

'3'
]
},
'minItems': 1,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a default and minItems = 1 will this break all existing packs?

Copy link
Member Author

@Kami Kami Jan 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope - min items only applies to this attribute when it's provided. If the attribute itself is not provided, minItems validation check is not performed.

We also have various test cases which cover that scenarios (we have a lot of pack test fixtures without that attribute).

@Kami
Copy link
Member Author

Kami commented Jan 8, 2019

@jeking3 Thanks for taking a look and your feedback.

I pushed a fix for the typo and I believe I addressed all of your comments. If I missed something, please let me know.

'maxItems': 2,
'uniqueItems': True,
'additionalItems': True
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why maxItems here? This means we have to update this code whenever a new major version of Python is released. Which, granted, doesn't happen all that often, but if packs want to specify a bunch of different values, I don't see how that is a problem.

Copy link

@jeking3 jeking3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My issues were resolved and questions answered to satisfaction.

@Kami
Copy link
Member Author

Kami commented Jan 9, 2019

@blag Re maxItems - that's correct, but it doesn't happen often.

And if a new version of Python is released this means we will likely need to update our code and definitely update our packages since we bundle the virtualenv with Python interpreter inside the packages.

In short - if a new version for Python is released and some user wants to use it, we will need to update our code (packs CI, etc.) anyway and at that time we will update maxItems as well.

@Kami Kami merged commit 5872d6e into master Jan 9, 2019
@Kami Kami deleted the python_version_pack_metadata branch January 9, 2019 08:45
Kami added a commit that referenced this pull request Jan 9, 2019
@arm4b
Copy link
Member

arm4b commented Mar 26, 2019

@Kami Is this feature documented somewhere?
Couldn't find any references in st2docs.

@Kami
Copy link
Member Author

Kami commented Mar 26, 2019

@armab Not yet - feel free to create an issue and assign it for me. I will go to it in time for v3.0.0.


result = action.run(packs=['test3'], abs_repo_base=self.repo_base)
self.assertEqual(result['test3'], 'Success.')

# Pack requires a version which is not satisfied by current StackStorm version
st2common.util.pack_management.CURRENT_STACKSTROM_VERSION = '2.2.0'
st2common.util.pack_management.CURRENT_STACKSTORM_VERSION = '2.2.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is definitely a 100 and 1 way to misspell StormStack 😃

@arm4b
Copy link
Member

arm4b commented Mar 26, 2019

@Kami Sounds good, here we go StackStorm/st2docs#870

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants