Skip to content

Commit

Permalink
Setting pipy configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-duarte committed Aug 27, 2017
1 parent baa7799 commit eb2eb03
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 111 deletions.
191 changes: 107 additions & 84 deletions .idea/workspace.xml

Large diffs are not rendered by default.

44 changes: 29 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
# Config file for automatic testing at travis-ci.org
# This file will be regenerated if you run travis_pypi_setup.py

# This file was autogenerated and will overwrite each time you run travis_pypi_setup.py
deploy:
provider: pypi
distributions: sdist bdist_wheel
user: yan-duarte
password:
secure: !!binary |
ZDZlbHZFUnZROTdqYWJsa093d1plOVlwK2N5N0ljeHM5d1J3aVB2RGRWd0c4dHZCQkNQTGMxcEhk
WTl5WGphaEk4amhNYStxa0V4VWxZS3Zpb0lxYjBFVmxJTy9vS2hwL2E5QTh3Q3RPejVNbGZHMjVr
Y3U5RGpYcURjYlFaUitteXBKdzEyeHM3bzMxSUErMjg4ZTlYYzFycHNabGV2aVlYdzY3T1VuWk1I
bGt5UU5GOTdlbDFCdElwNjd6TnN5Q1MvNExSNGRiRUpHck9ycDM2VVcrZXlPNTBzNDJRUkVmVy9J
Y0VTclc0UDhVZjNuOTh2RWNUQ21SQWNlallGakZoRDNqRnIvRmt0SkphWWFZQlhyaUUyMExTcEZB
ZGQrNmhaQzNDS2JCQ3NhYkxWek1ZTVJhNVZnRitkaUZ3OVNPWXlhYUdCQ09hVnJIWG4xS2hWTVFJ
N1F6US84MDczd2pDeW9GQitMUFJjUkZkZnZBYzJFMVA5RGZMVFZ3MTNoakRmS3hadHFhbDNMcnFY
a1laU1Z2UGNCSXpZYkU3RnYzeU1TbzJrQ0VFZXpkWkw0d1hSVWtKZnMvOFI2SE0xWGg4NGRXNk1O
RkhvZ3FVSEpIa1g3RkhjSWV5RjRaZFl2aDUrclE2UXJhMjlTKzZib3JBazdjUzRmVTdvYklZY1Rq
Q1BIdEY1NWZSNXh6S3NyNituNEN2QkwzRFlkUTBBL2ppTkt5aWlobnc2YWdsZ2FCRGRlSytGblJl
M2dNSkxxbHE3QVkrK3I4ZFdTVkk1REMzQTdPUHc5QUFha21EWnphRTNOMVR2UmZ2bm93WlhXNFJV
eFY0VE9GSnZkZUJrM1dyNFhMcFU1b3pNdDUyV3FKakdtY3czQzJhMGMwQktYMUVQczRYR3pUVVE9
true:
python: 3.6
repo: yan-duarte/qStatistic
tags: true
install: pip install -U tox-travis
language: python
python:
- 3.5
- 3.4
- 3.3
- 2.7
- 2.6

# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install: pip install -U tox-travis

# command to run tests, e.g. python setup.py test
- 3.5
- 3.4
- 3.3
- 2.7
- 2.6
script: tox


4 changes: 2 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Types of Contributions
Report Bugs
~~~~~~~~~~~

Report bugs at https://github.com/yan-duarte/qstatistic/issues.
Report bugs at https://github.com/yan-duarte/qStatistic/issues.

If you are reporting a bug, please include:

Expand Down Expand Up @@ -45,7 +45,7 @@ articles, and such.
Submit Feedback
~~~~~~~~~~~~~~~

The best way to send feedback is to file an issue at https://github.com/yan-duarte/qstatistic/issues.
The best way to send feedback is to file an issue at https://github.com/yan-duarte/qStatistic/issues.

If you are proposing a feature:

Expand Down
8 changes: 4 additions & 4 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ You can either clone the public repository:

.. code-block:: console
$ git clone git://github.com/yan-duarte/qstatistic
$ git clone git://github.com/yan-duarte/qStatistic
Or download the `tarball`_:

.. code-block:: console
$ curl -OL https://github.com/yan-duarte/qstatistic/tarball/master
$ curl -OL https://github.com/yan-duarte/qStatistic/tarball/master
Once you have a copy of the source, you can install it with:

