Skip to content

Commit 1304de9

Browse files
authored
Merge pull request #52 from pygame/mastertest
Adding ability to deploy through travisci. And docs.
2 parents 729a5ae + 9174403 commit 1304de9

File tree

7 files changed

+201
-18
lines changed

7 files changed

+201
-18
lines changed

.travis.yml

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,53 @@
1-
2-
# sudo required currently for postgresql 9.6
31
dist: trusty
42
sudo: required
53
services:
6-
- postgresql
4+
- postgresql
75
before_install:
8-
- sudo apt-get -qq update
9-
- sudo apt-get install -y yui-compressor node optipng
6+
- sudo apt-get -qq update
7+
- sudo apt-get install -y yui-compressor node optipng
108
before_script:
11-
- cp example.env .env
12-
- psql -c 'create database pygame_test;' -U postgres
13-
- psql pygame_test -c "CREATE USER pygame_test WITH PASSWORD 'password';" -U postgres
14-
- psql pygame_test -c "GRANT ALL PRIVILEGES ON DATABASE pygame_test to pygame_test;" -U postgres
9+
- cp example.env .env
10+
- psql -c 'create database pygame_test;' -U postgres
11+
- psql pygame_test -c "CREATE USER pygame_test WITH PASSWORD 'password';" -U postgres
12+
- psql pygame_test -c "GRANT ALL PRIVILEGES ON DATABASE pygame_test to pygame_test;"
13+
-U postgres
1514
addons:
16-
postgresql: "9.6"
15+
postgresql: '9.6'
1716
test:
1817
adapter: postgresql
1918
database: pygame_test
20-
2119
language: python
2220
cache: pip
2321
python:
24-
- "3.6"
22+
- '3.6'
2523
install:
2624
- pip install -r requirements.dev.txt
2725
- pip install coveralls
2826
- pip install -e .
29-
3027
script: APP_SECRET_KEY=a pytest
31-
3228
after_success:
33-
- coveralls
29+
- coveralls
30+
before_deploy:
31+
- pwd
32+
- ls -la
33+
- git checkout $TRAVIS_BRANCH
34+
- pygameweb_release_version_correct
35+
deploy:
36+
- provider: pypi
37+
user: illume
38+
distributions: sdist bdist_wheel
39+
on:
40+
branch:
41+
- master
42+
- mastertest
43+
password:
44+
secure: gzDc/dK0FJnLtcYBDXRu4PiIc+DvTBLKRbClBlSVayCiH0k+TzjatjwRJm9EPK0ctR3QX4esBrlxlLHVVIhjt1fWe/UcN+JEmR0ICPaPmcqR+17j+tPBX3PyrV8aULWe/PG9MgTKEZw9S8ysGPThlcXlcO0h65ma5/a58NZIBEKyamjXgrZmuipfYlMRjyk54c53gZGI+jKn3R3mgk+pDcjI3vL5pkA6QU69ucBhg/iLLoicpiTkUTfewV6nNcUKj88j162wgXshQ2Rnl7prvekDOaYeNplZzLto8gYO+HxO95povzG8nTxgqs1Soip1vW8hyPj4hmWkYfsxQt88UJZhnNaE+Dy2Uv+YyhxT7x9xonLB/HewOf2QROKElJG8qJ9CM+/F4QbkyRHXl9eP0hDbMDzc4cxAiuDJ0y3XysZBkRcBQoj+moDlyCv4LTc/bXhvoUXjCsmAI3xRmrV0j4Ml8wgoqFxT/bLH3CLW2sRmYg6mE+OCGfjubyxQPrwHLDOOJykj2kB1GCDhl1Jn0iGyRXdKzykSJPO3LJVelMmiwZwbdED0Nih70buG6EsEOquZhZB+oGltjO2W9rbphaxnoUDTQVq+JFrXD1eACY/42HJ4RZ9gBo0SqRCuGGaaYgw2BCvqinRoH+5qfoXontlkGX/XFbKQP3+3agJ0K+M=
45+
skip_cleanup: true
46+
- provider: pypi
47+
user: illume
48+
distributions: sdist bdist_wheel
49+
on:
50+
tags: true
51+
password:
52+
secure: gzDc/dK0FJnLtcYBDXRu4PiIc+DvTBLKRbClBlSVayCiH0k+TzjatjwRJm9EPK0ctR3QX4esBrlxlLHVVIhjt1fWe/UcN+JEmR0ICPaPmcqR+17j+tPBX3PyrV8aULWe/PG9MgTKEZw9S8ysGPThlcXlcO0h65ma5/a58NZIBEKyamjXgrZmuipfYlMRjyk54c53gZGI+jKn3R3mgk+pDcjI3vL5pkA6QU69ucBhg/iLLoicpiTkUTfewV6nNcUKj88j162wgXshQ2Rnl7prvekDOaYeNplZzLto8gYO+HxO95povzG8nTxgqs1Soip1vW8hyPj4hmWkYfsxQt88UJZhnNaE+Dy2Uv+YyhxT7x9xonLB/HewOf2QROKElJG8qJ9CM+/F4QbkyRHXl9eP0hDbMDzc4cxAiuDJ0y3XysZBkRcBQoj+moDlyCv4LTc/bXhvoUXjCsmAI3xRmrV0j4Ml8wgoqFxT/bLH3CLW2sRmYg6mE+OCGfjubyxQPrwHLDOOJykj2kB1GCDhl1Jn0iGyRXdKzykSJPO3LJVelMmiwZwbdED0Nih70buG6EsEOquZhZB+oGltjO2W9rbphaxnoUDTQVq+JFrXD1eACY/42HJ4RZ9gBo0SqRCuGGaaYgw2BCvqinRoH+5qfoXontlkGX/XFbKQP3+3agJ0K+M=
53+
skip_cleanup: true

