Skip to content

Commit

Permalink
Merge pull request audreyfeldroy#334 from astralblue/pep8
Browse files Browse the repository at this point in the history
Conform to PEP 8
  • Loading branch information
eliasdorneles authored Jun 10, 2017
2 parents a06d94f + 548fad1 commit 17ec67e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 30 deletions.
2 changes: 2 additions & 0 deletions {{cookiecutter.project_slug}}/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""The setup script."""

from setuptools import setup, find_packages

with open('README.rst') as readme_file:
Expand Down
2 changes: 2 additions & 0 deletions {{cookiecutter.project_slug}}/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# -*- coding: utf-8 -*-

"""Unit test package for {{ cookiecutter.project_slug }}."""
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
test_{{ cookiecutter.project_slug }}
----------------------------------
Tests for `{{ cookiecutter.project_slug }}` module.
"""
"""Tests for `{{ cookiecutter.project_slug }}` package."""

{% if cookiecutter.use_pytest == 'y' -%}
import pytest
{% else %}
import sys
import unittest
{%- endif %}
{%- if cookiecutter.command_line_interface|lower == 'click' %}
from contextlib import contextmanager
from click.testing import CliRunner
{%- endif %}

Expand All @@ -24,55 +17,60 @@
from {{ cookiecutter.project_slug }} import cli
{%- endif %}

{%- if cookiecutter.use_pytest == 'y' %}


{% if cookiecutter.use_pytest == 'y' -%}
@pytest.fixture
def response():
"""Sample pytest fixture.
See more at: http://doc.pytest.org/en/latest/fixture.html
"""
# import requests
# return requests.get('https://github.com/audreyr/cookiecutter-pypackage')


def test_content(response):
"""Sample pytest test function with the pytest fixture as an argument.
"""
"""Sample pytest test function with the pytest fixture as an argument."""
# from bs4 import BeautifulSoup
# assert 'GitHub' in BeautifulSoup(response.content).title.string
{%- if cookiecutter.command_line_interface|lower == 'click' %}


{%- if cookiecutter.command_line_interface|lower == 'click' %}
def test_command_line_interface():
"""Test the CLI."""
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert '{{ cookiecutter.project_slug }}.cli.main' in result.output
help_result = runner.invoke(cli.main, ['--help'])
assert help_result.exit_code == 0
assert '--help Show this message and exit.' in help_result.output

{%- endif %}
{% else %}
{%- else %}


class Test{{ cookiecutter.project_slug|title }}(unittest.TestCase):
"""Tests for `{{ cookiecutter.project_slug }}` package."""

def setUp(self):
pass
"""Set up test fixtures, if any."""

def tearDown(self):
pass
"""Tear down test fixtures, if any."""

def test_000_something(self):
pass
{% if cookiecutter.command_line_interface|lower == 'click' %}
"""Test something."""
{%- if cookiecutter.command_line_interface|lower == 'click' %}

def test_command_line_interface(self):
"""Test the CLI."""
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert '{{ cookiecutter.project_slug }}.cli.main' in result.output
help_result = runner.invoke(cli.main, ['--help'])
assert help_result.exit_code == 0
assert '--help Show this message and exit.' in help_result.output

{%- endif %}
{%- endif %}
{%- endif %}
23 changes: 14 additions & 9 deletions {{cookiecutter.project_slug}}/travis_pypi_setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Update encrypted deploy password in Travis config file
"""
"""Update encrypted deploy password in Travis config file."""


from __future__ import print_function
Expand All @@ -27,8 +26,9 @@


def load_key(pubkey):
"""Load public RSA key, with work-around for keys using
incorrect header/footer format.
"""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/
Expand Down Expand Up @@ -67,8 +67,7 @@ def fetch_public_key(repo):


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

Expand All @@ -79,19 +78,19 @@ def prepend_line(filepath, line):


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):
"""Update the deploy section of the .travis.yml file
to use the given 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)
Expand All @@ -104,6 +103,12 @@ def update_travis_deploy_password(encrypted_password):


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()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# -*- coding: utf-8 -*-

"""Top-level package for {{ cookiecutter.project_name }}."""

__author__ = """{{ cookiecutter.full_name }}"""
__email__ = '{{ cookiecutter.email }}'
__version__ = '{{ cookiecutter.version }}'
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-

"""Console script for {{cookiecutter.project_slug}}."""

import click


@click.command()
def main(args=None):
"""Console script for {{cookiecutter.project_slug}}"""
"""Console script for {{cookiecutter.project_slug}}."""
click.echo("Replace this message by putting your code into "
"{{cookiecutter.project_slug}}.cli.main")
click.echo("See click documentation at http://click.pocoo.org/")
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# -*- coding: utf-8 -*-

"""Main module."""

0 comments on commit 17ec67e

Please sign in to comment.