Skip to content

Commit

Permalink
chore: modernized structure
Browse files Browse the repository at this point in the history
Added black and unit test structure.
  • Loading branch information
joamag committed Aug 27, 2024
1 parent 36e2410 commit d7f27c4
Show file tree
Hide file tree
Showing 16 changed files with 230 additions and 187 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Deploy Workflow
on:
push:
tags:
- "*"
jobs:
build:
name: Build
strategy:
matrix:
python-version: [2.7]
runs-on: ubuntu-latest
container: python:${{ matrix.python-version }}
steps:
- 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: python setup.py test
- run: pip install twine wheel
- run: python setup.py sdist bdist_wheel
- run: python -m twine upload -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD} dist/*
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
55 changes: 55 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Main Workflow
on: [push]
jobs:
build:
name: Build
strategy:
matrix:
python-version: [
2.7,
3.5,
3.6,
3.7,
3.8,
3.9,
"3.10",
"3.11",
"3.12",
latest,
rc
]
runs-on: ubuntu-latest
container: python:${{ matrix.python-version }}
steps:
- 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'
build-pypy:
name: Build PyPy
strategy:
matrix:
python-version: [2.7, 3.6, 3.9, "3.10"]
runs-on: ubuntu-latest
container: pypy:${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- run: pypy --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: pypy setup.py test
if: matrix.python-version != '3.12' && matrix.python-version != 'latest'
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

session.shelve*

.DS_Store

/.vscode/settings.json

/.venv

/dist
/build
/src/digitalocean_api_python.egg-info
34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

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

## Build Automation

[![Build Status](https://app.travis-ci.com/hivesolutions/digitalocean-api.svg?branch=master)](https://travis-ci.com/github/hivesolutions/digitalocean-api)
[![Build Status](https://github.com/hivesolutions/digitalocean-api/workflows/Main%20Workflow/badge.svg)](https://github.com/hivesolutions/digitalocean-api/actions)
[![Coverage Status](https://coveralls.io/repos/hivesolutions/digitalocean-api/badge.svg?branch=master)](https://coveralls.io/r/hivesolutions/digitalocean-api?branch=master)
[![PyPi Status](https://img.shields.io/pypi/v/digitalocean-api_python.svg)](https://pypi.python.org/pypi/digitalocean-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/digitalocean/test
50 changes: 19 additions & 31 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@
__author__ = "João Magalhães <joamag@hive.pt>"
""" 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."
""" The copyright for the module """

Expand All @@ -41,25 +32,20 @@
import setuptools

setuptools.setup(
name = "digitalocean-api_python",
version = "0.1.3",
author = "Hive Solutions Lda.",
author_email = "development@hive.pt",
description = "DigitalOcean API Client",
license = "Apache License, Version 2.0",
keywords = "digitalocean api",
url = "http://digitalocean-api.hive.pt",
zip_safe = False,
packages = [
"digitalocean"
],
package_dir = {
"" : os.path.normpath("src")
},
install_requires = [
"appier"
],
classifiers = [
name="digitalocean-api_python",
version="0.1.3",
author="Hive Solutions Lda.",
author_email="development@hive.pt",
description="DigitalOcean API Client",
license="Apache License, Version 2.0",
keywords="digitalocean api",
url="http://digitalocean-api.hive.pt",
zip_safe=False,
packages=["digitalocean"],
test_suite="digitalocean.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",
)
9 changes: 0 additions & 9 deletions src/digitalocean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
# You should have received a copy of the Apache License along with
# Hive DigitalOcean 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."
""" The copyright for the module """

Expand Down
10 changes: 1 addition & 9 deletions src/digitalocean/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@
__author__ = "João Magalhães <joamag@hive.pt>"
""" 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."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
""" The license for the module """


class ActionAPI(object):

def list_actions(self):
Expand Down
58 changes: 22 additions & 36 deletions src/digitalocean/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@
__author__ = "João Magalhães <joamag@hive.pt>"
""" 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."
""" The copyright for the module """

Expand Down Expand Up @@ -62,18 +53,12 @@
""" The redirect URL used as default (fallback) value
in case none is provided to the API (client) """

SCOPE = (
"read",
"write"
)
SCOPE = ("read", "write")
""" The list of permissions to be used to create the
scope string for the OAuth value """

class API(
appier.OAuth2API,
action.ActionAPI,
droplet.DropletAPI
):

class API(appier.OAuth2API, action.ActionAPI, droplet.DropletAPI):

def __init__(self, *args, **kwargs):
appier.OAuth2API.__init__(self, *args, **kwargs)
Expand All @@ -90,15 +75,16 @@ def __init__(self, *args, **kwargs):
self.refresh_token = kwargs.get("refresh_token", None)
self.email = kwargs.get("email", None)

def oauth_authorize(self, state = None):
def oauth_authorize(self, state=None):
url = self.auth_url + "oauth/authorize"
values = dict(
client_id = self.client_id,
redirect_uri = self.redirect_url,
response_type = "code",
scope = " ".join(self.scope)
client_id=self.client_id,
redirect_uri=self.redirect_url,
response_type="code",
scope=" ".join(self.scope),
)
if state: values["state"] = state
if state:
values["state"] = state
data = appier.legacy.urlencode(values)
url = url + "?" + data
return url
Expand All @@ -107,12 +93,12 @@ def oauth_access(self, code):
url = self.auth_url + "oauth/token"
contents = self.post(
url,
token = False,
client_id = self.client_id,
client_secret = self.client_secret,
grant_type = "authorization_code",
redirect_uri = self.redirect_url,
code = code
token=False,
client_id=self.client_id,
client_secret=self.client_secret,
grant_type="authorization_code",
redirect_uri=self.redirect_url,
code=code,
)
self.access_token = contents["access_token"]
self.refresh_token = contents["refresh_token"]
Expand All @@ -124,12 +110,12 @@ def oauth_refresh(self, refresh_token):
url = self.auth_url + "oauth/token"
contents = self.post(
url,
token = False,
client_id = self.client_id,
client_secret = self.client_secret,
grant_type = "refresh_token",
redirect_uri = self.redirect_url,
refresh_token = refresh_token,
token=False,
client_id=self.client_id,
client_secret=self.client_secret,
grant_type="refresh_token",
redirect_uri=self.redirect_url,
refresh_token=refresh_token,
)
self.access_token = contents["access_token"]
self.refresh_token = contents["refresh_token"]
Expand Down
12 changes: 2 additions & 10 deletions src/digitalocean/droplet.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@
__author__ = "João Magalhães <joamag@hive.pt>"
""" 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."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
""" The license for the module """


class DropletAPI(object):

def list_droplets(self):
Expand All @@ -46,7 +38,7 @@ def list_droplets(self):

def create_droplet(self, payload):
url = self.base_url + "droplets"
contents = self.post(url, data_j = payload)
contents = self.post(url, data_j=payload)
return contents

def get_droplet(self, droplet_id):
Expand Down
Loading

0 comments on commit d7f27c4

Please sign in to comment.