Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit e060d44

Browse files
authored
AP-1039 Revamp CI (#54)
1 parent 53b4bbf commit e060d44

File tree

10 files changed

+153
-146
lines changed

10 files changed

+153
-146
lines changed

.circleci/config.yml

Lines changed: 0 additions & 65 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
lint_and_test:
11+
name: Linting and Testing
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python-version: [ 3.6, 3.7, 3.8 ]
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v2
20+
21+
- name: Start PG test container
22+
run: docker-compose up -d --build db
23+
24+
- name: Set up Python ${{ matrix.python-version }}
25+
uses: actions/setup-python@v2
26+
with:
27+
python-version: ${{ matrix.python-version }}
28+
29+
- name: Setup virtual environment
30+
run: make venv
31+
32+
- name: Pylinting
33+
run: make pylint
34+
35+
- name: Unit Tests
36+
run: make unit_test
37+
38+
- name: Integration Tests
39+
env:
40+
LOGGING_CONF_FILE: ./sample_logging.conf
41+
run: make integration_test
42+
43+
- name: Shutdown PG test container
44+
run: docker-compose down

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
venv:
2+
python3 -m venv venv ;\
3+
. ./venv/bin/activate ;\
4+
pip install --upgrade pip setuptools wheel ;\
5+
pip install -e .[test]
6+
7+
pylint:
8+
. ./venv/bin/activate ;\
9+
pylint --rcfile .pylintrc target_postgres/
10+
11+
unit_test:
12+
. ./venv/bin/activate ;\
13+
pytest --cov=target_postgres --cov-fail-under=44 tests/unit -v
14+
15+
env:
16+
export TARGET_POSTGRES_PORT=5432
17+
export TARGET_POSTGRES_DBNAME=target_db
18+
export TARGET_POSTGRES_USER=my_user
19+
export TARGET_POSTGRES_PASSWORD=secret
20+
export TARGET_POSTGRES_HOST=localhost
21+
export TARGET_POSTGRES_SCHEMA=public
22+
23+
integration_test: env
24+
. ./venv/bin/activate ;\
25+
pytest tests/integration --cov=target_postgres --cov-fail-under=87 -v

README.md

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,43 @@ installation instructions for [Mac](http://docs.python-guide.org/en/latest/start
2323
It's recommended to use a virtualenv:
2424

2525
```bash
26-
python3 -m venv venv
27-
pip install pipelinewise-target-postgres
28-
```
29-
30-
or
31-
32-
```bash
33-
python3 -m venv venv
34-
. venv/bin/activate
35-
pip install --upgrade pip
36-
pip install .
26+
make venv
3727
```
3828

3929
### To run
4030

41-
Like any other target that's following the singer specificiation:
31+
Like any other target that's following the singer specification:
4232

4333
`some-singer-tap | target-postgres --config [config.json]`
4434

45-
It's reading incoming messages from STDIN and using the properites in `config.json` to upload data into Postgres.
35+
It's reading incoming messages from STDIN and using the properties in `config.json` to upload data into Postgres.
4636

4737
**Note**: To avoid version conflicts run `tap` and `targets` in separate virtual environments.
4838

49-
### Configuration settings
5039

51-
Running the the target connector requires a `config.json` file. An example with the minimal settings:
40+
#### Spin up a PG DB
41+
42+
Make use of the available docker-compose file to spin up a PG DB.
5243

53-
```json
54-
{
55-
"host": "localhost",
56-
"port": 5432,
57-
"user": "my_user",
58-
"password": "secret",
59-
"dbname": "my_db_name",
60-
"default_target_schema": "my_target_schema"
61-
}
62-
```
44+
```bash
45+
docker-compose up -d --build db
46+
```
47+
48+
49+
### Configuration settings
50+
51+
Running the target connector requires a `config.json` file. An example with the minimal settings:
52+
53+
```json
54+
{
55+
"host": "localhost",
56+
"port": 5432,
57+
"user": "my_user",
58+
"password": "secret",
59+
"dbname": "target_db",
60+
"default_target_schema": "public"
61+
}
62+
```
6363

6464
Full list of options in `config.json`:
6565

@@ -96,33 +96,29 @@ Full list of options in `config.json`:
9696
export TARGET_POSTGRES_SCHEMA=<postgres-schema>
9797
```
9898

99-
2. Install python dependencies in a virtual env and run nose unit and integration tests
99+
**PS**: You can run `make env` to export pre-defined environment variables
100+
101+
102+
2. Install python dependencies in a virtual env and run unit and integration tests
100103
```
101-
python3 -m venv venv
102-
. venv/bin/activate
103-
pip install --upgrade pip
104-
pip install .[test]
104+
make venv
105105
```
106106

107107
3. To run unit tests:
108108
```
109-
nosetests --where=tests/unit
109+
make unit_test
110110
```
111111

112112
4. To run integration tests:
113113
```
114-
nosetests --where=tests/integration
114+
make integration_test
115115
```
116116

117117
### To run pylint:
118118

119119
1. Install python dependencies and run python linter
120120
```
121-
python3 -m venv venv
122-
. venv/bin/activate
123-
pip install --upgrade pip
124-
pip install .[test]
125-
pylint --rcfile .pylintrc --disable duplicate-code target_postgres/
121+
make venv pylint
126122
```
127123

128124
## License

docker-compose.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: "3"
2+
3+
services:
4+
db:
5+
image: postgres:12-alpine
6+
environment:
7+
POSTGRES_DB: "target_db"
8+
POSTGRES_USER: "my_user"
9+
POSTGRES_PASSWORD: "secret"
10+
ports:
11+
- 5432:5432

requirements.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

setup.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup
44

55
with open('README.md') as f:
6-
long_description = f.read()
6+
long_description = f.read()
77

88
setup(name="pipelinewise-target-postgres",
99
version="2.1.1",
@@ -25,17 +25,16 @@
2525
],
2626
extras_require={
2727
"test": [
28-
'nose==1.3.7',
29-
'mock==3.0.5',
30-
'pylint==2.4.4',
31-
'nose-cov==1.6'
32-
]
28+
'pytest==6.2.1',
29+
'pylint==2.6.0',
30+
'pytest-cov==2.10.1',
31+
]
3332
},
3433
entry_points="""
3534
[console_scripts]
3635
target-postgres=target_postgres:main
3736
""",
3837
packages=["target_postgres"],
39-
package_data = {},
38+
package_data={},
4039
include_package_data=True,
41-
)
40+
)

target_postgres/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def persist_lines(config, lines) -> None:
9494
stream_to_sync = {}
9595
total_row_count = {}
9696
batch_size_rows = config.get('batch_size_rows', DEFAULT_BATCH_SIZE_ROWS)
97-
parallelism = config.get("parallelism", -1)
9897

9998
# Loop over lines from stdin
10099
for line in lines:
@@ -127,8 +126,9 @@ def persist_lines(config, lines) -> None:
127126
raise InvalidValidationOperationException(
128127
f"Data validation failed and cannot load to destination. RECORD: {o['record']}\n"
129128
"multipleOf validations that allows long precisions are not supported (i.e. with 15 digits"
130-
"or more) Try removing 'multipleOf' methods from JSON schema.")
131-
raise RecordValidationException(f"Record does not pass schema validation. RECORD: {o['record']}")
129+
"or more) Try removing 'multipleOf' methods from JSON schema.") from ex
130+
raise RecordValidationException(
131+
f"Record does not pass schema validation. RECORD: {o['record']}") from ex
132132

133133
primary_key_string = stream_to_sync[stream].record_primary_key_string(o['record'])
134134
if not primary_key_string:

0 commit comments

Comments
 (0)