Expand All @@ -47,5 +47,5 @@ Once you have a copy of the source, you can install it with:
$ python setup.py install
.. _Github repo: https://github.com/yan-duarte/qstatistic
.. _tarball: https://github.com/yan-duarte/qstatistic/tarball/master
.. _Github repo: https://github.com/yan-duarte/qStatistic
.. _tarball: https://github.com/yan-duarte/qStatistic/tarball/master
10 changes: 5 additions & 5 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pip==8.1.2
pip==9.0.1
bumpversion==0.5.3
wheel==0.29.0
watchdog==0.8.3
flake8==2.6.0
tox==2.3.1
coverage==4.1
Sphinx==1.4.8
flake8==3.4.1
tox==2.7.0
coverage==4.4.1
Sphinx==1.6.3


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
long_description=readme + '\n\n' + history,
author="Yan Anderson Siriano Duarte",
author_email='yan_asd@hotmail.com',
url='https://github.com/yan-duarte/qstatistic',
url='https://github.com/yan-duarte/qStatistic',
packages=find_packages(include=['qstatistic']),
include_package_data=True,
install_requires=requirements,
Expand Down
127 changes: 127 additions & 0 deletions travis_pypi_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Update encrypted deploy password in Travis config file."""


from __future__ import print_function
import base64
import json
import os
from getpass import getpass
import yaml
from cryptography.hazmat.primitives.serialization import load_pem_public_key
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15


try:
from urllib import urlopen
except ImportError:
from urllib.request import urlopen


GITHUB_REPO = 'yan-duarte/qStatistic'
TRAVIS_CONFIG_FILE = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '.travis.yml')


def load_key(pubkey):
"""Load public RSA key.
Work around keys with incorrect header/footer format.
Read more about RSA encryption with cryptography:
https://cryptography.io/latest/hazmat/primitives/asymmetric/rsa/
"""
try:
return load_pem_public_key(pubkey.encode(), default_backend())
except ValueError:
# workaround for https://github.com/travis-ci/travis-api/issues/196
pubkey = pubkey.replace('BEGIN RSA', 'BEGIN').replace('END RSA', 'END')
return load_pem_public_key(pubkey.encode(), default_backend())


def encrypt(pubkey, password):
"""Encrypt password using given RSA public key and encode it with base64.
The encrypted password can only be decrypted by someone with the
private key (in this case, only Travis).
"""
key = load_key(pubkey)
encrypted_password = key.encrypt(password, PKCS1v15())
return base64.b64encode(encrypted_password)


def fetch_public_key(repo):
"""Download RSA public key Travis will use for this repo.
Travis API docs: http://docs.travis-ci.com/api/#repository-keys
"""
keyurl = 'https://api.travis-ci.org/repos/{0}/key'.format(repo)
data = json.loads(urlopen(keyurl).read().decode())
if 'key' not in data:
errmsg = "Could not find public key for repo: {}.\n".format(repo)
errmsg += "Have you already added your GitHub repo to Travis?"
raise ValueError(errmsg)
return data['key']


def prepend_line(filepath, line):
"""Rewrite a file adding a line to its beginning."""
with open(filepath) as f:
lines = f.readlines()

lines.insert(0, line)

with open(filepath, 'w') as f:
f.writelines(lines)


def load_yaml_config(filepath):
"""Load yaml config file at the given path."""
with open(filepath) as f:
return yaml.load(f)


def save_yaml_config(filepath, config):
"""Save yaml config file at the given path."""
with open(filepath, 'w') as f:
yaml.dump(config, f, default_flow_style=False)


def update_travis_deploy_password(encrypted_password):
"""Put `encrypted_password` into the deploy section of .travis.yml."""
config = load_yaml_config(TRAVIS_CONFIG_FILE)

config['deploy']['password'] = dict(secure=encrypted_password)

save_yaml_config(TRAVIS_CONFIG_FILE, config)

line = ('# This file was autogenerated and will overwrite'
' each time you run travis_pypi_setup.py\n')
prepend_line(TRAVIS_CONFIG_FILE, line)


def main(args):
"""Add a PyPI password to .travis.yml so that Travis can deploy to PyPI.
Fetch the Travis public key for the repo, and encrypt the PyPI password
with it before adding, so that only Travis can decrypt and use the PyPI
password.
"""
public_key = fetch_public_key(args.repo)
password = args.password or getpass('PyPI password: ')
update_travis_deploy_password(encrypt(public_key, password.encode()))
print("Wrote encrypted password to .travis.yml -- you're ready to deploy")


if '__main__' == __name__:
import argparse
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--repo', default=GITHUB_REPO,
help='GitHub repo (default: %s)' % GITHUB_REPO)
parser.add_argument('--password',
help='PyPI password (will prompt if not provided)')

args = parser.parse_args()
main(args)

0 comments on commit eb2eb03

Please sign in to comment.