README.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,34 @@ With with a @cache decorator, and/or markup in a template.
226226
.. |coverage-status| image:: https://coveralls.io/repos/github/pygame/pygameweb/badge.svg?branch=master
227227
:target: https://coveralls.io/github/pygame/pygameweb?branch=master
228228
:alt: Test coverage percentage
229+
230+
231+
232+
233+
Releases
234+
========
235+
236+
Releases are done from travisci. Fairly closely following this:
237+
https://docs.travis-ci.com/user/deployment/pypi/
238+
239+
- Commits to `master` branch do a dev deploy to pypi.
240+
- Commits to `mastertest` branch do a dev deploy to pypi.
241+
- Commits to a tag do a real deploy to pypi.
242+
243+
244+
https://packaging.python.org/tutorials/distributing-packages/#pre-release-versioning
245+
246+
Pre releases should be named like this:
247+
```
248+
# pygameweb/__init__.py
249+
__version__ = '0.0.2'
250+
```
251+
Which is one version ahead of of the last tagged release.
252+
253+
Release tags should be like '0.0.2', and match the `pygameweb/__init__.py __version__`.
254+
255+
When everything is ready, tags should be done through github.
256+
257+
Note: do not tag pre releases (these are made on commits to `master`/`mastertest`).
258+
https://help.github.com/articles/creating-releases/
259+

pygameweb/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '0.0.1'
1+
__version__ = '0.0.4.dev'
22

33

