Skip to content

Commit

Permalink
Merge pull request #58 from pllim/lazy-import
Browse files Browse the repository at this point in the history
Expose handler classes in top level import
  • Loading branch information
Cadair authored Dec 15, 2018
2 parents 5d0a9a8 + ec5243a commit 179eb16
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ htmlcov/
*egg-info*
build/
dist/
doc/api/
doc/_build/
27 changes: 19 additions & 8 deletions baldrick/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import os

from flask import Flask
from werkzeug.contrib.fixers import ProxyFix

from baldrick.config import load, Config
from baldrick.blueprints import github_blueprint, circleci_blueprint
from baldrick import github # noqa

__all__ = ['create_app', '__version__']

__version__ = '0.3.dev0'

GLOBAL_TOML = os.path.join('.', 'pyproject.toml')
GLOBAL_TOML = ''


def _init_global_toml():
import os
global GLOBAL_TOML

GLOBAL_TOML = os.path.join('.', 'pyproject.toml')


def create_app(name, register_blueprints=True):
Expand All @@ -31,6 +32,13 @@ def create_app(name, register_blueprints=True):
app
"""
import os

from flask import Flask
from werkzeug.contrib.fixers import ProxyFix

from baldrick.config import load, Config
from baldrick.blueprints import github_blueprint, circleci_blueprint

app = Flask(name)

Expand Down Expand Up @@ -60,3 +68,6 @@ def installation_authorized():
return "Installation authorized"

return app


_init_global_toml()
1 change: 1 addition & 0 deletions baldrick/github/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from baldrick.github.github_api import * # noqa
2 changes: 1 addition & 1 deletion baldrick/github/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from baldrick.config import loads
from baldrick.github.github_auth import github_request_headers

__all__ = ['GitHubHandler', 'RepoHandler', 'PullRequestHandler']
__all__ = ['GitHubHandler', 'IssueHandler', 'RepoHandler', 'PullRequestHandler']

HOST = "https://api.github.com"
HOST_NONAPI = "https://github.com"
Expand Down
2 changes: 1 addition & 1 deletion doc/api.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
API documentation
=================

.. automodapi:: baldrick.github.github_api
.. automodapi:: baldrick.github
:no-inheritance-diagram:

.. automodapi:: baldrick.github.github_auth
Expand Down
10 changes: 5 additions & 5 deletions doc/local.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ GitHub API

The different components of the bot interact with GitHub via a set of helper
classes that live in ``baldrick.github``. These classes are
:class:`~baldrick.github.github_api.RepoHandler`,
:class:`~baldrick.github.github_api.IssueHandler`, and
:class:`~baldrick.github.github_api.PullRequestHandler`. It is possible to try
:class:`~baldrick.github.RepoHandler`,
:class:`~baldrick.github.IssueHandler`, and
:class:`~baldrick.github.PullRequestHandler`. It is possible to try
these out locally, at least for the parts of the GitHub API that do not require
authentication. For example, the following should work::

>>> from baldrick.github.github_api import RepoHandler, IssueHandler, PullRequestHandler
>>> from baldrick.github import RepoHandler, IssueHandler, PullRequestHandler
>>> repo = RepoHandler('astropy/astropy')
>>> repo.get_issues('open', 'Close?')
[6025, 5193, 4842, 4549, 4058, 3951, 3845, 2603, 2232, 1920, 1024, 435, 383, 282]
Expand Down Expand Up @@ -54,7 +54,7 @@ the Installation ID and look like:
In this case, 36238 is the installation ID. Provided you set the environment
variables correctly, you should then be able to do e.g.::

>>> from baldrick.github.github_api import IssueHandler
>>> from baldrick.github import IssueHandler
>>> issue = IssueHandler('astrofrog/test-bot', 5, installation=36238)
>>> issue.submit_comment('I am alive!')

Expand Down
4 changes: 2 additions & 2 deletions doc/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ then use it to decorate a function of the form::
...

This function will be called with ``pr_handler``, an instance of
:class:`~baldrick.github.github_api.PullRequestHandler`, and ``repo_handler``,
an instance of :class:`~baldrick.github.github_api.RepoHandler` (click on
:class:`~baldrick.github.PullRequestHandler`, and ``repo_handler``,
an instance of :class:`~baldrick.github.RepoHandler` (click on
the class names to find out the available properties/methods).

Your function should then return either `None` (no check results), or
Expand Down

0 comments on commit 179eb16

Please sign in to comment.