Skip to content

Commit

Permalink
deps: bump pydantic to v2 & fix bugs. (#48)
Browse files Browse the repository at this point in the history
* deps: bump pydantic to v2 & fix bugs.

* fix pre-commit

* fix ci
  • Loading branch information
overcat committed Aug 28, 2023
1 parent c3d5779 commit 1c76846
Show file tree
Hide file tree
Showing 97 changed files with 981 additions and 678 deletions.
30 changes: 5 additions & 25 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ name: GitHub Action
on:
push:
pull_request:
branches-ignore:
- 'temp*'
- 'tmp*'
release:
types: [ created ]

Expand All @@ -15,35 +12,18 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest ]
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10", "pypy3" ]
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.7" ]
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.1.13 # Drop python3.6 support in 1.2.x
virtualenvs-create: true
virtualenvs-in-project: true

# - name: Load cached venv
# id: cached-poetry-dependencies
# uses: actions/cache@v2
# with:
# path: .venv
# key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
# if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
run: pip install .

- name: Test with unittest
run: |
source .venv/bin/activate
python -m unittest
run: python -m unittest
11 changes: 5 additions & 6 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ name: pre-commit
on:
push:
pull_request:
branches-ignore:
- 'temp*'
- 'tmp*'

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.10'
- uses: pre-commit/[email protected]
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
repos:
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
language_version: python3 # Should be a command that runs python3.6+

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.4
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8

- repo: https://github.com/timothycrosley/isort
rev: 5.8.0
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
additional_dependencies: [ toml ]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=============
stellar-model
=============
.. image:: https://img.shields.io/github/workflow/status/StellarCN/stellar-model/GitHub%20Action/main?style=flat&maxAge=1800
.. image:: https://img.shields.io/github/actions/workflow/status/StellarCN/stellar-model/continuous-integration-workflow.yml?branch=main&style=flat&maxAge=1800
:alt: GitHub Action
:target: https://github.com/StellarCN/stellar-model/actions

Expand Down Expand Up @@ -40,7 +40,7 @@ Example
url = "https://horizon.stellar.org/accounts/GALAXYVOIDAOPZTDLHILAJQKCVVFMD4IKLXLSZV5YHO7VY74IWZILUTO"
raw_resp = requests.get(url).json()
parsed_resp = AccountResponse.parse_obj(raw_resp)
parsed_resp = AccountResponse.model_validate(raw_resp)
print(f"Account Sequence: {parsed_resp.sequence}")
Expand All @@ -54,7 +54,7 @@ Of course you can use it with `stellar-sdk`_.
server = Server("https://horizon.stellar.org")
account_id = "GALAXYVOIDAOPZTDLHILAJQKCVVFMD4IKLXLSZV5YHO7VY74IWZILUTO"
raw_resp = server.accounts().account_id(account_id).call()
parsed_resp = AccountResponse.parse_obj(raw_resp)
parsed_resp = AccountResponse.model_validate(raw_resp)
print(f"Account Sequence: {parsed_resp.sequence}")
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
# sys.path.insert(0, os.path.abspath('.'))
import stellar_model


# -- Project information -----------------------------------------------------

project = "stellar-model"
Expand Down
597 changes: 426 additions & 171 deletions poetry.lock

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ classifiers = [
]

[tool.poetry.dependencies]
python = ">=3.6.1"
pydantic = "^1.8.1"
python = ">=3.7"
pydantic = "^2.3.0"

[tool.poetry.dev-dependencies]
Sphinx = "^5.2.3"
Expand All @@ -47,14 +47,8 @@ build-backend = "poetry.core.masonry.api"

[tool.isort]
profile = "black"
force_single_line = true
atomic = true
include_trailing_comma = true
lines_after_imports = 2
lines_between_types = 1
use_parentheses = true
src_paths = ["stellar_model", "tests"]
skip_glob = ["*/setup.py", "docs"]
skip_glob = ["docs"]
filter_files = true

[tool.black]
Expand Down
54 changes: 31 additions & 23 deletions stellar_model/model/horizon/account.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
from datetime import datetime
from decimal import Decimal
from typing import List
from typing import Mapping
from typing import Optional
from typing import List, Mapping, Optional

from pydantic import BaseModel
from pydantic import Field
from pydantic import BaseModel, Field

from stellar_model.model.horizon.link import Link


__all__ = ["Account"]


