From da01e8e8d419901ecc233bc18760c4c449141fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= Date: Wed, 28 Aug 2024 00:13:31 +0100 Subject: [PATCH] chore: major code re-structure Made black the default formatter for the project. Added simple unit tests. --- .github/workflows/deploy.yml | 28 ++++++++++++++++++ .github/workflows/main.yml | 55 ++++++++++++++++++++++++++++++++++++ .gitignore | 6 ++++ .travis.yml | 34 ---------------------- pytest.ini | 3 ++ setup.py | 50 +++++++++++++------------------- src/opbeat/__init__.py | 9 ------ src/opbeat/base.py | 40 ++++++++++++-------------- src/opbeat/test/__init__.py | 26 +++++++++++++++++ src/opbeat/test/base.py | 37 ++++++++++++++++++++++++ 10 files changed, 192 insertions(+), 96 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml create mode 100644 pytest.ini create mode 100644 src/opbeat/test/__init__.py create mode 100644 src/opbeat/test/base.py 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 e129159..420ce4e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,12 @@ session.shelve* +.DS_Store + +/.vscode/settings.json + +/.venv + /dist /build /src/opbeat_api.egg-info diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3fb2bef..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=opbeat 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: ZHpHtrIezbKL/hIABzcRP8LGS6DjmLKeTK0GhjfdZOu7iuExdOFVWhP343qs96rq7WiuSI7fS3DxncXR0nZq2X7kqjDMr/nkGq0wOjhVEoPMAHN4mwJYeu/SK8FT+RByZZy04tNGfPVNJzpsvpFlDDRDl6uaAYvF0nJ98X0yiI2dlw71aTnD7wImMWr0DUjirWb5qqo7EIUjGk//0XocUFbFfm10yRZqVd+ERy10rS9iPu4RkKke7wBheJa2JIiuvE+zS85EPGnG3BGlq2BEuTmKeoi0/gvBB/mMRdI/a4N/mVgl9aqOj55KaOqtpRXJIEfJE0HJqVHGeIQ0GVY1qoXB3I/bceJu3bAw3KmnZO95pK4In/uqwETWVBrxOLZfLIQw9wXMXzVGGHsc+GykdrTO8yX8GNSqvCJGQ8RWRVijqTJXVDqUKQzlmVOIFcz+TumGog+1Q2HJoUCoWXvsLJ0gVHs1gbEiXne9Wz93am/tPER2j2B4U7RfG2qaKj7cQpAfnzo3alnQxNmTcjY0X9vV4ekqjl3ekwimnc7opkF6mKiJHq2/FrPlnN3/6G2rLVdBZWIyfkF+0FY5QSu1VbLeDcNXNkxyS6yuRU2IKl5GbRe7Y9mpY332fs4wzzwCY5/eM1BZfbhc8pHOgr+fVm+6UXCnuc+eXUWMKvB5j6E= - distributions: sdist bdist_wheel - on: - tags: true - python: "2.7" diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..4ff9adb --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +python_files = *.py +testpaths = src/opbeat/test diff --git a/setup.py b/setup.py index 9e58d73..c208502 100644 --- a/setup.py +++ b/setup.py @@ -22,15 +22,6 @@ __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." """ The copyright for the module """ @@ -41,25 +32,20 @@ import setuptools setuptools.setup( - name = "opbeat-api", - version = "0.1.2", - author = "Hive Solutions Lda.", - author_email = "development@hive.pt", - description = "Opbeat API Client", - license = "Apache License, Version 2.0", - keywords = "Opbeat API", - url = "http://opbeat-api.hive.pt", - zip_safe = False, - packages = [ - "opbeat" - ], - package_dir = { - "" : os.path.normpath("src") - }, - install_requires = [ - "appier" - ], - classifiers = [ + name="opbeat-api", + version="0.1.2", + author="Hive Solutions Lda.", + author_email="development@hive.pt", + description="Opbeat API Client", + license="Apache License, Version 2.0", + keywords="Opbeat API", + url="http://opbeat-api.hive.pt", + zip_safe=False, + packages=["opbeat"], + test_suite="opbeat.test", + package_dir={"": os.path.normpath("src")}, + install_requires=["appier"], + classifiers=[ "Development Status :: 3 - Alpha", "Topic :: Utilities", "License :: OSI Approved :: Apache Software License", @@ -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", ) diff --git a/src/opbeat/__init__.py b/src/opbeat/__init__.py index 7233dc8..ad9833d 100644 --- a/src/opbeat/__init__.py +++ b/src/opbeat/__init__.py @@ -19,15 +19,6 @@ # You should have received a copy of the Apache License along with # Hive Opbeat 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." """ The copyright for the module """ diff --git a/src/opbeat/base.py b/src/opbeat/base.py index 303ad1e..6a579ce 100644 --- a/src/opbeat/base.py +++ b/src/opbeat/base.py @@ -22,15 +22,6 @@ __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." """ The copyright for the module """ @@ -43,6 +34,7 @@ """ The default base URL to be used when no other base URL value is provided to the constructor """ + class API(appier.API): def __init__(self, *args, **kwargs): @@ -60,27 +52,31 @@ 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 not auth: return + if not auth: + return headers["Authorization"] = "Bearer %s" % self.token - def release(self, payload = {}): + def release(self, payload={}): url = self.app_url + "releases/" - contents = self.post(url, data_j = payload) + contents = self.post(url, data_j=payload) return contents - def error(self, payload = {}): + def error(self, payload={}): url = self.app_url + "errors/" - contents = self.post(url, data_j = payload) + contents = self.post(url, data_j=payload) return contents def _build_url(self): - self.app_url = self.base_url + "organizations/%s/apps/%s/" % (self.org_id, self.app_id) + self.app_url = self.base_url + "organizations/%s/apps/%s/" % ( + self.org_id, + self.app_id, + ) diff --git a/src/opbeat/test/__init__.py b/src/opbeat/test/__init__.py new file mode 100644 index 0000000..4035ea9 --- /dev/null +++ b/src/opbeat/test/__init__.py @@ -0,0 +1,26 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Hive Opbeat API +# Copyright (c) 2008-2020 Hive Solutions Lda. +# +# This file is part of Hive Opbeat API. +# +# Hive Opbeat 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 Opbeat 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 Opbeat API. If not, see . + +__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda." +""" The copyright for the module """ + +__license__ = "Apache License, Version 2.0" +""" The license for the module """ diff --git a/src/opbeat/test/base.py b/src/opbeat/test/base.py new file mode 100644 index 0000000..a626b90 --- /dev/null +++ b/src/opbeat/test/base.py @@ -0,0 +1,37 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# Hive Opbeat API +# Copyright (c) 2008-2020 Hive Solutions Lda. +# +# This file is part of Hive Opbeat API. +# +# Hive Opbeat 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 Opbeat 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 Opbeat API. If not, see . + +__author__ = "João Magalhães " +""" The author(s) 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 """ + +import unittest + + +class BaseTest(unittest.TestCase): + + def test_basic(self): + self.assertEqual(1 + 1, 2)