Skip to content

Commit fb067c8

Browse files
authored
Merge pull request #2 from questdb/ma/examples-only
Ma/examples only
2 parents a6ad1b0 + f6b80be commit fb067c8

File tree

6 files changed

+112
-29
lines changed

6 files changed

+112
-29
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ celerybeat.pid
107107
*.sage.py
108108

109109
# Environments
110+
.idea
110111
.env
111112
.venv
112113
env/

DEV_NOTES.rst

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,36 @@ Install Rust as per https://rustup.rs/.
1919
2020
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
2121
22-
Install Cython:
22+
Install your local Python3 environment **venv**
23+
24+
.. code-block:: bash
25+
26+
python3 -m venv venv
27+
venv/bin/python install -U pip
28+
venv/bin/python install -r dev_requirements.txt
29+
30+
# or simply:
31+
python3 proj.py venv
32+
33+
# either of the ^ ^ should be followed by:
34+
source venv/bin/activate
35+
36+
The development requirements are these if you prefer to install them one by one:
37+
38+
- Install Cython:
2339

2440
.. code-block:: bash
2541
2642
python3 -m pip install cython
2743
28-
Documentation
29-
-------------
44+
- Documentation
3045

3146
.. code-block:: bash
3247
3348
python3 -m pip install sphinx
3449
python3 -m pip install sphinx_rtd_theme
3550
36-
37-
Packaging and releasing
38-
-----------------------
51+
- Packaging and releasing
3952

4053
.. code-block:: bash
4154
@@ -87,7 +100,7 @@ MacOS Apple Silicon, run:
87100
.. code-block:: bash
88101
89102
python3 proj.py sdist # source distribution
90-
python3 proj.py cibuildwheel
103+
python3 proj.py cibuildwheel # the order of these two lines does not matter
91104
92105
This will end up putting everything in the ``dist/`` directory.
93106

dev_requirements.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
setuptools>=45.2.0
2+
Cython>=0.29.24
3+
wheel>=0.34.2
4+
cibuildwheel>=2.8.0
5+
Sphinx>=5.0.2
6+
sphinx-rtd-theme>=1.0.0
7+
twine>=4.0.1
8+
bump2version>=1.0.1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from questdb.ingress import Sender, Buffer, TimestampNanos
2+
3+
if __name__ == '__main__':
4+
with Sender('localhost', 9009) as sender:
5+
buffer = sender.new_buffer()
6+
buffer.row(
7+
'line_sender_buffer_example',
8+
symbols={'id': 'Hola'},
9+
columns={'price': '111222233333i', 'qty': 3.5},
10+
at=TimestampNanos(111222233333)
11+
)
12+
buffer.row(
13+
'line_sender_example',
14+
symbols={'id': 'Adios'},
15+
columns={'price': '111222233343i', 'qty': 2.5},
16+
at=TimestampNanos(111222233343)
17+
)
18+
# last line is not flushed
19+
sender.flush(buffer)

examples/line_sender_example.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from questdb.ingress import Sender
2+
3+
4+
# buffer.tabular(
5+
# # 'table_name',
6+
# # [['abc', 123, 3.14, 'xyz'],
7+
# # ['def', 456, 6.28, 'abc'],
8+
# # ['ghi', 789, 9.87, 'def']],
9+
# # header=['col1', 'col2', 'col3', 'col4'],
10+
# # symbols=True) # `col1` and `col4` are SYMBOL columns.
11+
def tabular(sender, table_name):
12+
pass
13+
14+
15+
if __name__ == '__main__':
16+
with Sender('localhost', 9009) as sender:
17+
sender.row(
18+
'line_sender_example',
19+
symbols={'id': 'OMEGA'},
20+
columns={'price': '111222233333i', 'qty': 3.5}
21+
)
22+
sender.row(
23+
'line_sender_example',
24+
symbols={'id': 'ZHETA'},
25+
columns={'price': '111222233330i', 'qty': 2.5}
26+
)
27+
sender.flush()

proj.py

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import sys
4+
45
sys.dont_write_bytecode = True
56
import os
67
import shutil
@@ -10,7 +11,6 @@
1011
import glob
1112
import platform
1213

13-
1414
PROJ_ROOT = pathlib.Path(__file__).parent
1515

1616