Expand Down Expand Up @@ -75,33 +71,40 @@ class Balance(BaseModel):
)
liquidity_pool_id: Optional[str] = Field(
description="This liquidity pool’s id encoded in a "
"hex string representation."
"hex string representation.",
default=None,
)
limit: Optional[Decimal] = Field(
description="The maximum amount of this asset that this account "
"is willing to accept. Specified when opening a trustline."
"is willing to accept. Specified when opening a trustline.",
default=None,
)
buying_liabilities: Optional[Decimal] = Field(
description="The sum of all buy offers owned by this account " "for this asset."
description="The sum of all buy offers owned by this account for this asset.",
default=None,
)
selling_liabilities: Optional[Decimal] = Field(
description="The sum of all sell offers owned by this account "
"for this asset."
"for this asset.",
default=None,
)
sponsor: Optional[str] = Field(
description="The account ID of the sponsor who is paying "
"the reserves for this trustline."
"the reserves for this trustline.",
default=None,
)
last_modified_ledger: Optional[int]
is_authorized: Optional[bool]
is_authorized_to_maintain_liabilities: Optional[bool]
is_clawback_enabled: Optional[bool]
last_modified_ledger: Optional[int] = None
is_authorized: Optional[bool] = None
is_authorized_to_maintain_liabilities: Optional[bool] = None
is_clawback_enabled: Optional[bool] = None
asset_type: str = Field(
description="Either **native**, **credit_alphanum4**, or **credit_alphanum12**."
)
asset_code: Optional[str] = Field(description="The code for this asset.")
asset_code: Optional[str] = Field(
description="The code for this asset.", default=None
)
asset_issuer: Optional[str] = Field(
description="The Stellar address of this asset's issuer."
description="The Stellar address of this asset's issuer.", default=None
)


Expand Down Expand Up @@ -129,24 +132,28 @@ class Account(BaseModel):
"For use when submitting this account's next transaction."
)
sequence_ledger: Optional[int] = Field(
description="The unsigned 32-bit ledger " "number of the sequence number's age."
description="The unsigned 32-bit ledger "
"number of the sequence number's age.",
default=None,
)
sequence_time: Optional[datetime] = Field(
description="The time of the sequence number's age."
description="The time of the sequence number's age.", default=None
)
subentry_count: int = Field(description="The number of subentries on this account.")
inflation_destination: Optional[str] = Field(
description="The inflation destination set for this account."
description="The inflation destination set for this account.", default=None
)
home_domain: Optional[str] = Field(
description="The domain that hosts this account's stellar.toml file."
description="The domain that hosts this account's stellar.toml file.",
default=None,
)
last_modified_ledger: int = Field(
description="The ID of the last ledger that included changes to this account."
)
last_modified_time: Optional[datetime] = Field(
description="The time of the last ledger that included "
"changes to this account."
"changes to this account.",
default=None,
)
thresholds: AccountThresholds = Field(
description="Operations have varying levels of access. "
Expand All @@ -170,7 +177,8 @@ class Account(BaseModel):
)
sponsor: Optional[str] = Field(
description="The account ID of the sponsor who is paying the "
"reserves for this account."
"reserves for this account.",
default=None,
)
paging_token: str = Field(description="A cursor value for use in pagination.")
links: Links = Field(alias="_links")
6 changes: 2 additions & 4 deletions stellar_model/model/horizon/account_data.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from typing import Optional

from pydantic import BaseModel
from pydantic import Field

from pydantic import BaseModel, Field

__all__ = ["AccountData"]

Expand All @@ -14,4 +12,4 @@ class AccountData(BaseModel):

value: str = Field(description="The key value for this data.")
# TODO: add description
sponsor: Optional[str]
sponsor: Optional[str] = None
9 changes: 5 additions & 4 deletions stellar_model/model/horizon/asset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Optional

from pydantic import BaseModel
from pydantic import Field
from pydantic import BaseModel, Field


class Asset(BaseModel):
Expand All @@ -13,7 +12,9 @@ class Asset(BaseModel):
description="The type for this asset. Either **native**, "
"**credit_alphanum4**, or **credit_alphanum12**."
)
asset_code: Optional[str] = Field(description="The code for this asset.")
asset_code: Optional[str] = Field(
description="The code for this asset.", default=None
)
asset_issuer: Optional[str] = Field(
description="The Stellar address of this asset's issuer."
description="The Stellar address of this asset's issuer.", default=None
)
4 changes: 1 addition & 3 deletions stellar_model/model/horizon/asset_stat.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from decimal import Decimal

from pydantic import BaseModel
from pydantic import Field
from pydantic import BaseModel, Field

from stellar_model.model.horizon.account import AccountFlags
from stellar_model.model.horizon.link import Link


__all__ = ["AssetStat"]


Expand Down
Loading

0 comments on commit 1c76846

Please sign in to comment.