Skip to content

Commit ee73c98

Browse files
authored
Merge pull request #92 from aaxelb/10311-osf-extract
[ENG-10311] improvements from osf-metrics (and more)
2 parents e3d3b42 + 22c384e commit ee73c98

36 files changed

Lines changed: 1518 additions & 639 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ var/
2828
pip-log.txt
2929
pip-delete-this-directory.txt
3030

31+
# mypy
32+
.dmypy.json
33+
3134
# Unit test / coverage reports
3235
htmlcov/
3336
.tox/

.konchrc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ from django.conf import settings
77
from django.utils.termcolors import colorize
88
from django.apps import apps
99
import konch
10-
import elasticsearch_dsl
11-
from elasticsearch_dsl import connections, Search
10+
import elasticsearch8
1211

13-
from elasticsearch_metrics.registry import registry
12+
from elasticsearch_metrics.registry import djelme_registry
1413
from elasticsearch_metrics.management.color import color_style
1514

1615

@@ -19,9 +18,9 @@ from elasticsearch_metrics.management.color import color_style
1918
# 'context_format', 'ipy_extensions', 'ipy_autoreload',
2019
# 'ipy_colors', 'ipy_highlighting_style'
2120
context = {
22-
"dsl": elasticsearch_dsl,
23-
"Search": Search,
24-
"registry": registry,
21+
"dsl": elasticsearch8.dsl,
22+
"Search": elasticsearch8.dsl.Search,
23+
"registry": djelme_registry,
2524
"apps": apps,
2625
"settings": settings,
2726
"style": color_style(),
@@ -41,10 +40,11 @@ def setup():
4140
# Set up django and add the default elasticsearch-py client and Metric to the context
4241
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "elasticsearch_metrics.tests.settings")
4342
django.setup()
44-
from elasticsearch_metrics.metrics import Metric
43+
from elasticsearch_metrics.imps.elastic8 import EventRecord, CyclicRecord
4544

46-
context["client"] = connections.get_connection()
47-
context["Metric"] = Metric
45+
context["client"] = elasticsearch8.dsl.connections.get_connection()
46+
context["EventRecord"] = EventRecord
47+
context["CyclicRecord"] = CyclicRecord
4848
konch.config({"context": context})
4949

5050

CONTRIBUTING.md

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,51 @@
11
# Contributing
22
(TODO: update)
33

4-
## Setting up for development
4+
## Code conventions
55

6-
* Create and activate a new virtual environment
7-
* `pip install -e '.[dev]'`
8-
* Install django: `pip install django`
9-
* (Optional but recommended) Run elasticsearch: `docker-compose up`
106

11-
* Run tests and checks:
7+
## Setting up local devloop
128

9+
### 0. get the code
10+
for example:
1311
```
14-
# Run all tests (requires elasticsearch to be running)
15-
python3 -m elasticsearch_metrics.tests
12+
git clone https://github.com/CenterForOpenScience/django-elasticsearch-metrics.git djelme
13+
cd djelme
1614
```
15+
16+
### 1. put environment together
17+
create and activate a [python virtual environment](https://docs.python.org/3.14/tutorial/venv.html)
18+
with python version 3.10+ -- there are many tools for this; you may already have your own way.
19+
20+
here's an example using `venv` (in python's standard lib) to create the virtual environment in a `.venv` directory, with bash:
1721
```
18-
# Run only linting (not tests)
19-
python3 -m elasticsearch_metrics.tests --lint
22+
python -m venv .venv && source .venv/bin/activate
2023
```
24+
25+
install dependencies (listed in `pyproject.toml`), including the `dev` extra (and maybe `anydjango`) -- here's an example using `pip`:
2126
```
22-
# Run only tests (not linting)
23-
python3 -m elasticsearch_metrics.tests --test
27+
pip install -e '.[dev,anydjango]'
2428
```
2529

26-
* Run the shell with:
30+
### Run tests and checks
31+
32+
these expect elasticsearches to be running and configured in `elasticsearch_metrics/tests/settings.py` (or set environment variables `ELASTICSEARCH6_URL` and `ELASTICSEARCH8_URL`) -- see `using docker-style container tools`, below, for one way to do that
33+
34+
running the python module `elasticsearch_metrics.tests` will run tests and linting checks
35+
-- should always pass before merging to `main`
36+
37+
```
38+
python -m elasticsearch_metrics.tests
39+
```
40+
optional args:
41+
- `--devloop`: adds `--failfast --pdb` to test args
42+
- `--coverage`: print code coverage report
43+
- `--test`: run only tests (not linting)
44+
- `--lint`: run only linting checks (not tests)
45+
46+
see `elasticsearch_metrics/tests/__main__.py` for more details
47+
48+
### Run the shell with:
2749

2850
```
2951
konch allow
@@ -43,3 +65,23 @@ Run the tests with tox:
4365
```
4466
tox
4567
```
68+
69+
### (optional) using docker-style container tools
70+
see `testbox.Containerfile` and `docker-compose.yml` -- running `testbox` runs `python -m elasticsearch_metrics.tests`
71+
72+
(note: examples use `pc` aliased to a `docker-compose` equivalent)
73+
74+
start elasticsearches in the background
75+
```
76+
pc up -d elasticsearch6 elasticsearch8
77+
```
78+
79+
run tests and lint
80+
```
81+
pc up testbox
82+
```
83+
84+
example devloop -- use current code, debugger on error, stop on failure
85+
```
86+
pc run --build --rm --no-deps testbox poetry run python -m elasticsearch_metrics.tests --devloop
87+
```

0 commit comments

Comments
 (0)