44
# So we can use environment variables to configure things.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""For updating the version from git.
2+
3+
__init__.py contains a __version__ field.
4+
Update that.
5+
6+
7+
If we are on master, we want to update the version as a pre-release.
8+
git describe --tags
9+
10+
11+
12+
With these:
13+
__init__.py
14+
__version__= '0.0.2'
15+
git describe --tags
16+
0.0.1-22-g729a5ae
17+
18+
We want this:
19+
__init__.py
20+
__version__= '0.0.2.dev22.g729a5ae'
21+
22+
Get the branch/tag name with this.
23+
git symbolic-ref -q --short HEAD || git describe --tags --exact-match
24+
25+
26+
27+
"""
28+
29+
import io
30+
import os
31+
import pathlib
32+
import re
33+
import subprocess
34+
35+
36+
def migrate_source_attribute(attr, to_this, target_file, regex):
37+
"""Updates __magic__ attributes in the source file"""
38+
change_this = re.compile(regex, re.S)
39+
new_file = []
40+
found = False
41+
42+
with open(target_file, 'r') as fp:
43+
lines = fp.readlines()
44+
45+
for line in lines:
46+
if line.startswith(attr):
47+
found = True
48+
line = re.sub(change_this, to_this, line)
49+
new_file.append(line)
50+
51+
if found:
52+
with open(target_file, 'w') as fp:
53+
fp.writelines(new_file)
54+
55+
def migrate_version(target_file, new_version):
56+
"""Updates __version__ in the source file"""
57+
regex = r"['\"](.*)['\"]"
58+
migrate_source_attribute('__version__', f"'{new_version}'", target_file, regex)
59+
60+
61+
def is_master_or_mastertest():
62+
cmd = ('git rev-parse --abbrev-ref HEAD')
63+
tag_branch = subprocess.check_output(cmd, shell=True)
64+
return tag_branch in [b'master\n', b'mastertest\n']
65+
66+
def git_tag_name():
67+
cmd = ('git describe --tags')
68+
tag_branch = subprocess.check_output(cmd, shell=True)
69+
tag_branch = tag_branch.decode().strip()
70+
return tag_branch
71+
72+
def get_git_version_info():
73+
cmd = 'git describe --tags'
74+
ver_str = subprocess.check_output(cmd, shell=True)
75+
ver, commits_since, githash = ver_str.decode().strip().split('-')
76+
return ver, commits_since, githash
77+
78+
def prerelease_version():
79+
""" return what the prerelease version should be.
80+
https://packaging.python.org/tutorials/distributing-packages/#pre-release-versioning
81+
82+
0.0.2.dev22
83+
"""
84+
ver, commits_since, githash = get_git_version_info()
85+
initpy_ver = get_version()
86+
# import pdb;pdb.set_trace()
87+
88+
assert len(initpy_ver.split('.')) in [3, 4], 'pygameweb/__init__.py version should be like 0.0.2 or 0.0.2.dev'
89+
assert initpy_ver > ver, 'the pygameweb/__init__.py version should be newer than the last tagged release.'
90+
# return f'{initpy_ver}.dev{commits_since}+git.{commits_since}.{githash}'
91+
return f'{initpy_ver}{commits_since}'
92+
93+
def read(*parts):
94+
""" Reads in file from *parts.
95+
"""
96+
try:
97+
return io.open(os.path.join(*parts), 'r', encoding='utf-8').read()
98+
except IOError:
99+
return ''
100+
101+
def get_version():
102+
""" Returns version from pygameweb/__init__.py
103+
"""
104+
version_file = read('pygameweb', '__init__.py')
105+
version_match = re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]',
106+
version_file, re.MULTILINE)
107+
if version_match:
108+
return version_match.group(1)
109+
raise RuntimeError('Unable to find version string.')
110+
111+
112+
def release_version_correct():
113+
"""Makes sure the:
114+
- prerelease verion for master is correct.
115+
- release version is correct for tags.
116+
"""
117+
if is_master_or_mastertest():
118+
# update for a pre release version.
119+
initpy = pathlib.Path('pygameweb') / '__init__.py'
120+
121+
if initpy.exists():
122+
target_version = str(initpy.absolute())
123+
new_version = prerelease_version()
124+
print(f'updating version in {initpy} from {target_version} to {new_version}')
125+
migrate_version(target_version, new_version)
126+
else:
127+
# check that we are a tag with the same version as in __init__.py
128+
assert get_version() == git_tag_name(), 'git tag/branch name not the same as pygame/__init__.py __verion__'

requirements.dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ pytest-pylint
1414
pytest-timeout
1515
pytest-watch
1616
pytest-xdist
17+
twine
18+
wheel
1719
-r requirements.txt

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99

1010
addopts=-v --cov pygameweb pygameweb/ tests/
1111

12+
[bdist_wheel]
13+
universal=1

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ def get_requirements():
4141
name='pygameweb',
4242
classifiers=[
4343
'Development Status :: 1 - Planning',
44-
'Classifier: Framework :: Flask',
45-
'Classifier: License :: OSI Approved',
4644
'License :: OSI Approved :: BSD License',
4745
'Programming Language :: Python :: 3',
4846
'Programming Language :: Python :: 3.6',
@@ -80,6 +78,8 @@ def get_requirements():
8078
'pygameweb.comment.classifier_train:classify_comments',
8179
'pygameweb_worker='
8280
'pygameweb.tasks.worker:work',
81+
'pygameweb_release_version_correct='
82+
'pygameweb.builds.update_version_from_git:release_version_correct',
8383
],
8484
},
8585
)

0 commit comments

Comments
 (0)