Skip to content

Commit

Permalink
Version 2 (#122)
Browse files Browse the repository at this point in the history
New from the ground up object based implementation in stead of parsing of type strings, which improves performance, flexibility and readability.
  • Loading branch information
arjanz authored Jul 17, 2024
1 parent 3130eef commit ed78926
Show file tree
Hide file tree
Showing 50 changed files with 1,314 additions and 59,651 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/unittests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Run unit tests

on:
push:
branches: [master, develop, v1.0, v0.11]
branches: [master, develop, v1.0, v2]
pull_request:
# The branches below must be a subset of the branches above
branches: [master, develop, v1.0, v0.11]
branches: [master, develop, v1.0, v2]

jobs:
build:
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@ https://polkascan.github.io/py-scale-codec/
pip install scalecodec
```

## Code examples

```python
from scalecodec.types import ScaleBytes, Bool, String, U32, U8, U16, Struct, Vec, Compact, Tuple, Enum

# encode a Vec<u16>
obj = Vec(U16).new()
value = [1, 2]
data = obj.encode(value)

# Define and decode a Struct
scale_obj = Struct(test=U8, test2=Tuple(U8, U8)).new()
value = scale_obj.decode(ScaleBytes("0x020105"))

# Define and encode an Enum
scale_obj = Enum(
Bool=Bool(),
Number=U32,
Complex=Struct(data=String(), version=Compact(U8)),
None_=None
).new()
value = {'Bool': True}

data = scale_obj.encode(value)
```

## Examples of different types

| Type | Description | Example SCALE decoding value | SCALE encoded value |
Expand Down
48 changes: 48 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
[build-system]
requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "scalecodec"
description = "Python SCALE Codec Library"
readme = "README.md"

authors = [
{ name = "Polkascan Foundation", email = "[email protected]" }
]

requires-python = ">=3.6, <4"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3"
]
keywords = ["scale", "codec", "polkascan", "polkadot", "substrate", "blockchain", "kusama"]

dynamic = ["dependencies", "version"]

[project.optional-dependencies]
dev = [
"coverage==5.3",
"pytest>=6.1.2",
"mkdocs",
"mkdocs-material",
"mkdocs-autorefs",
"mkdocstrings",
"mkdocstrings[python]"
]

[project.urls]
Homepage = "https://github.com/polkascan/py-scale-codec"

[tool.setuptools.packages.find]
where = ["."]
exclude = ["contrib", "docs", "tests", "test"]

[tool.setuptools.package-data]
"scalecodec.type_registry" = ["*.json"]

[tool.setuptools.dynamic]
version = {attr = "scalecodec.__version__"}
dependencies = {file = ["requirements.txt"]}
16 changes: 2 additions & 14 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
base58==2.0.1
atomicwrites~=1.4.0
attrs~=20.3.0
coverage==5.3
more-itertools~=8.6.0
pluggy==0.13.1
pytest>=6.1.2
base58>=2.0.1
more-itertools>=8.6.0
requests>=2.24.0
six==1.15.0

mkdocs
mkdocs-material
mkdocs-autorefs
mkdocstrings
mkdocstrings[python]
10 changes: 7 additions & 3 deletions scalecodec/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python SCALE Codec Library
#
# Copyright 2018-2020 Stichting Polkascan (Polkascan Foundation).
# Copyright 2018-2024 Stichting Polkascan (Polkascan Foundation).
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,5 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Import all type to make sure types classes are registered when RuntimeConfiguration inits.
from .types import *
import os

if os.getenv('GITHUB_REF') and os.getenv('GITHUB_REF').startswith('refs/tags/v'):
__version__ = os.getenv('GITHUB_REF').replace('refs/tags/v', '')
else:
__version__ = '2.0.0-dev1'
Loading

0 comments on commit ed78926

Please sign in to comment.