Skip to content

Commit

Permalink
Merge 38c0231 into c19a186
Browse files Browse the repository at this point in the history
  • Loading branch information
stopthatcow committed Apr 26, 2019
2 parents c19a186 + 38c0231 commit 154033c
Show file tree
Hide file tree
Showing 42 changed files with 556 additions and 276 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
dist: trusty
dist: xenial
sudo: required

language: python
python:
- "2.7"
- "3.6"
- "3.7"

# command to install dependencies
install:
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include fastentrypoints.py
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ The zazu.yaml file lives at the base of the repo and describes the integrations

::

issueTracker:
issue_tracker:
type: github
owner: stopthatcow
repo: zazu

codeReviewer:
code_reviewer:
type: github
owner: stopthatcow
repo: zazu
Expand Down
5 changes: 2 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import sphinx_rtd_theme
import sys
sys.path.insert(0, os.path.abspath('..'))
import zazu.build

import zazu.repo.commands # noqa

# -- General configuration ------------------------------------------------

Expand Down Expand Up @@ -57,7 +56,7 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
semver = zazu.build.make_semver('../', 0)
semver = zazu.repo.commands.make_semver('../', 0)
pep440_version = zazu.build.pep440_from_semver(semver)
version = '{}.{}.{}'.format(semver.major, semver.minor, semver.patch)
if version == '0.0.0':
Expand Down
112 changes: 112 additions & 0 deletions fastentrypoints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# noqa: D300,D400
# Copyright (c) 2016, Aaron Christianson
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
Monkey patch setuptools to write faster console_scripts with this format:
import sys
from mymodule import entry_function
sys.exit(entry_function())
This is better.
(c) 2016, Aaron Christianson
http://github.com/ninjaaron/fast-entry_points
'''
from setuptools.command import easy_install
import re
TEMPLATE = r'''
# -*- coding: utf-8 -*-
# EASY-INSTALL-ENTRY-SCRIPT: '{3}','{4}','{5}'
__requires__ = '{3}'
import re
import sys
from {0} import {1}
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit({2}())'''.lstrip()


@classmethod
def get_args(cls, dist, header=None): # noqa: D205,D400
"""
Yield write_script() argument tuples for a distribution's
console_scripts and gui_scripts entry points.
"""
if header is None:
# pylint: disable=E1101
header = cls.get_header()
spec = str(dist.as_requirement())
for type_ in 'console', 'gui':
group = type_ + '_scripts'
for name, ep in dist.get_entry_map(group).items():
# ensure_safe_name
if re.search(r'[\\/]', name):
raise ValueError("Path separators not allowed in script names")
script_text = TEMPLATE.format(
ep.module_name, ep.attrs[0], '.'.join(ep.attrs),
spec, group, name)
# pylint: disable=E1101
args = cls._get_script_args(type_, name, header, script_text)
for res in args:
yield res


# pylint: disable=E1101
easy_install.ScriptWriter.get_args = get_args


def main():
import os
import re
import shutil
import sys
dests = sys.argv[1:] or ['.']
filename = re.sub(r'\.pyc$', '.py', __file__)

for dst in dests:
shutil.copy(filename, dst)
manifest_path = os.path.join(dst, 'MANIFEST.in')
setup_path = os.path.join(dst, 'setup.py')

# Insert the include statement to MANIFEST.in if not present
with open(manifest_path, 'a+') as manifest:
manifest.seek(0)
manifest_content = manifest.read()
if 'include fastentrypoints.py' not in manifest_content:
manifest.write(('\n' if manifest_content else '') +
'include fastentrypoints.py')

# Insert the import statement to setup.py if not present
with open(setup_path, 'a+') as setup:
setup.seek(0)
setup_content = setup.read()
if 'import fastentrypoints' not in setup_content:
setup.seek(0)
setup.truncate()
setup.write('import fastentrypoints\n' + setup_content)
19 changes: 12 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import fastentrypoints # Work around issue where setuptools creates very slow entry points for non-wheel distributions.
import setuptools
import os.path
import sys
Expand All @@ -16,7 +17,7 @@
import zazu.repo.commands
semver = zazu.repo.commands.make_semver('.')
version = zazu.repo.commands.pep440_from_semver(semver)
except ImportError:
except:
# Missing dependencies at this point.
version = '0.0.0'

Expand All @@ -36,12 +37,18 @@
url='https://github.com/stopthatcow/zazu',
license='MIT',
platforms='POSIX,MacOS,Windows',
# Python 2.7 and 3.6+ are supported.
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*',
classifiers=[
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Software Development',
'Topic :: Software Development :: Build Tools',
'Topic :: Software Development :: Quality Assurance',
Expand All @@ -55,17 +62,15 @@
'jira>=1.0.11', # BSD
'GitPython>=2.1.8', # BSD
'dict-recursive-update>=1.0.1', # MIT
'ruamel.yaml<=0.15', # MIT
'keyring<=8.0', # MIT
'ruamel.yaml>0.15', # MIT
'keyring>=18.0.1', # MIT
'keyrings.alt>=2.3', # MIT
'autopep8>=1.3.4', # MIT
'docformatter>=1.0', # Expat
'semantic_version>=2.6.0', # BSD
'future>=0.16.0', # MIT
'futures>=3.2.0', # PSF
'inquirer>=2.2.0', # MIT
'Importing>=1.10', # PSF
'straight.plugin>=1.5.0'], # MIT
'futures>=3.2.0 ; python_version<"3.0"', # PSF
'inquirer>=2.2.0'], # MIT
extras_require={
':sys_platform == "win32"': [
'pyreadline>=2.1' # BSD
Expand Down
53 changes: 26 additions & 27 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

@pytest.fixture()
def temp_user_config(tmp_dir):
config = {'scmHost': {'gh': {'type': 'github', 'user': 'user'}}}
config = {'scm_host': {'gh': {'type': 'github', 'user': 'user'}}}
path = os.path.join(tmp_dir, '.zazuconfig.yaml')
with open(path, 'w') as file:
yaml.dump(config, file)
Expand All @@ -34,7 +34,7 @@ def empty_user_config(tmp_dir):
def repo_with_invalid_issue_tracker(git_repo):
root = git_repo.working_tree_dir
config = {
'issueTracker': {
'issue_tracker': {
}
}
with open(os.path.join(root, 'zazu.yaml'), 'a') as file:
Expand All @@ -46,7 +46,7 @@ def repo_with_invalid_issue_tracker(git_repo):
def repo_with_unknown_issue_tracker(git_repo):
root = git_repo.working_tree_dir
config = {
'issueTracker': {
'issue_tracker': {
'type': 'foobar',
}
}
Expand All @@ -59,7 +59,7 @@ def repo_with_unknown_issue_tracker(git_repo):
def repo_with_jira(git_repo):
root = git_repo.working_tree_dir
jira_config = {
'issueTracker': {
'issue_tracker': {
'type': 'jira',
'url': 'https://zazu.atlassian.net/',
'project': 'TEST',
Expand Down Expand Up @@ -123,14 +123,14 @@ def test_unknown_styler():

def test_unknown_scm_host():
uut = zazu.config.Config('')
uut._user_config = {'scmHost': {'gh': {'type': ''}}}
uut._user_config = {'scm_host': {'gh': {'type': ''}}}
with pytest.raises(click.ClickException):
uut.scm_hosts()


def test_no_type_scm_host():
uut = zazu.config.Config('')
uut._user_config = {'scmHost': {'gh': {}}}
uut._user_config = {'scm_host': {'gh': {}}}
with pytest.raises(click.ClickException):
uut.scm_hosts()

Expand All @@ -149,48 +149,47 @@ def test_scm_host_repo(mocker, temp_user_config):
mock_scm_host.repos = mocker.Mock(side_effect=IOError)
uut._scm_hosts = {'foo': mock_scm_host}
uut._default_scm_host = 'foo'
assert uut.scm_host_repo('foo/bar') == None
assert uut.scm_host_repo('foo/bar') is None


def test_github_scm_host():
uut = zazu.config.Config('')
uut._user_config = {'scmHost': {'gh': {'type': 'github', 'user': 'user'}}}
uut._user_config = {'scm_host': {'gh': {'type': 'github', 'user': 'user'}}}
assert uut.scm_hosts()
assert uut.scm_hosts()['gh']
assert uut.default_scm_host() == 'gh'


def test_default_string_scm_host():
uut = zazu.config.Config('')
uut._user_config = {'scmHost': {'default': 'gh2',
'gh': {'type': 'github', 'user': 'user'},
'gh2': {'type': 'github', 'user': 'user'}}}
uut._user_config = {'scm_host': {'default': 'gh2',
'gh': {'type': 'github', 'user': 'user'},
'gh2': {'type': 'github', 'user': 'user'}}}
assert len(uut.scm_hosts()) == 2
assert uut.default_scm_host() == 'gh2'


def test_default_dict_scm_host():
uut = zazu.config.Config('')
uut._user_config = {'scmHost': {'default': {'type': 'github', 'user': 'user'},
'gh': {'type': 'github', 'user': 'user'}}}
uut._user_config = {'scm_host': {'default': {'type': 'github', 'user': 'user'},
'gh': {'type': 'github', 'user': 'user'}}}
assert len(uut.scm_hosts()) == 2
assert uut.default_scm_host() == 'default'


def test_bad_default_scm_host():
uut = zazu.config.Config('')
uut._user_config = {'scmHost': {'default': 'foo',
'gh': {'type': 'github', 'user': 'user'}}}
uut._user_config = {'scm_host': {'default': 'foo',
'gh': {'type': 'github', 'user': 'user'}}}
with pytest.raises(click.ClickException) as e:
assert uut.default_scm_host()
assert str(e.value) == 'default scmHost \'foo\' not found'
assert str(e.value) == 'default scm_host \'foo\' not found'


def test_github_user_config(mocker, temp_user_config):
mocker.patch('zazu.config.user_config_filepath', return_value=temp_user_config)
uut = zazu.config.Config('')
assert uut.scm_hosts()
print uut.scm_hosts()
assert uut.scm_hosts()['gh']


Expand All @@ -217,7 +216,7 @@ def test_no_code_reviewer():

def test_valid_code_reviewer():
uut = zazu.config.Config('')
uut._project_config = {'codeReviewer': {'type': 'github'}}
uut._project_config = {'code_reviewer': {'type': 'github'}}
assert uut.code_reviewer()


Expand Down Expand Up @@ -253,27 +252,27 @@ def test_config_list(mocker, temp_user_config):
mocker.patch('zazu.config.user_config_filepath', return_value=temp_user_config)
runner = click.testing.CliRunner()
result = runner.invoke(zazu.cli.cli, ['config', '--list'])
assert result.output == '''scmHost.gh.type=github\nscmHost.gh.user=user\n'''
assert result.output == '''scm_host.gh.type=github\nscm_host.gh.user=user\n'''
assert result.exit_code == 0
result = runner.invoke(zazu.cli.cli, ['config', 'scmHost.gh.user'])
result = runner.invoke(zazu.cli.cli, ['config', 'scm_host.gh.user'])
assert result.output == 'user\n'
assert result.exit_code == 0


def test_config_add_unset(mocker, temp_user_config):
mocker.patch('zazu.config.user_config_filepath', return_value=temp_user_config)
runner = click.testing.CliRunner()
result = runner.invoke(zazu.cli.cli, ['config', '--unset', 'scmHost.gh.user'])
result = runner.invoke(zazu.cli.cli, ['config', '--unset', 'scm_host.gh.user'])
assert result.exit_code == 0
result = runner.invoke(zazu.cli.cli, ['config', 'scmHost.gh.user'])
result = runner.invoke(zazu.cli.cli, ['config', 'scm_host.gh.user'])
assert result.exit_code != 0
result = runner.invoke(zazu.cli.cli, ['config', 'scmHost.gh.user', 'user'])
result = runner.invoke(zazu.cli.cli, ['config', 'scm_host.gh.user', 'user'])
assert result.exit_code != 0
result = runner.invoke(zazu.cli.cli, ['config', 'scmHost.gh.user'])
result = runner.invoke(zazu.cli.cli, ['config', 'scm_host.gh.user'])
assert result.exit_code != 0
result = runner.invoke(zazu.cli.cli, ['config', '--add', 'scmHost.gh.user', 'user'])
result = runner.invoke(zazu.cli.cli, ['config', '--add', 'scm_host.gh.user', 'user'])
assert result.exit_code == 0
result = runner.invoke(zazu.cli.cli, ['config', 'scmHost.gh.user'])
result = runner.invoke(zazu.cli.cli, ['config', 'scm_host.gh.user'])
assert result.exit_code == 0


Expand Down Expand Up @@ -309,5 +308,5 @@ def test_alt_branch_names(git_repo):

def test_complete_param(mocker, temp_user_config):
mocker.patch('zazu.config.user_config_filepath', return_value=temp_user_config)
assert zazu.config.complete_param(None, [], '') == ['scmHost.gh.type', 'scmHost.gh.user']
assert zazu.config.complete_param(None, [], '') == ['scm_host.gh.type', 'scm_host.gh.user']
assert zazu.config.complete_param(None, ['--add'], '') == []
2 changes: 1 addition & 1 deletion tests/test_dev.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import click
import click.testing
import conftest
import tests.conftest as conftest
import pytest
import webbrowser
import zazu.cli
Expand Down

0 comments on commit 154033c

Please sign in to comment.