Alex Gaynor | 0e10f57 | 2014-01-06 13:17:31 -0800 | [diff] [blame] | 1 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 2 | # you may not use this file except in compliance with the License. |
| 3 | # You may obtain a copy of the License at |
| 4 | # |
| 5 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | # |
| 7 | # Unless required by applicable law or agreed to in writing, software |
| 8 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| 10 | # implied. |
| 11 | # See the License for the specific language governing permissions and |
| 12 | # limitations under the License. |
| 13 | from __future__ import absolute_import, division, print_function |
| 14 | |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 15 | import os |
| 16 | import re |
| 17 | |
| 18 | import invoke |
| 19 | |
| 20 | |
| 21 | def update_version(filename, identifier, version): |
| 22 | path = os.path.join(os.path.dirname(__file__), filename) |
| 23 | with open(path) as f: |
| 24 | contents = f.read() |
| 25 | contents = re.sub( |
| 26 | r"^{} = .*?$".format(identifier), |
| 27 | '{} = "{}"'.format(identifier, version), |
| 28 | contents |
| 29 | ) |
| 30 | with open(path, "w") as f: |
| 31 | f.write(contents) |
| 32 | |
| 33 | |
| 34 | @invoke.task |
| 35 | def release(version): |
| 36 | """ |
| 37 | ``version`` should be a string like '0.4' or '1.0'. |
| 38 | """ |
| 39 | # This checks for changes in the repo. |
| 40 | invoke.run("git diff-index --quiet HEAD") |
| 41 | |
Alex Gaynor | 7b8ef39 | 2014-01-06 15:16:49 -0800 | [diff] [blame] | 42 | update_version("cryptography/__about__.py", "__version__", version) |
| 43 | update_version("docs/conf.py", "version", version) |
| 44 | update_version("docs/conf.py", "release", version) |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 45 | |
| 46 | invoke.run("git commit -am 'Bump version numbers for release.'") |
Alex Gaynor | 6b1235a | 2014-01-06 15:28:59 -0800 | [diff] [blame^] | 47 | invoke.run("git push") |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 48 | invoke.run("git tag -s {}".format(version)) |
Alex Gaynor | 6b1235a | 2014-01-06 15:28:59 -0800 | [diff] [blame^] | 49 | invoke.run("git push --tags") |
Alex Gaynor | 6bc3af7 | 2014-01-06 12:04:53 -0800 | [diff] [blame] | 50 | |
| 51 | invoke.run("python setup.py sdist bdist_wheel") |
| 52 | invoke.run("twine upload -s dist/cryptography-{}*".format(version)) |