Skip to content

Commit 0c8b4c7

Browse files
Michael HollerMike Holler
authored andcommitted
Add support for Python lib continuous deployment.
Use a combination of travis and twine to publish to PyPI. New publications will be made: * When `master` is updated. This will trigger the publication of a the Python artifact versioned an iso-compliant build datetime. In this way, the cutting edge version will always be available via PyPI. * When a new git tag is pushed. Tag pushes trigger the publication of a python artifact with the same version as the git tag, with the leading `v` stripped if present (`v1.2.3` becomes `1.2.3`). Publications rely on Travis having a PYPI_PASSWORD environment set in the project settings. See the Travis CI documentation for information on [setting environment variables which containing sensitive data][1]. Make extra sure the "Display value in build log" switch is OFF. In addition to setting the previously mentioned `PYPI_PASSWORD` environment variable, the owner of the PyPI `flatbuffers` repository should, after merging this commit into master, add his own commit to change `mikeholler` in `.travis/deploy-python.sh` to his username. It's also recommended that the owner of `flatbuffers` use a separate account in the unlikely event that the environment variable somehow becomes compromised. Again, this is very unlikely, since the environment variable is only set for "safe" builds approved by maintainers (not on random pull requests). [1]: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings
1 parent 34aea43 commit 0c8b4c7

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

‎.travis.yml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ env:
44
- GCC_VERSION="4.9"
55
matrix:
66
include:
7+
- language: python
8+
python: "2.7"
9+
install:
10+
- "pip install wheel twine"
11+
script:
12+
- "cd python/"
13+
- 'VERSION="$TRAVIS_TAG" python setup.py sdist bdist_wheel'
14+
- "cd ../"
15+
deploy:
16+
# Checkpointed release builds.
17+
provider: script
18+
script: .travis/deploy-python.sh
19+
skip_cleanup: true
20+
on:
21+
tags: true
22+
deploy:
23+
# Produce a new build for the cutting edge when master changes.
24+
provider: script
25+
script: .travis/deploy-python.sh
26+
skip_cleanup: true
27+
on:
28+
branch: master
729
- language: cpp
830
os:
931
- linux

‎.travis/deploy-python.sh‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
PROD_REPOSITORY="https://upload.pypi.org/legacy"
5+
TEST_REPOSITORY="https://test.pypi.org/legacy/"
6+
7+
twine upload \
8+
--username mikeholler \
9+
--password "$PYPI_PASSWORD" \
10+
--repository-url "$PROD_REPOSITORY" \
11+
"$DIR/../python/dist/"*
12+

‎python/.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/dist/
2+
/*.egg-info/

‎python/setup.py‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,38 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
import os
16+
from datetime import datetime
1517
from setuptools import setup
1618

19+
20+
def version():
21+
version = os.getenv('VERSION', None)
22+
if version:
23+
# Most git tags are prefixed with 'v' (example: v1.2.3) this is
24+
# never desirable for artifact repositories, so we strip the
25+
# leading 'v' if it's present.
26+
return version[1:] if version.startswith('v') else version
27+
else:
28+
# Default version is an ISO8601 compiliant datetime. PyPI doesn't allow
29+
# the colon ':' character in its versions, and time is required to allow
30+
# for multiple publications to master in one day. This datetime string
31+
# uses the "basic" ISO8601 format for both its date and time components
32+
# to avoid issues with the colon character (ISO requires that date and
33+
# time components of a date-time string must be uniformly basic or
34+
# extended, which is why the date component does not have dashes.
35+
#
36+
# Publications using datetime versions should only be made from master
37+
# to represent the HEAD moving forward.
38+
version = datetime.utcnow().strftime('%Y%m%d%H%M%S')
39+
print("VERSION environment variable not set, using datetime instead: {}"
40+
.format(version))
41+
42+
return version
43+
1744
setup(
1845
name='flatbuffers',
19-
version='2015.05.14.0',
46+
version=version(),
2047
license='Apache 2.0',
2148
author='FlatBuffers Contributors',
2249
author_email='me@rwinslow.com',

0 commit comments

Comments
 (0)