@@ -20,13 +20,12 @@ def _run(*args, env=None, cwd=None):
2020
On error, exit with child's return code.
2121
"""
2222
cwd = cwd or PROJ_ROOT
23-
args = [str(arg) for arg in args]
2423
sys.stderr.write('[CMD] ')
2524
if env is not None:
2625
env_str = ' '.join(f'{k}={shlex.quote(v)}' for k, v in env.items())
2726
sys.stderr.write(f'{env_str} ')
2827
env = {**os.environ, **env}
29-
escaped_cmd = ' '.join(shlex.quote(arg) for arg in args)
28+
escaped_cmd = ' '.join(shlex.quote(str(arg)) for arg in args)
3029
sys.stderr.write(f'{escaped_cmd}\n')
3130
ret_code = subprocess.run(args, cwd=str(cwd), env=env).returncode
3231
if ret_code != 0:
@@ -53,11 +52,11 @@ def _arg2bool(arg):
5352
return arg.lower() in ('true', 'yes', '1')
5453

5554

56-
COMMANDS = set()
55+
COMMANDS = []
5756

5857

5958
def command(fn):
60-
COMMANDS.add(fn.__name__)
59+
COMMANDS.append(fn.__name__)
6160
return fn
6261

6362

@@ -67,28 +66,28 @@ def build():
6766

6867

6968
@command
70-
def serve(port=None):
71-
port = port or 8000
72-
docs_dir = PROJ_ROOT / 'build' / 'docs'
73-
_run('python3', '-m', 'http.server', port, cwd=docs_dir)
69+
def test(all=False, patch_path='1', *args):
70+
env = {'TEST_QUESTDB_PATCH_PATH': patch_path}
71+
if _arg2bool(all):
72+
env['TEST_QUESTDB_INTEGRATION'] = '1'
73+
_run('python3', 'test/test.py', '-v', *args,
74+
env=env)
7475

7576

7677
@command
7778
def doc(http_serve=False, port=None):
7879
_run('python3', '-m', 'sphinx.cmd.build',
79-
'-b', 'html', 'docs', 'build/docs',
80-
env={'PYTHONPATH': str(PROJ_ROOT / 'src')})
80+
'-b', 'html', 'docs', 'build/docs',
81+
env={'PYTHONPATH': str(PROJ_ROOT / 'src')})
8182
if _arg2bool(http_serve):
8283
serve(port)
8384

8485

8586
@command
86-
def test(all=False, patch_path='1', *args):
87-
env = {'TEST_QUESTDB_PATCH_PATH': patch_path}
88-
if _arg2bool(all):
89-
env['TEST_QUESTDB_INTEGRATION'] = '1'
90-
_run('python3', 'test/test.py', '-v', *args,
91-
env=env)
87+
def serve(port=None):
88+
port = port or 8000
89+
docs_dir = PROJ_ROOT / 'build' / 'docs'
90+
_run('python3', '-m', 'http.server', port, cwd=docs_dir)
9291

9392

9493
@command
@@ -105,11 +104,16 @@ def cibuildwheel(*args):
105104
# Python version.
106105
python = '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3'
107106
_run(python, '-m',
108-
'cibuildwheel',
109-
'--platform', plat,
110-
'--output-dir', 'dist',
111-
'--archs', platform.machine(),
112-
*args)
107+
'cibuildwheel',
108+
'--platform', plat,
109+
'--output-dir', 'dist',
110+
'--archs', platform.machine(),
111+
*args)
112+
113+
114+
@command
115+
def cw(*args):
116+
cibuildwheel(args)
113117

114118

115119
@command
@@ -133,6 +137,17 @@ def clean():
133137
_rm(PROJ_ROOT / 'src', '**/*.html')
134138

135139

140+
@command
141+
def venv():
142+
if pathlib.Path('venv').exists():
143+
sys.stderr.write('venv already exists, delete it, or run command clean\n')
144+
return
145+
_run('python3', '-m', 'venv', 'venv')
146+
_run('venv/bin/python3', '-m', 'pip', 'install', '-U', 'pip')
147+
_run('venv/bin/python3', '-m', 'pip', 'install', '-r', 'dev_requirements.txt')
148+
sys.stdout.write('NOTE: remember to activate the environment: source venv/bin/activate\n')
149+
150+
136151
def main():
137152
if len(sys.argv) < 2:
138153
sys.stderr.write('Usage: python3 proj.py <command>\n')

0 commit comments

Comments
 (0)