Skip to content

Commit c9f517f

Browse files
willis102thebeeland
authored andcommitted
SG-11735: Support for Python 3! (#202)
Python 3 support is here! This release is also compatible with Python 2.6 and 2.7, as it was before. This release includes a large number of changes to accommodate the newer versions of Python, but functionally it should remain the same.
1 parent a1e3d16 commit c9f517f

59 files changed

Lines changed: 10042 additions & 10385 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coveragerc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
source=shotgun_api3
1717
omit=
1818
shotgun_api3/lib/httplib2/*
19-
shotgun_api3/lib/simplejson/*
19+
shotgun_api3/lib/six.py
2020
shotgun_api3/lib/xmlrpclib.py

.flake8

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2019 Shotgun Software Inc.
2+
#
3+
# CONFIDENTIAL AND PROPRIETARY
4+
#
5+
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
6+
# Source Code License included in this distribution package. See LICENSE.
7+
# By accessing, using, copying or modifying this work you indicate your
8+
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
9+
# not expressly granted therein are reserved by Shotgun Software Inc.
10+
11+
[flake8]
12+
max-line-length = 120
13+
exclude = shotgun_api3/lib/httplib2/*,shotgun_api3/lib/six.py,shotgun_api3/lib/xmlrpclib.py,tests/httplib2test.py,tests/mock.py

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Copyright (c) 2019 Shotgun Software Inc.
2+
#
3+
# CONFIDENTIAL AND PROPRIETARY
4+
#
5+
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
6+
# Source Code License included in this distribution package. See LICENSE.
7+
# By accessing, using, copying or modifying this work you indicate your
8+
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
9+
# not expressly granted therein are reserved by Shotgun Software Inc.
10+
111
#python specific
212
*.pyc
313

.travis.yml

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,89 @@
1+
# Copyright (c) 2019 Shotgun Software Inc.
2+
#
3+
# CONFIDENTIAL AND PROPRIETARY
4+
#
5+
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
6+
# Source Code License included in this distribution package. See LICENSE.
7+
# By accessing, using, copying or modifying this work you indicate your
8+
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
9+
# not expressly granted therein are reserved by Shotgun Software Inc.
10+
111
language: python
2-
python:
3-
- "2.6"
4-
- "2.7"
512

6-
# use trusty dist, since xenial (default) does not support python 2.6
7-
dist: trusty
13+
# We need to test on multiple distros, since python 2.6 is not supported in xenial
14+
# and 3.7 is not supported in trusty. For now just use trusty to test 2.6, and use
15+
# the more modern xenial for 2.7 and 3.7.
16+
17+
# Additionally, we'll test on multiple sites. To accomplish this, we store the
18+
# secrets for the second site in a set of additional environment variables,
19+
# and copy those into the standard environment variables when running on the
20+
# second site.
21+
matrix:
22+
include:
23+
24+
# Use trusty dist for python 2.6, since the built-in xenial distro (default)
25+
# does not support Python 2.6
26+
# See https://docs.travis-ci.com/user/reference/xenial/#python-support
27+
28+
# Python 2.6, Server #1
29+
- dist: trusty
30+
python: "2.6"
31+
# flake8 does not support python 2.6, so only run it on 2.7+
32+
env:
33+
- RUN_FLAKE=false
34+
35+
# Python 2.6, Server #2
36+
- dist: trusty
37+
python: "2.6"
38+
# flake8 does not support python 2.6, so only run it on 2.7+
39+
env:
40+
- RUN_FLAKE=false
41+
- SG_SERVER_URL=$SG_SERVER_URL_2
42+
- SG_API_KEY=$SG_API_KEY_2
43+
- SG_HUMAN_PASSWORD=$SG_HUMAN_PASSWORD_2
44+
45+
# Test python 2.7 and 3.7 on Xenial.
46+
47+
# Python 2.7, Server #1
48+
- dist: xenial
49+
python: "2.7"
50+
env:
51+
- RUN_FLAKE=true
52+
53+
# Python 2.7, Server #2
54+
- dist: xenial
55+
python: "2.7"
56+
env:
57+
- RUN_FLAKE=true
58+
- SG_SERVER_URL=$SG_SERVER_URL_2
59+
- SG_API_KEY=$SG_API_KEY_2
60+
- SG_HUMAN_PASSWORD=$SG_HUMAN_PASSWORD_2
61+
62+
# Python 3.7, Server #1
63+
- dist: xenial
64+
python: "3.7"
65+
env:
66+
- RUN_FLAKE=true
67+
68+
# Python 3.7, Server #1
69+
- dist: xenial
70+
python: "3.7"
71+
env:
72+
- RUN_FLAKE=true
73+
- SG_SERVER_URL=$SG_SERVER_URL_2
74+
- SG_API_KEY=$SG_API_KEY_2
75+
- SG_HUMAN_PASSWORD=$SG_HUMAN_PASSWORD_2
876

977
# command to install dependencies
1078
install:
1179
- pip install -r tests/ci_requirements.txt
1280
before_script:
1381
- cp ./tests/example_config ./tests/config
14-
# command to run tests
15-
script: coverage run -m nose
82+
# Run flake and then run tests
83+
script:
84+
- if [ -n "$RUN_FLAKE" = true ]; then flake8; fi
85+
- coverage run -m nose --config="nose.cfg"
1686
after_success: coveralls
1787
notifications:
1888
email:
1989
- api@shotgunsoftware.com
20-
slack:
21-
rooms:
22-
secure: NgcVxptQji2OL7EKx5owh21tOl4rRg51ydYhLPHpBIpBVzlqPxi1jbMHpcbl8mG+GuhU6y1D6kVQgQfuAfIWx5YOc4FodhOFZgeS+eol5RTmEepl1OT6XmAVgEclSZUYQmK25OkcxnFnOV/31RuDPXWcgCvSBZqTy6lAbOZ5VwQ=

HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Shotgun Python API Changelog
44

55
Here you can see the full list of changes between each Python API release.
66

7+
v3.1.0 (2019 July 29)
8+
=====================
9+
- Adds support for Python 3.7
10+
711
v3.0.41 (2019 June 28)
812
=====================
913
- Adds an optional sleep between retries specified via the `SHOTGUN_API_RETRY_INTERVAL` environment variable, or by setting `sg.config.rpc_attempt_interval`.

README.md

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
[![VFX Platform](https://img.shields.io/badge/vfxplatform-2018-yellow.svg)](http://www.vfxplatform.com/)
1+
[![VFX Platform](https://img.shields.io/badge/vfxplatform-2020-blue.svg)](http://www.vfxplatform.com/)
2+
[![Python 2.6 2.7 3.7](https://img.shields.io/badge/python-2.6%20%7C%202.7%20%7C%203.7-blue.svg)](https://www.python.org/)
23
[![Reference Documentation](http://img.shields.io/badge/doc-reference-blue.svg)](http://developer.shotgunsoftware.com/python-api)
34
[![Build Status Linux](https://secure.travis-ci.org/shotgunsoftware/python-api.svg?branch=master)](http://travis-ci.org/shotgunsoftware/python-api)
45
[![Build status Windows](https://ci.appveyor.com/api/projects/status/slvw7u4jatvdly98/branch/master?svg=true
56
)](https://ci.appveyor.com/project/jfboismenu/python-api/branch/master)
67
[![Coverage Status](https://coveralls.io/repos/github/shotgunsoftware/python-api/badge.svg?branch=master)](https://coveralls.io/github/shotgunsoftware/python-api?branch=master)
7-
[![Linting](https://img.shields.io/badge/PEP8%20by-Hound%20CI-a873d1.svg)](https://houndci.com)
88

99
# Shotgun Python API
1010

@@ -15,14 +15,10 @@ The latest version can always be found at http://github.com/shotgunsoftware/pyth
1515
## Minimum Requirements
1616

1717
* Shotgun server v2.4.12+.
18-
* Python v2.6 - v2.7.
19-
20-
## High Performance Requirements
21-
22-
* Install [simplejson 2.1.6](http://pypi.python.org/pypi/simplejson/2.1.6)
18+
* Python v2.6 - v2.7 or v3.7
2319

2420
## Documentation
25-
Tutorials and detailed documentation about the Python API are available at http://developer.shotgunsoftware.com/python-api).
21+
Tutorials and detailed documentation about the Python API are available at http://developer.shotgunsoftware.com/python-api).
2622

2723
Some useful direct links:
2824

@@ -39,12 +35,70 @@ You can see the [full history of the Python API on the documentation site](http:
3935
## Updating HTTPLib2
4036

4137
1. Download the latest version of HTTPLib2 at https://pypi.org/project/httplib2.
42-
2. Extract the python2/httplib2 into shotgun_api3/lib/http2lib without the test folder.
43-
3. Scan the files for any references to importing httplib2 and make sure they import "from ." instead of "from httplib2" because the library isn't in the Python path.
38+
2. Extract the python2/httplib2 into shotgun_api3/lib/http2lib/python2 without the test folder.
39+
3. Extract the python3/httplib2 into shotgun_api3/lib/http2lib/python3 without the test folder.
40+
4. Scan the files for any references to importing httplib2 and make sure they import "from ." instead of "from httplib2" because the library isn't in the Python path.
41+
42+
## Maintaining Python 2 and 3 compatibility
43+
44+
python-api should remain compatible with both Python 2, and 3. To make this easier, we use [six](https://six.readthedocs.io/). When adding code that works with types that have changed between Python 2 and 3, notably strings and files, it's advisable to use the `six` types for casting and comparisons. Be sure to follow Python 2 and 3 compatible conventions in code, especially when raising or capturing exceptions and printing. While we don't use `future`, [this page](https://python-future.org/compatible_idioms.html) contains a fairly comprehensive list of Python 2/3 compatibility sticking points to look out for.
45+
46+
Additionally, the [python-modernize](https://python-modernize.readthedocs.io/en/latest/) tool can be helpful when updating Python 2 code for Python 3 compatibility.
47+
48+
### Examples:
49+
50+
#### Comparisons against changed types:
51+
52+
Python 2:
53+
54+
```
55+
if isinstance(my_variable, str):
56+
```
57+
58+
Python 2/3:
59+
60+
```
61+
if isinstance(my_variable, six.string_types):
62+
```
63+
64+
#### Catching exceptions
65+
66+
Python 2:
67+
68+
```
69+
except SomeExceptionType, e:
70+
print "I like to swallow exceptions!"
71+
```
72+
73+
Python 2/3:
74+
75+
```
76+
from __future__ import print_function
77+
except SomeExceptionType as e:
78+
print("I like to swallow exceptions!")
79+
```
80+
81+
#### Print statements
82+
83+
Python 2:
84+
85+
```
86+
print "My spoon is too big!"
87+
```
88+
89+
Python 2/3:
90+
91+
```
92+
from __future__ import print_function
93+
print("My spoon is too big!")
94+
```
95+
96+
97+
Additionally, when testing locally, tests should be run for both python 2 and python 3 to ensure changes won't break cross-compatibility.
4498

45-
## Tests
99+
## Tests
46100

47-
Integration and unit tests are provided.
101+
Integration and unit tests are provided.
48102

49103
- All tests require the [nose unit testing tools](http://nose.readthedocs.org), and a `tests/config` file (you can copy an example from `tests/example_config`).
50104
- Tests can be run individually like this: `nosetest tests/test_client.py`
@@ -58,11 +112,11 @@ Integration and unit tests are provided.
58112

59113
1) Update the Changelog in the `HISTORY.rst` file
60114
- Add bullet points for any changes that have happened since the previous release. This may include changes you did not make so look at the commit history and make sure we don't miss anything. If you notice something was done that wasn't added to the changelog, hunt down that engineer and make them feel guilty for not doing so. This is a required step in making changes to the API.
61-
- Try and match the language of previous change log messages. We want to keep a consistent voice.
115+
- Try and match the language of previous change log messages. We want to keep a consistent voice.
62116
- Make sure the date of the release matches today. We try and keep this TBD until we're ready to do a release so it's easy to catch that it needs to be updated.
63117
- Make sure the version number is filled out and correct. We follow semantic versioning. Or more correctly, we should be following it.
64118
2) Ensure any changes or additions to public methods are documented
65-
- Update the Github wiki, and usually you'll need to update the Method Reference page with concise and exact documentation of the changes that are in this release.
119+
- Update the Github wiki, and usually you'll need to update the Method Reference page with concise and exact documentation of the changes that are in this release.
66120
- Ensure that doc strings are updated in the code itself to work with Sphinx and are correctly formatted.
67121
- Examples are always good especially if this a new feature or method.
68122
- Think about a new user to the API trying to figure out how to use the features you're documenting.
@@ -76,7 +130,7 @@ Integration and unit tests are provided.
76130
- Add more detailed information regarding the changes in this release. This is a great place to add examples, and reasons for the change!
77131

78132
### Letting the world know
79-
We usually send an email to the `shotgun-dev` list with an announcement of the release and highlight the changes.
133+
We usually send an email to the `shotgun-dev` list with an announcement of the release and highlight the changes.
80134

81135
### Prepare for the Next Dev Cycle
82136
1) Update the `__version__` value in `shotgun_api3/shotgun.py` to the next version number with `.dev` appended to it. For example, `v3.0.24.dev`

appveyor.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
environment:
1414
matrix:
15+
- PYTHON: "C:\\Python26"
1516
- PYTHON: "C:\\Python27"
17+
- PYTHON: "C:\\Python37"
1618

1719
# To update these values, visit AppVeyor's site, click the user icon and scroll down to Encrypt Data.
1820
SG_SERVER_URL:
@@ -28,6 +30,16 @@ environment:
2830

2931
build: off
3032

33+
before_test:
34+
# The certificate store of the build machine is out of date and is missing a
35+
# new certificate authority used by Amazon for S3, so we need to update it.
36+
# See https://developer.shotgunsoftware.com/c593f0aa/
37+
- ps: |
38+
$cert_url = "https://www.amazontrust.com/repository/SFSRootCAG2.cer"
39+
$cert_file = New-TemporaryFile
40+
Invoke-WebRequest -Uri $cert_url -UseBasicParsing -OutFile $cert_file.FullName
41+
Import-Certificate -FilePath $cert_file.FullName -CertStoreLocation Cert:\LocalMachine\Root
42+
3143
test_script:
3244
# Put your test command here.
3345
# If you don't need to build C extensions on 64-bit Python 3.3 or 3.4,

docs/cookbook/examples/ami_version_packager.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,5 @@ It is intended to be used in conjunction with the script dicussed in :ref:`ami_h
253253
raise ShotgunException("Unknown action... :%s" % sa.action)
254254
255255
256-
print "\nVersion Packager done!"
256+
print("\nVersion Packager done!")
257257

docs/cookbook/examples/basic_create_shot.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ The Complete Example
8989
}
9090
result = sg.create('Shot', data)
9191
pprint(result)
92-
print "The id of the %s is %d." % (result['type'], result['id'])
92+
print("The id of the {} is {}.".format(result['type'], result['id']))
9393

9494
And here is the output::
9595

docs/cookbook/examples/svn_integration.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ link to the Revision.
117117
'created_by':{"type":"HumanUser", "id":result['id']}
118118
}
119119
revision = sg.create("Revision", parameters)
120-
print "created Revision #"+str(revision_code)
120+
print("created Revision #"+str(revision_code))
121121
122122
# Send error message if valid HumanUser is not found
123123
else:
124-
print "Unable to find valid Shotgun User with login: "+author+", Revision not created in Shotgun."
124+
print("Unable to find valid Shotgun User with login: "+author+", Revision not created in Shotgun.")
125125
126126
127127

0 commit comments

Comments
 (0)