Skip to content

Commit ed78926

Browse files
authored
Version 2 (#122)
New from the ground up object based implementation in stead of parsing of type strings, which improves performance, flexibility and readability.
1 parent 3130eef commit ed78926

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1314
-59651
lines changed

.github/workflows/unittests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: Run unit tests
22

33
on:
44
push:
5-
branches: [master, develop, v1.0, v0.11]
5+
branches: [master, develop, v1.0, v2]
66
pull_request:
77
# The branches below must be a subset of the branches above
8-
branches: [master, develop, v1.0, v0.11]
8+
branches: [master, develop, v1.0, v2]
99

1010
jobs:
1111
build:

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,32 @@ https://polkascan.github.io/py-scale-codec/
1818
pip install scalecodec
1919
```
2020

21+
## Code examples
22+
23+
```python
24+
from scalecodec.types import ScaleBytes, Bool, String, U32, U8, U16, Struct, Vec, Compact, Tuple, Enum
25+
26+
# encode a Vec<u16>
27+
obj = Vec(U16).new()
28+
value = [1, 2]
29+
data = obj.encode(value)
30+
31+
# Define and decode a Struct
32+
scale_obj = Struct(test=U8, test2=Tuple(U8, U8)).new()
33+
value = scale_obj.decode(ScaleBytes("0x020105"))
34+
35+
# Define and encode an Enum
36+
scale_obj = Enum(
37+
Bool=Bool(),
38+
Number=U32,
39+
Complex=Struct(data=String(), version=Compact(U8)),
40+
None_=None
41+
).new()
42+
value = {'Bool': True}
43+
44+
data = scale_obj.encode(value)
45+
```
46+
2147
## Examples of different types
2248

2349
| Type | Description | Example SCALE decoding value | SCALE encoded value |

pyproject.toml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[build-system]
2+
requires = ["setuptools>=61", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "scalecodec"
7+
description = "Python SCALE Codec Library"
8+
readme = "README.md"
9+
10+
authors = [
11+
{ name = "Polkascan Foundation", email = "info@polkascan.org" }
12+
]
13+
14+
requires-python = ">=3.6, <4"
15+
classifiers = [
16+
"Development Status :: 5 - Production/Stable",
17+
"Intended Audience :: Developers",
18+
"License :: OSI Approved :: Apache Software License",
19+
"Programming Language :: Python :: 3"
20+
]
21+
keywords = ["scale", "codec", "polkascan", "polkadot", "substrate", "blockchain", "kusama"]
22+
23+
dynamic = ["dependencies", "version"]
24+
25+
[project.optional-dependencies]
26+
dev = [
27+
"coverage==5.3",
28+
"pytest>=6.1.2",
29+
"mkdocs",
30+
"mkdocs-material",
31+
"mkdocs-autorefs",
32+
"mkdocstrings",
33+
"mkdocstrings[python]"
34+
]
35+
36+
[project.urls]
37+
Homepage = "https://github.com/polkascan/py-scale-codec"
38+
39+
[tool.setuptools.packages.find]
40+
where = ["."]
41+
exclude = ["contrib", "docs", "tests", "test"]
42+
43+
[tool.setuptools.package-data]
44+
"scalecodec.type_registry" = ["*.json"]
45+
46+
[tool.setuptools.dynamic]
47+
version = {attr = "scalecodec.__version__"}
48+
dependencies = {file = ["requirements.txt"]}

requirements.txt

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
base58==2.0.1
2-
atomicwrites~=1.4.0
3-
attrs~=20.3.0
4-
coverage==5.3
5-
more-itertools~=8.6.0
6-
pluggy==0.13.1
7-
pytest>=6.1.2
1+
base58>=2.0.1
2+
more-itertools>=8.6.0
83
requests>=2.24.0
9-
six==1.15.0
10-
11-
mkdocs
12-
mkdocs-material
13-
mkdocs-autorefs
14-
mkdocstrings
15-
mkdocstrings[python]

scalecodec/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python SCALE Codec Library
22
#
3-
# Copyright 2018-2020 Stichting Polkascan (Polkascan Foundation).
3+
# Copyright 2018-2024 Stichting Polkascan (Polkascan Foundation).
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -14,5 +14,9 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
# Import all type to make sure types classes are registered when RuntimeConfiguration inits.
18-
from .types import *
17+
import os
18+
19+
if os.getenv('GITHUB_REF') and os.getenv('GITHUB_REF').startswith('refs/tags/v'):
20+
__version__ = os.getenv('GITHUB_REF').replace('refs/tags/v', '')
21+
else:
22+
__version__ = '2.0.0-dev1'

0 commit comments

Comments
 (0)