Skip to content

Commit

Permalink
refactor: new black structure
Browse files Browse the repository at this point in the history
Removed travis and the badge.
Made code simpler with black.
Added dummy test for pytest execution.
  • Loading branch information
joamag committed Sep 26, 2024
1 parent 5dc5445 commit 85642c9
Show file tree
Hide file tree
Showing 24 changed files with 322 additions and 379 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ jobs:
- uses: actions/checkout@v4
- run: python --version
- run: pip install -r requirements.txt
- run: |
pip install black
black . --check
if: matrix.python-version == '3.12'
- run: |
pip install pytest
pytest
- run: python setup.py test
if: matrix.python-version != '3.12' && matrix.python-version != 'latest'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

session.shelve*

/.venv

/dist
/build
/src/github_api-python.egg-info
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ GitHub API is currently licensed under the [Apache License, Version 2.0](http://

## Build Automation

[![Build Status](https://app.travis-ci.com/hivesolutions/github-api.svg?branch=master)](https://travis-ci.com/github/hivesolutions/github-api)
[![Build Status GitHub](https://github.com/hivesolutions/github-api/workflows/Main%20Workflow/badge.svg)](https://github.com/hivesolutions/github-api/actions)
[![Build Status](https://github.com/hivesolutions/github-api/workflows/Main%20Workflow/badge.svg)](https://github.com/hivesolutions/github-api/actions)
[![Coverage Status](https://coveralls.io/repos/hivesolutions/github-api/badge.svg?branch=master)](https://coveralls.io/r/hivesolutions/github-api?branch=master)
[![PyPi Status](https://img.shields.io/pypi/v/github-api-python.svg)](https://pypi.python.org/pypi/github-api-python)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://www.apache.org/licenses/)
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
python_files = *.py
testpaths = src/github/test
54 changes: 21 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Hive GitHub API
# Copyright (c) 2008-2020 Hive Solutions Lda.
# Copyright (c) 2008-2024 Hive Solutions Lda.
#
# This file is part of Hive GitHub API.
#
Expand All @@ -22,16 +22,7 @@
__author__ = "João Magalhães <[email protected]>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda."
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
Expand All @@ -41,25 +32,20 @@
import setuptools

setuptools.setup(
name = "github-api-python",
version = "0.2.2",
author = "Hive Solutions Lda.",
author_email = "[email protected]",
description = "GitHub API Client",
license = "Apache License, Version 2.0",
keywords = "github api",
url = "http://github-api.hive.pt",
zip_safe = False,
packages = [
"github"
],
package_dir = {
"" : os.path.normpath("src")
},
install_requires = [
"appier"
],
classifiers = [
name="github-api-python",
version="0.2.2",
author="Hive Solutions Lda.",
author_email="[email protected]",
description="GitHub API Client",
license="Apache License, Version 2.0",
keywords="github api",
url="http://github-api.hive.pt",
zip_safe=False,
packages=["github"],
test_suite="github.test",
package_dir={"": os.path.normpath("src")},
install_requires=["appier"],
classifiers=[
"Development Status :: 3 - Alpha",
"Topic :: Utilities",
"License :: OSI Approved :: Apache Software License",
Expand All @@ -74,8 +60,10 @@
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7"
"Programming Language :: Python :: 3.7",
],
long_description = open(os.path.join(os.path.dirname(__file__), "README.md"), "rb").read().decode("utf-8"),
long_description_content_type = "text/markdown"
long_description=open(os.path.join(os.path.dirname(__file__), "README.md"), "rb")
.read()
.decode("utf-8"),
long_description_content_type="text/markdown",
)
13 changes: 2 additions & 11 deletions src/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Hive GitHub API
# Copyright (c) 2008-2020 Hive Solutions Lda.
# Copyright (c) 2008-2024 Hive Solutions Lda.
#
# This file is part of Hive GitHub API.
#
Expand All @@ -19,16 +19,7 @@
# You should have received a copy of the Apache License along with
# Hive GitHub API. If not, see <http://www.apache.org/licenses/>.

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda."
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
Expand Down
42 changes: 15 additions & 27 deletions src/examples/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Hive GitHub API
# Copyright (c) 2008-2020 Hive Solutions Lda.
# Copyright (c) 2008-2024 Hive Solutions Lda.
#
# This file is part of Hive GitHub API.
#
Expand All @@ -22,16 +22,7 @@
__author__ = "João Magalhães <[email protected]>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda."
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
Expand All @@ -41,14 +32,11 @@

from . import base


class GithubApp(appier.WebApp):

def __init__(self, *args, **kwargs):
appier.WebApp.__init__(
self,
name = "github",
*args, **kwargs
)
appier.WebApp.__init__(self, name="github", *args, **kwargs)

@appier.route("/", "GET")
def index(self):
Expand All @@ -57,7 +45,8 @@ def index(self):
@appier.route("/me", "GET")
def me(self):
url = self.ensure_api()
if url: return self.redirect(url)
if url:
return self.redirect(url)
api = self.get_api()
user = api.self_user()
return user
Expand All @@ -72,26 +61,24 @@ def oauth(self):
error = self.field("error")
appier.verify(
not error,
message = "Invalid OAuth response (%s)" % error,
exception = appier.OperationalError
message="Invalid OAuth response (%s)" % error,
exception=appier.OperationalError,
)
api = self.get_api()
access_token = api.oauth_access(code)
self.session["gh.access_token"] = access_token
return self.redirect(
self.url_for("github.index")
)
return self.redirect(self.url_for("github.index"))

@appier.exception_handler(appier.OAuthAccessError)
def oauth_error(self, error):
if "gh.access_token" in self.session: del self.session["gh.access_token"]
return self.redirect(
self.url_for("github.index")
)
if "gh.access_token" in self.session:
del self.session["gh.access_token"]
return self.redirect(self.url_for("github.index"))

def ensure_api(self):
access_token = self.session.get("gh.access_token", None)
if access_token: return
if access_token:
return
api = base.get_api()
return api.oauth_authorize()

Expand All @@ -101,6 +88,7 @@ def get_api(self):
api.access_token = access_token
return api


if __name__ == "__main__":
app = GithubApp()
app.serve()
Expand Down
24 changes: 8 additions & 16 deletions src/examples/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Hive GitHub API
# Copyright (c) 2008-2020 Hive Solutions Lda.
# Copyright (c) 2008-2024 Hive Solutions Lda.
#
# This file is part of Hive GitHub API.
#
Expand All @@ -22,16 +22,7 @@
__author__ = "João Magalhães <[email protected]>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda."
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
Expand All @@ -41,11 +32,12 @@

import github


def get_api():
return github.API(
username = appier.conf("GITHUB_USERNAME"),
password = appier.conf("GITHUB_PASSWORD"),
client_id = appier.conf("GITHUB_ID"),
client_secret = appier.conf("GITHUB_SECRET"),
redirect_url = appier.conf("GITHUB_REDIRECT_URL")
username=appier.conf("GITHUB_USERNAME"),
password=appier.conf("GITHUB_PASSWORD"),
client_id=appier.conf("GITHUB_ID"),
client_secret=appier.conf("GITHUB_SECRET"),
redirect_url=appier.conf("GITHUB_REDIRECT_URL"),
)
19 changes: 7 additions & 12 deletions src/examples/blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Hive GitHub API
# Copyright (c) 2008-2020 Hive Solutions Lda.
# Copyright (c) 2008-2024 Hive Solutions Lda.
#
# This file is part of Hive GitHub API.
#
Expand All @@ -22,16 +22,7 @@
__author__ = "João Magalhães <[email protected]> & Hugo Gomes <[email protected]>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda."
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
Expand All @@ -41,6 +32,10 @@

if __name__ == "__main__":
api = base.get_api()
print(api.blobs_data("hivesolutions", "appier", "fe0c75cd7960bf177d2ed6aa478e188ee7a2db85"))
print(
api.blobs_data(
"hivesolutions", "appier", "fe0c75cd7960bf177d2ed6aa478e188ee7a2db85"
)
)
else:
__path__ = []
Loading

0 comments on commit 85642c9

Please sign in to comment.