Skip to content

add PEP-396 version attribute to sagemaker module #435

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

Merged
merged 1 commit into from
Oct 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,27 @@
# language governing permissions and limitations under the License.
from __future__ import absolute_import

from glob import glob
import os
import re
from glob import glob

from setuptools import setup, find_packages


def get_version():
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we should follow pep-0396 guidance https://www.python.org/dev/peps/pep-0396/#classic-distutils :
In classic distutils, the simplest way to add the version string to the setup() function in setup.py is to do something like this:

from elle import __version__
setup(name='elle', version=__version__)

In the PEP author's experience however, this can fail in some cases, such as when the module uses automatic Python 3 conversion via the 2to3 program (because setup.py is executed by Python 3 before the elle module has been converted).

In that case, it's not much more difficult to write a little code to parse the version from the file rather than importing it. Without providing too much detail, it's likely that modules such as distutils2 will provide a way to parse version strings from files. E.g.:

from distutils2 import get_version
setup(name='elle', version=get_version('elle.py'))

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind, from offline conversation that seems to be the new way (especially since Distutils2 development is stopped):
https://packaging.python.org/guides/single-sourcing-package-version/

root = os.path.dirname(__file__)
version_re = re.compile(r'''__version__ = ['"]([0-9.]+)['"]''')

init = read(os.path.join(root, 'src/sagemaker', '__init__.py'))
return version_re.search(init).group(1)


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


setup(name="sagemaker",
version="1.11.3",
version=get_version(),
description="Open source library for training and deploying models on Amazon SageMaker.",
packages=find_packages('src'),
package_dir={'': 'src'},
Expand All @@ -44,7 +53,8 @@ def read(fname):
],

# Declare minimal set for installation
install_requires=['boto3>=1.4.8', 'numpy>=1.9.0', 'protobuf>=3.1', 'scipy>=0.19.0', 'urllib3 >=1.21, <1.23',
install_requires=['boto3>=1.4.8', 'numpy>=1.9.0', 'protobuf>=3.1', 'scipy>=0.19.0',
'urllib3 >=1.21, <1.23',
'PyYAML>=3.2', 'protobuf3-to-dict>=0.1.5', 'docker-compose>=1.21.0'],

extras_require={
Expand Down
2 changes: 2 additions & 0 deletions src/sagemaker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@
from sagemaker.session import production_variant # noqa: F401
from sagemaker.session import s3_input # noqa: F401
from sagemaker.session import get_execution_role # noqa: F401

__version__ = '1.11.3'
19 changes: 19 additions & 0 deletions tests/unit/test_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
from __future__ import absolute_import

import sagemaker


def test_version():
assert sagemaker.__version__