Skip to content

Commit

Permalink
Version Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofix committed Jun 27, 2024
1 parent 56e5dc3 commit c20f9e5
Show file tree
Hide file tree
Showing 34 changed files with 441 additions and 108 deletions.
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{html,py,json,md}]
charset = utf-8

[*.py]
indent_style = space
indent_size = 4
max_line_length = 119

[*.md]
indent_style = space
indent_size = 4
max_line_length = 119

[*.html]
indent_style = space
indent_size = 2

[Makefile]
indent_style = tab

[*.json]
indent_style = space
indent_size = 2
15 changes: 15 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[flake8]
max-complexity = 10
max-line-length = 119
max-doc-length = 120
indent-size = 4
exclude =
.git,
__pycache__,
.github,
docs,
tests
filename = *.py
accept-encodings = utf-8
inline-quotes = single
multiline-quotes = double
41 changes: 0 additions & 41 deletions .github/workflows/ci.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/test_coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Tests&Coverage

on:
push:
branches: ["sandbox"]
pull_request:
branches: ["main"]

jobs:
tests:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
poetry-version: ["1.8.3"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Set Up Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install merchants
run: poetry install --with dev
- name: Run Tests and coverage
run: poetry run coverage run -m pytest
- name: Coverage report (xml)
run: poetry run coverage xml
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@v2
- name: Run codacy-coverage-reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: "coverage.xml"
language: "python"
39 changes: 29 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-json
- id: check-added-large-files
args: ['--maxkb=1024']
- id: check-case-conflict
- id: mixed-line-ending
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
rev: v3.16.0
hooks:
- id: pyupgrade
- repo: https://github.com/pycqa/isort
rev: 5.12.0
args: [--py311-plus]
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.4
hooks:
- id: isort
args: ["--profile", "black", "--filter-files", "--line-length", "100"]
- id: autopep8
- repo: https://github.com/PyCQA/flake8
rev: "7.1.0"
hooks:
- id: flake8
additional_dependencies:
- flake8-comprehensions
- flake8-bugbear
- flake8-polyfill
- toml
exclude: docs\/.*
17 changes: 17 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.PHONY: env-info
env-info:
poetry env info

# MIG_MSG="new thing" make migrations
.PHONY: migrations
migrations:
poetry run flask db migrate -m "${MIG_MSG}"

.PHONY: upgrade-db
upgrade-db:
poetry run flask db upgrade head

.PHONY: pre-commit
pre-commit:
poetry run pre-commit autoupdate -j 2
poetry run pre-commit run --all-files
File renamed without changes.
30 changes: 30 additions & 0 deletions examples/peewee/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import peewee

from merchants import settings
from merchants.orm.peewee import MerchantsAccountSettings, MerchantsBaseModel

db = peewee.SqliteDatabase("./examples/peewee/example.sqlite3")


class Payment(MerchantsBaseModel):
content = peewee.TextField()

class Meta:
database = db


class AccountSettings(MerchantsAccountSettings):
class Meta:
database = db


def create_database():
with db:
db.create_tables([Payment, AccountSettings])


create_database()

# settings.process_on_save = False
settings.load_variants(config=None)
print(f"{settings=}")
Binary file added examples/peewee/example.sqlite3
Binary file not shown.
File renamed without changes.
6 changes: 2 additions & 4 deletions examples/sqlalchemy/example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Literal

from sqlalchemy import Column, Integer, String, create_engine
from sqlalchemy import Column, Integer, create_engine
from sqlalchemy.orm import declarative_base, sessionmaker
from sqlalchemy_utils import generic_repr

from merchants.core.orm.sqla import PaymentMixin
from merchants.orm.sqla import PaymentMixin

SQLALCHEMY_DATABASE_URL = "sqlite:///./examples/sqlalchemy/db.sqlite3"

Expand Down
3 changes: 3 additions & 0 deletions merchants/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .config import base_settings as settings

__all__ = ["settings"]
4 changes: 2 additions & 2 deletions merchants/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import typer
from rich import print # pylint: disable=W0622
from rich import print

from merchants.providers import _provider_list
from merchants.integrations import _provider_list

cli = typer.Typer(help="Merchants CLI operations")

Expand Down
52 changes: 52 additions & 0 deletions merchants/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from dataclasses import dataclass, field


def _available_integrations() -> list:
return [
"paypal",
"square",
"stripe",
"payu",
"braintree", # es de paypal
"authorizenet",
"twocheckout",
"verifone", # compró 2checkout
"worldpay",
"fis", # fisglobal.com compro worldpay
"adyen",
"skrill",
"applepay",
"googlepay",
"klarna",
"wepay",
"alipay",
"wix",
]


@dataclass
class MerchantsSettings:
available_integrations: list = field(default_factory=_available_integrations)
enabled_accounts: list = field(default_factory=list)
process_on_save: bool = True

load_from_database: bool = True

def __post__init__(self):
pass

def load_variants(self, config: dict) -> list:
from .integrations.dummy import settings as example_settings

self.enabled_accounts = [
{
"example": {
"config": example_settings,
"provider_class": "merchants.integrations.dummy.Provider",
}
},
]
return self.enabled_accounts


base_settings = MerchantsSettings()
12 changes: 12 additions & 0 deletions merchants/core/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dataclasses import dataclass


@dataclass
class ModelStatus:
CREATED: str = "Created"
PROCESSING: str = "Processing"
ERROR: str = "Error"
REJECTED: str = "Rejected"
COMPLETED: str = "Completed"
REFUNDED: str = "Refunded"
REVERSED: str = "Reversed"
2 changes: 2 additions & 0 deletions merchants/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ProcessError(Exception):
pass
15 changes: 15 additions & 0 deletions merchants/integrations/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from ..config import base_settings


def local_factory(slug: str):
if slug not in base_settings.available_providers:
raise NotImplementedError(f"The provider {slug} is not supported.")

return slug


def create_provider(slug: str):
if slug not in base_settings.available_providers:
raise NotImplementedError(f"The provider {slug} is not supported.")

return slug
15 changes: 15 additions & 0 deletions merchants/integrations/dummy/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from dataclasses import dataclass

__version__ = "0.1.0"
__merchants_name__ = "dummy"
__merchants_slug__ = "dummy"


@dataclass
class Settings:
endpoint: str = "https://api.example.com"
api_key: str = "key_123456"
api_secret: str = "secret_123456"


settings = Settings()
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions merchants/integrations/stripe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__version__ = "0.1.0"
__merchants_name__ = "Stripe"
__merchants_slug__ = "stripe"
File renamed without changes.
Loading

0 comments on commit c20f9e5

Please sign in to comment.