diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml new file mode 100644 index 0000000..bd4c333 --- /dev/null +++ b/.github/workflows/build-test.yaml @@ -0,0 +1,52 @@ +name: PR Checks + +on: + pull_request: + types: [opened, synchronize, reopened, edited, ready_for_review] + push: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:latest + env: + POSTGRES_PASSWORD: "postgres" + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + ports: + - "5432:5432" + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.9" + cache: "pip" + + - name: Install Python Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt -e .[dev] + + # temporarily don't fail on pylint failures so they can be fixed later + - name: Lint with pylint + run: pylint --disable=C0115,C0116,C0104,C0114,W0511 src tests || true + + - name: Check with flake8 + run: flake8 + + - name: Check import sorting + run: isort --check-only -p savage -p tests . + + - name: Check black formatting + run: black --check --line-length=100 src tests + + - name: Run all tests + run: pytest --cov=. tests diff --git a/Makefile b/Makefile index 7e95b59..a127f09 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ default: install lint tests # ---- Install ---- venv: - # Create a local virtual environment in `venv/` + # Use Python 3.9 for local development python -mvenv $(VENV_DIR) install: venv diff --git a/setup.py b/setup.py index 081f2a8..0f3ce3b 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ test_requires = ["pytest", "pytest-cov", "pytest-mock"] dev_requires = test_requires + [ "autopep8>=1.4.4", - "black>=23", + "black>=23.12.1", "flake8", "ipython", "isort>=4.3.21", diff --git a/src/savage/api/data.py b/src/savage/api/data.py index f212fe6..10e6e52 100644 --- a/src/savage/api/data.py +++ b/src/savage/api/data.py @@ -276,8 +276,7 @@ def _get_latest_time_slice(table, session, conds, include_deleted, limit, offset def _get_limit_and_offset(page, page_size): - """Returns a 0-indexed offset and limit based on page and page_size for a MySQL query. - """ + """Returns a 0-indexed offset and limit based on page and page_size for a MySQL query.""" if page < 1: raise ValueError("page must be >= 1") limit = page_size diff --git a/tests/db_utils.py b/tests/db_utils.py index 259a6d0..e6efda3 100644 --- a/tests/db_utils.py +++ b/tests/db_utils.py @@ -6,7 +6,7 @@ from psycopg2 import connect from sqlalchemy.orm import sessionmaker -PG_CONFIG = dict(user="postgres", password="", host="localhost", port=5543) +PG_CONFIG = dict(user="postgres", password="postgres", host="localhost", port=5432) CI_PG_CONFIG = dict(PG_CONFIG, port=5432) MASTER_DATABASE = "postgres" diff --git a/tests/test_api.py b/tests/test_api.py index 568af46..f6a473b 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -276,8 +276,7 @@ def test_get_products_after_version(session, user_table, get_api_test_setup): def test_fields_query(session, user_table, get_api_test_setup): - """Test specifying fields and make sure dedup happens correctly. - """ + """Test specifying fields and make sure dedup happens correctly.""" p1_history, p2_history, p3_history = get_api_test_setup conds = [{"product_id": 10}] @@ -329,8 +328,7 @@ def test_fields_query(session, user_table, get_api_test_setup): def test_failure_conditions(session, user_table, get_api_test_setup): - """Pass invalid conds arguments and ensure the query fails. - """ + """Pass invalid conds arguments and ensure the query fails.""" conds = [{"product_id": 10, "foo": 15}] with pytest.raises(ValueError): get(user_table, session, t1=datetime.utcfromtimestamp(31), conds=conds)