Skip to content

Commit

Permalink
Added pre-commit, reformatted all code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Knucklessg1 committed May 9, 2024
1 parent 2d4f81c commit 292b7d1
Show file tree
Hide file tree
Showing 11 changed files with 426 additions and 172 deletions.
69 changes: 69 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
default_language_version:
python: python3
exclude: 'dotnet'
ci:
autofix_prs: true
autoupdate_commit_msg: '[pre-commit.ci] pre-commit suggestions'
autoupdate_schedule: 'monthly'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-ast
- id: check-yaml
- id: check-toml
- id: check-json
- id: check-byte-order-marker
exclude: .gitignore
- id: check-merge-conflict
- id: detect-private-key
- id: trailing-whitespace
- id: end-of-file-fixer
- id: no-commit-to-branch
- repo: https://github.com/psf/black
rev: 24.3.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: ruff
types_or: [ python, pyi, jupyter ]
args: ["--fix", "--ignore=E402"]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args: ["-L", "ans,linar,nam,tread,ot,"]
exclude: |
(?x)^(
pyproject.toml |
website/static/img/ag.svg |
website/yarn.lock |
website/docs/tutorial/code-executors.ipynb |
website/docs/topics/code-execution/custom-executor.ipynb |
website/docs/topics/non-openai-models/cloud-gemini.ipynb |
notebook/.*
)$
# See https://jaredkhan.com/blog/mypy-pre-commit
- repo: local
hooks:
- id: mypy
name: mypy
entry: "./scripts/pre-commit-mypy-run.sh"
language: python
# use your preferred Python version
# language_version: python3.8
additional_dependencies: []
types: [python]
# use require_serial so that script
# is only called once per commit
require_serial: true
# Print the number of files as a sanity-check
verbose: true
- repo: https://github.com/nbQA-dev/nbQA
rev: 1.8.5
hooks:
- id: nbqa-black
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,3 @@ python -m pip install listmonk-api
![GitHub followers](https://img.shields.io/github/followers/Knucklessg1)
![GitHub User's stars](https://img.shields.io/github/stars/Knucklessg1)
</details>

2 changes: 2 additions & 0 deletions listmonk_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
__version__ = __version__
__author__ = __author__
__credits__ = __credits__

__all__ = ["Api"]
4 changes: 4 additions & 0 deletions listmonk_api/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
# coding: utf-8

import functools

try:
from listmonk_api.exceptions import LoginRequiredError
except ModuleNotFoundError:
from exceptions import LoginRequiredError


def require_auth(function):
"""
Wraps API calls in function that ensures headers are passed
with a token
"""

@functools.wraps(function)
def wrapper(self, *args, **kwargs):
if not self.headers:
raise LoginRequiredError
return function(self, *args, **kwargs)

return wrapper
6 changes: 6 additions & 0 deletions listmonk_api/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
#!/usr/bin/python
# coding: utf-8


class AuthError(Exception):
"""
Authentication error
"""

pass


class UnauthorizedError(AuthError):
"""
Unauthorized error
"""

pass


class MissingParameterError(Exception):
"""
Missing Parameter error
"""

pass


class ParameterError(Exception):
"""
Parameter error
"""

pass


class LoginRequiredError(Exception):
"""
Authentication error
"""

pass
Loading

0 comments on commit 292b7d1

Please sign in to comment.