This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnoxfile.py
59 lines (47 loc) · 1.65 KB
/
noxfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pathlib import Path
import nox_poetry
local = Path(__file__).parent.absolute()
@nox_poetry.session(python=["3.10"])
def build_blockfrost_classes(session):
"""Autogenerate the blockfrost models.
This uses `datamodel-code-generator` to generate model classes from the Blockfrost
OpenAPI specification.
Args:
session (_type_): _description_
"""
# Install dependencies
session.install("datamodel-code-generator", ".")
session.install("requests", ".")
# Download the latest OpenAPI schema from blockfrost/openapi/master
import requests
url = "https://raw.githubusercontent.com/blockfrost/openapi/master/openapi.yaml"
source = local.joinpath("src/models/data/blockfrost/openapi.yaml")
source.parent.mkdir(exist_ok=True, parents=True)
response = requests.get(url=url)
with open(source, "wb") as fw:
fw.write(response.content)
destination = local.joinpath("src/minswap/models/blockfrost_models.py")
session.run(
"datamodel-codegen",
"--input",
str(source),
"--input-file-type",
"openapi",
"--output",
str(destination),
"--use-schema-description",
"--use-field-description",
"--collapse-root-models",
"--field-constraints",
"--use-double-quotes",
"--target-python-version",
"3.9",
)
@nox_poetry.session(python=["3.10"])
def unit_tests(session):
"""Run unit tests on all supported versions of Python"""
# Install dependencies
session.install("poetry")
session.run_always("poetry", "install", "--only-root")
session.install("pytest")
session.run("pytest")