Skip to content

Commit a0e2d6f

Browse files
Update metadata, fix package discovery (#758)
1 parent cbee0b2 commit a0e2d6f

Some content is hidden

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

63 files changed

+301
-1341
lines changed

.github/workflows/docs.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ jobs:
5757
- name: Build docs
5858
run: pdm run docs_build
5959

60-
- name: Commit and push frontend
61-
if: github.ref == 'refs/heads/next'
62-
run: |
63-
cd ../interface
64-
git config --local user.email "[email protected]"
65-
git config --local user.name "GitHub Action"
66-
git add .
67-
git diff-index --quiet HEAD || git commit -m "${{ github.event.head_commit.message }}"
68-
git push origin $FRONTEND_BRANCH
60+
# FIXME: Reenable before 7.0.0rc3 release
61+
# - name: Commit and push frontend
62+
# if: github.ref == 'refs/heads/next'
63+
# run: |
64+
# cd ../interface
65+
# git config --local user.email "[email protected]"
66+
# git config --local user.name "GitHub Action"
67+
# git add .
68+
# git diff-index --quiet HEAD || git commit -m "${{ github.event.head_commit.message }}"
69+
# git push origin $FRONTEND_BRANCH

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ The format is based on [Keep a Changelog], and this project adheres to [Semantic
88

99
### Fixed
1010

11+
- ci: Fixed dipdup package metadata.
12+
- cli: Generate base template from replay only when --base flag is set.
1113
- index: Remove Python limitation on large int<->str conversions.
1214
- index: Fixed crash when parsing typed transactions with empty parameter.
15+
- package: Don't create empty pyproject.toml during init.
16+
- package: Fixed discovery of the package when workdir is project root.
1317

1418
## [6.5.10] - 2023-08-02
1519

docs/0.quickstart.md

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,79 @@ This page will guide you through the steps to get your first selective indexer u
1010

1111
Let's create an indexer for the [tzBTC FA1.2 token contract](https://tzkt.io/KT1PWx2mnDueood7fEmfbBDKx1D9BAnnXitn/operations/). Our goal is to save all token transfers to the database and then calculate some statistics of its holders' activity.
1212

13-
`demo_token` demo is discussed in this guide; you can find it in the list of available templates when running `dipdup new` command.
13+
## Install DipDup
1414

1515
A modern Linux/macOS distribution with Python 3.11 installed is required to run DipDup.
1616

17-
## Create a new project
18-
19-
### Interactively (recommended)
20-
21-
You can initialize a hello-world project interactively by choosing configuration options in the terminal. The following command will install DipDup for the current user:
17+
We have a [convenient installer](https://dipdup.io/install.py) that will install DipDup and all the required dependencies for you. It uses pipx to install DipDup as a CLI application and make it available everywhere for the current user. Run the following command in your terminal:
2218

2319
```shell [Terminal]
2420
curl -Lsf https://dipdup.io/install.py | python3
2521
```
2622

27-
Now, let's create a new project:
23+
If you don't want to use our installer, create a new project directory you can install DipDup manually. You can use any Python package manager you like, but we recommend [PDM](https://pdm.fming.dev/latest/). Here are some spells to get you started:
2824

2925
```shell [Terminal]
30-
dipdup new
31-
```
26+
# pipx
27+
pipx install dipdup datamodel-code-generator pdm
3228

33-
Follow the instructions; the project will be created in the current directory. You can skip reading the rest of this page and slap `dipdup run` instead.
29+
# PDM
30+
pdm init --python 3.11
31+
pdm use .venv
32+
pdm add "dipdup>=7.0.0rc2,<8"
33+
$(pdm venv activate)
3434

35-
### From scratch
35+
# Poetry
36+
poetry init --python ">=3.11,<3.12"
37+
poetry add "dipdup>=7.0.0rc2,<8"
38+
poetry shell
3639

37-
If you don't want to use our installer, you can install DipDup manually. You can use any Python package manager you like, but we recommend [PDM](https://pdm.fming.dev/latest/).
40+
# pip + venv
41+
python -m venv .venv
42+
. .venv/bin/activate
43+
echo "dipdup>=7.0.0rc2,<8" > requirements.txt
44+
pip install -r requirements.txt -e .
45+
```
46+
47+
## Create a project
48+
49+
DipDup CLI has a built-in project generator. Run the following command in your terminal:
3850

3951
```shell [Terminal]
40-
# Create a new project directory
41-
mkdir {{ project.package }}; cd {{ project.package }}
52+
dipdup new
53+
```
4254

43-
# PDM
44-
pdm init --python ">=3.11,<3.12"
45-
pdm add dipdup
46-
pdm venv activate
55+
For educational purposes, we'll create a project from scratch, so choose `[none]` network and `demo_blank` template.
4756

48-
# Plain pip
49-
python -m venv .venv
50-
. .venv/bin/activate
51-
pip install dipdup
57+
::banner{type="note"}
58+
Want to skip a tutorial? Choose `Tezos` and `demo_token` instead!
59+
::
5260

53-
# or Poetry
54-
poetry init --python ">=3.11,<3.12"
55-
poetry add dipdup
56-
poetry shell
57-
```
61+
Follow the instructions; the project will be created in the new directory.
5862

5963
## Write a configuration file
6064

61-
DipDup configuration is stored in YAML files of a specific format. Create a new file named `dipdup.yaml` in the project root with the following content:
65+
In the project root, you'll find a file named `dipdup.yaml`. It's the main configuration file of your indexer. We will discuss it in detail in the [Config](1.getting_started/3.config.md) section; for now just replace its content with the following:
6266

6367
```yaml [dipdup.yaml]
6468
{{ #include ../src/demo_token/dipdup.yaml }}
6569
```
6670

6771
## Generate types and stubs
6872

69-
Now it's time to generate typeclasses and callback stubs. Run the following command:
73+
Now it's time to generate typeclasses and callback stubs based on definitions from config. Examples below use `demo_token` as a package name; yours may differ.
74+
75+
Run the following command:
7076

7177
```shell [Terminal]
7278
dipdup init
7379
```
7480

75-
DipDup will create a Python package `demo_token` having the following structure:
81+
DipDup will create a Python package `demo_token` with everything you need to start writing your indexer. Use `package tree` command to see the generated structure:
7682

77-
```shell
78-
demo_token [src/demo_token]
83+
```shell [Terminal]
84+
$ dipdup package tree
85+
demo_token [.]
7986
├── abi
8087
├── configs
8188
│ ├── dipdup.compose.yaml
@@ -108,24 +115,25 @@ demo_token [src/demo_token]
108115
│ ├── tzbtc/tezos_parameters/mint.py
109116
│ ├── tzbtc/tezos_parameters/transfer.py
110117
│ └── tzbtc/tezos_storage.py
111-
├── py.typed
112-
├── __init__.py
113-
└── pyproject.toml
118+
├── demo_token.py
119+
└── py.typed
114120
```
115121

116122
That's a lot of files and directories! But don't worry, we will need only `models` and `handlers` sections in this guide.
117123

118124
## Define data models
119125

120-
Our schema will consist of a single model `Holder` having several fields:
126+
DipDup supports storing data in SQLite, PostgreSQL and TimescaleDB databases. We use custom ORM based on Tortoise ORM as an abstraction layer.
127+
128+
First, you need to define a model class. Our schema will consist of a single model `Holder` with the following fields:
121129

122130
- `address` — account address
123-
- `balance`in tzBTC
124-
- `volume` — total transfer/mint amount bypassed
131+
- `balance`token amount held by the account
132+
- `volume` — total amount of transfer/mint calls
125133
- `tx_count` — number of transfers/mints
126134
- `last_seen` — time of the last transfer/mint
127135

128-
Put the following content in the `models/__init__.py` file:
136+
Here's how to implement this model in DipDup:
129137

130138
```python [models/__init__.py]
131139
{{ #include ../src/demo_token/models/__init__.py }}
@@ -153,7 +161,7 @@ Three methods of tzBTC contract can alter token balances — `transfer`, `mint`,
153161

154162
And that's all! We can run the indexer now.
155163

156-
## Next steps
164+
## Next steps
157165

158166
Run the indexer in-memory:
159167

@@ -176,4 +184,14 @@ cp .env.default .env
176184
docker-compose up
177185
```
178186

179-
DipDup will fetch all the historical data and then switch to realtime updates. Your application data has been successfully indexed!
187+
DipDup will fetch all the historical data and then switch to realtime updates. You can check the progress in the logs.
188+
189+
If you use SQLite, run a query to check the data:
190+
191+
```bash
192+
sqlite3 demo_token.sqlite 'SELECT * FROM holder LIMIT 10'
193+
```
194+
195+
If you run a Compose stack, check open `http://127.0.0.1:8080` in your browser to see the Hasura console (exposed port may differ). You can use it to explore the database and build GraphQL queries.
196+
197+
Congratulations! You've just created your first DipDup indexer. Proceed to the Getting Started section to learn in-depth about DipDup configuration and features.

docs/1.getting-started/1.installation.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,19 @@ Then use the snippets below to create a new Python project and add DipDup as a d
4646
PDM is a very powerful package manager with a lot of features. Also, it can run scripts from pyproject.toml as npm does. It's a good choice for both beginners and advanced users.
4747

4848
```shell [Terminal]
49-
pdm init --python ">=3.10,<3.11"
50-
pdm add dipdup
51-
pdm venv activate
49+
pdm init --python 3.11
50+
pdm use .venv
51+
pdm add "dipdup>=7.0.0rc2,<8"
52+
$(pdm venv activate)
5253
```
5354

5455
#### Poetry
5556

5657
Poetry is another popular tool to manage Python projects. It's less stable and often slower than PDM, but it's still a good choice.
5758

5859
```shell [Terminal]
59-
poetry init --python ">=3.10,<3.11"
60-
poetry add dipdup
60+
poetry init --python ">=3.11,<3.12"
61+
poetry add "dipdup>=7.0.0rc2,<8"
6162
poetry shell
6263
```
6364

@@ -68,7 +69,7 @@ Finally, if you prefer to do everything manually, you can use pip. It's the most
6869
```shell [Terminal]
6970
python -m venv .venv
7071
. .venv/bin/activate
71-
echo "dipdup~={{ project.dipdup_version }}" >> requirements.txt
72+
echo "dipdup>=7.0.0rc2,<8" >> requirements.txt
7273
pip install -r requirements.txt -e .
7374
```
7475

docs/1.getting-started/4.package.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ To generate all necessary directories and files according to config run the `ini
1111

1212
The structure of the resulting package is the following:
1313

14-
| Path | Description |
15-
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
16-
| :file_folder: `abi` | Contract ABIs used to generate typeclasses |
17-
| :file_folder: `configs` | Environment-specific configs to merge with the root one |
18-
| :file_folder: `deploy` | Dockerfiles, compose files, and default env variables for each environment |
19-
| :file_folder: `graphql` | Custom GraphQL queries to expose with Hasura engine |
20-
| :file_folder: `handlers` | User-defined callbacks to process contract data |
21-
| :file_folder: `hasura` | Arbitrary Hasura metadata to apply during configuration |
22-
| :file_folder: `hooks` | User-defined callbacks to run manually or by schedule |
23-
| :file_folder: `models` | DipDup ORM models to store data in the database |
24-
| :file_folder: `sql` | SQL scripts and queries to run manually or on specific events |
25-
| :file_folder: `types` | Automatically generated Pydantic dataclasses for contract types |
26-
| `dipdup.yaml` | Root DipDup config; can be expanded with env-specific files |
27-
| `pyproject.toml` | Python package metadata (introduced in PEP 518; see [details](https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/)) |
28-
| | |
14+
| Path | Description |
15+
| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
16+
| :file_folder: `abi` | Contract ABIs used to generate typeclasses |
17+
| :file_folder: `configs` | Environment-specific configs to merge with the root one |
18+
| :file_folder: `deploy` | Dockerfiles, compose files, and default env variables for each environment |
19+
| :file_folder: `graphql` | Custom GraphQL queries to expose with Hasura engine |
20+
| :file_folder: `handlers` | User-defined callbacks to process contract data |
21+
| :file_folder: `hasura` | Arbitrary Hasura metadata to apply during configuration |
22+
| :file_folder: `hooks` | User-defined callbacks to run manually or by schedule |
23+
| :file_folder: `models` | DipDup ORM models to store data in the database |
24+
| :file_folder: `sql` | SQL scripts and queries to run manually or on specific events |
25+
| :file_folder: `types` | Automatically generated Pydantic dataclasses for contract types |
26+
| `dipdup.yaml` | Root DipDup config; can be expanded with env-specific files |
27+
| `{{ project.package }}.py` | A little helper to let you import the package from the root directory. |
28+
| `pyproject.toml` | Python package metadata (introduced in PEP 518; see [details](https://pip.pypa.io/en/stable/reference/build-system/pyproject-toml/)) |
29+
| | |
2930

3031
There are also a bunch files in the root directory: .ignore files, PEP 561 marker, etc. Usually, you won't need to modify them.
3132

0 commit comments

Comments
 (0)