diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..1bf936e --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..bd53800 --- /dev/null +++ b/.github/workflows/main.yml @@ -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' diff --git a/.gitignore b/.gitignore index 97cb79b..3913a9d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,7 @@ session.shelve* +/.venv + /dist /src/tutum_api.egg-info diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ada1bbb..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -dist: trusty -language: python -python: - - "2.7" - - "3.4" - - "3.5" - - "3.6" - - "pypy3" -matrix: - include: - - python: 3.8 - dist: xenial - - python: 3.9 - dist: xenial - - python: pypy - dist: xenial - - python: pypy3 - dist: xenial -before_install: - - pip install --upgrade pip setuptools -install: - - pip install -r requirements.txt - - if [[ $TRAVIS_PYTHON_VERSION != pypy* ]]; then pip install coveralls; fi -script: if [[ $TRAVIS_PYTHON_VERSION != pypy* ]]; then coverage run --source=tutum setup.py test; else python setup.py test; fi -after_success: if [[ $TRAVIS_PYTHON_VERSION != pypy* ]]; then coveralls; fi -deploy: - provider: pypi - user: joamag - password: - secure: PVeU5BHaKjmpCEajQYhXZgH0QvHalMezLC2Tj+llKUr4cc+uVIyd7LYj1L5moDUAfY9YTlRqe+CfrNu77V2ik3PL1CRlhw3wP6cbq1qSFxfd8ko9GLVjXGb8KxCuLge3MF+N3Y5fOEciMZ3pHwMbPFa+kW8/okATLtbuCBGbhf3oCPDc1xygbFcavl8TPGXj/vT1KmltYjU6Ue1HhzI0B6EQikaHqH7Dy7+TaWFy0w39XRvLOEiaQzr9tG+hccseC8lt85HSbIVXCa0KL4n2hCQ0EJ+9lHW8udNB7J3RRN+SJZIxtmyzKws7G6f46BnJKMFORIXfDPQ01Rmanih3bWDB5oPioX0uguR2SNiKDlq56gqBIgWalhtfKNwcxUdiiSRC8W/DilBHXW7wf4fm1PKNTndK8upwllzEf28nC+VcQKuDoKSht5jgn9rJnWM+3tVBQbSrmAC+GTL0sm5t6Ml/x0rxgzDHzTeJfpZvslNMRyqBcwBeHYmrqQJLK7qepJQKYBKrMSvjNFoydr3OlkGzZJKnAiY7yvawaxR+S1gdUiK9OZNS1G626JwrB8nWC24RMJYtF07PMTP7NFBiuDbkmNhXSGbkwvkvuECH1RVzO1ISBnpjDrQHQSbE/88Bkr5TxqCTiceP1GygjtifRm9Lekqw9K1/GdQGdFCzaX8= - distributions: sdist bdist_wheel - on: - tags: true - python: "2.7" diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..7b80212 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +python_files = *.py +testpaths = src/tutum/test diff --git a/setup.py b/setup.py index c05894a..bc7023e 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -22,16 +22,7 @@ __author__ = "João Magalhães " """ 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" @@ -41,25 +32,20 @@ import setuptools setuptools.setup( - name = "tutum-api", - version = "0.1.1", - author = "Hive Solutions Lda.", - author_email = "development@hive.pt", - description = "Tutum API Client", - license = "Apache License, Version 2.0", - keywords = "tutum api", - url = "http://tutum-api.hive.pt", - zip_safe = False, - packages = [ - "tutum" - ], - package_dir = { - "" : os.path.normpath("src") - }, - install_requires = [ - "appier" - ], - classifiers = [ + name="tutum-api", + version="0.1.1", + author="Hive Solutions Lda.", + author_email="development@hive.pt", + description="Tutum API Client", + license="Apache License, Version 2.0", + keywords="tutum api", + url="http://tutum-api.hive.pt", + zip_safe=False, + packages=["tutum"], + test_suite="tutum.test", + package_dir={"": os.path.normpath("src")}, + install_requires=["appier"], + classifiers=[ "Development Status :: 3 - Alpha", "Topic :: Utilities", "License :: OSI Approved :: Apache Software License", @@ -74,6 +60,6 @@ "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", + ], ) diff --git a/src/examples/__init__.py b/src/examples/__init__.py index 5348777..ef0ecb5 100644 --- a/src/examples/__init__.py +++ b/src/examples/__init__.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -19,16 +19,7 @@ # You should have received a copy of the Apache License along with # Hive Tutum API. If not, see . -__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" diff --git a/src/examples/app.py b/src/examples/app.py index 95d664d..130d91c 100644 --- a/src/examples/app.py +++ b/src/examples/app.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -22,16 +22,7 @@ __author__ = "João Magalhães " """ 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" @@ -41,14 +32,11 @@ from . import base + class TututmApp(appier.WebApp): def __init__(self, *args, **kwargs): - appier.WebApp.__init__( - self, - name = "tutum", - *args, **kwargs - ) + appier.WebApp.__init__(self, name="tutum", *args, **kwargs) @appier.route("/", "GET") def index(self): @@ -112,6 +100,7 @@ def get_api(self): api = base.get_api() return api + if __name__ == "__main__": app = TututmApp() app.serve() diff --git a/src/examples/base.py b/src/examples/base.py index 16d042e..d4c9f79 100644 --- a/src/examples/base.py +++ b/src/examples/base.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -22,16 +22,7 @@ __author__ = "João Magalhães " """ 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" @@ -41,8 +32,8 @@ import tutum + def get_api(): return tutum.API( - username = appier.conf("TT_USERNAME"), - token = appier.conf("TT_PASSWORD") + username=appier.conf("TT_USERNAME"), token=appier.conf("TT_PASSWORD") ) diff --git a/src/tutum/__init__.py b/src/tutum/__init__.py index 869b5b5..cf1a674 100644 --- a/src/tutum/__init__.py +++ b/src/tutum/__init__.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -19,16 +19,7 @@ # You should have received a copy of the Apache License along with # Hive Tutum API. If not, see . -__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" diff --git a/src/tutum/action.py b/src/tutum/action.py index 6fa2c12..6140f9d 100644 --- a/src/tutum/action.py +++ b/src/tutum/action.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -22,21 +22,13 @@ __author__ = "João Magalhães " """ 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" """ The license for the module """ + class ActionAPI(object): def list_actions(self): diff --git a/src/tutum/base.py b/src/tutum/base.py index 634ecf1..bfeb3a4 100644 --- a/src/tutum/base.py +++ b/src/tutum/base.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -22,16 +22,7 @@ __author__ = "João Magalhães " """ 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" @@ -50,12 +41,13 @@ """ The default base URL to be used when no other base URL value is provided to the constructor """ + class API( appier.API, node.NodeAPI, action.ActionAPI, service.ServiceAPI, - container.ContainerAPI + container.ContainerAPI, ): def __init__(self, *args, **kwargs): @@ -70,19 +62,21 @@ def build( self, method, url, - data = None, - data_j = None, - data_m = None, - headers = None, - params = None, - mime = None, - kwargs = None + data=None, + data_j=None, + data_m=None, + headers=None, + params=None, + mime=None, + kwargs=None, ): auth = kwargs.pop("auth", True) - if auth: headers["Authorization"] = self.get_authorization() + if auth: + headers["Authorization"] = self.get_authorization() def get_authorization(self): - if not self.username or not self.password: None + if not self.username or not self.password: + None payload = "%s:%s" % (self.username, self.password) payload = appier.legacy.bytes(payload) authorization = base64.b64encode(payload) diff --git a/src/tutum/container.py b/src/tutum/container.py index fd4a053..15640d6 100644 --- a/src/tutum/container.py +++ b/src/tutum/container.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -22,21 +22,13 @@ __author__ = "João Magalhães " """ 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" """ The license for the module """ + class ContainerAPI(object): def list_containers(self): diff --git a/src/tutum/node.py b/src/tutum/node.py index d1d69de..f8b59e0 100644 --- a/src/tutum/node.py +++ b/src/tutum/node.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -22,21 +22,13 @@ __author__ = "João Magalhães " """ 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" """ The license for the module """ + class NodeAPI(object): def list_nodes(self): diff --git a/src/tutum/service.py b/src/tutum/service.py index 0da6a52..c3236f6 100644 --- a/src/tutum/service.py +++ b/src/tutum/service.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Hive Tutum API -# Copyright (c) 2008-2020 Hive Solutions Lda. +# Copyright (c) 2008-2024 Hive Solutions Lda. # # This file is part of Hive Tutum API. # @@ -22,21 +22,13 @@ __author__ = "João Magalhães " """ 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" """ The license for the module """ + class ServiceAPI(object): def list_services(self): diff --git a/src/tutum/test/__init__.py b/src/tutum/test/__init__.py new file mode 100644 index 0000000..0415093 --- /dev/null +++ b/src/tutum/test/__init__.py @@ -0,0 +1,26 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Hive Tutum API +# Copyright (c) 2008-2024 Hive Solutions Lda. +# +# This file is part of Hive Tutum API. +# +# Hive Tutum API is free software: you can redistribute it and/or modify +# it under the terms of the Apache License as published by the Apache +# Foundation, either version 2.0 of the License, or (at your option) any +# later version. +# +# Hive Tutum API is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Apache License for more details. +# +# You should have received a copy of the Apache License along with +# Hive Tutum API. If not, see . + +__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda." +""" The copyright for the module """ + +__license__ = "Apache License, Version 2.0" +""" The license for the module """ diff --git a/src/tutum/test/base.py b/src/tutum/test/base.py new file mode 100644 index 0000000..055e5db --- /dev/null +++ b/src/tutum/test/base.py @@ -0,0 +1,37 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Hive Tutum API +# Copyright (c) 2008-2024 Hive Solutions Lda. +# +# This file is part of Hive Tutum API. +# +# Hive Tutum API is free software: you can redistribute it and/or modify +# it under the terms of the Apache License as published by the Apache +# Foundation, either version 2.0 of the License, or (at your option) any +# later version. +# +# Hive Tutum API is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# Apache License for more details. +# +# You should have received a copy of the Apache License along with +# Hive Tutum API. If not, see . + +__author__ = "João Magalhães " +""" The author(s) of the module """ + +__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda." +""" The copyright for the module """ + +__license__ = "Apache License, Version 2.0" +""" The license for the module """ + +import unittest + + +class BaseTest(unittest.TestCase): + + def test_basic(self): + self.assertEqual(1 + 1, 2)