Skip to content

Commit

Permalink
make: Dev reqs are now in isolation [BF-1560]
Browse files Browse the repository at this point in the history
This makes sure that the tests can run in their own environment, without affecting the system deps, while still using the system deps.
  • Loading branch information
Samuel Giffard committed Apr 4, 2023
1 parent 09a15b1 commit 9a0abae
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 28 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ jobs:
python-version: ${{ matrix.python-version }}

- id: dependencies
run: |
pip install -e .
pip install -r requirements.dev.txt
run: make local-install

- id: mypy
run: make mypy
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ coverage.xml
rpm/
dist/

.venv-test/

# Generated targets
pglookout-rpm-src.tar
58 changes: 34 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ short_ver = 2.1.0
long_ver = $(shell git describe --long 2>/dev/null || echo $(short_ver)-0-unknown-g`git describe --always`)
generated = pglookout/version.py

VENV = .venv-test
VENV_PYTHON = $(VENV)/bin/python
PYTHON ?= python3
PYTHON_SOURCE_DIRS = pglookout/ test/ stubs/ version.py setup.py

Expand All @@ -11,35 +13,45 @@ all: $(generated)
pglookout/version.py: version.py
$(PYTHON) $^ $@

test: mypy flake8 pylint unittest
# This venv is only used for tests and development. It has access to system site packages, because pglookout
# would need them to run. Development deps are kept in this venv, so that they don't interfere with the
# system python.
$(VENV):
$(PYTHON) -m venv --system-site-packages $(VENV)
$(VENV)/bin/pip install -r requirements.dev.txt

unittest: $(generated)
$(PYTHON) -m pytest
local-install: $(VENV)
$(VENV_PYTHON) -m pip install -e .

mypy: $(generated)
MYPYPATH=stubs $(PYTHON) -m mypy
test: mypy flake8 pylint unittest fmt-check

flake8: $(generated)
$(PYTHON) -m flake8 $(PYTHON_SOURCE_DIRS)
unittest: $(generated) $(VENV)
$(VENV_PYTHON) -m pytest

pylint: $(generated)
$(PYTHON) -m pylint $(PYTHON_SOURCE_DIRS)
mypy: $(generated) $(VENV)
MYPYPATH=stubs $(VENV_PYTHON) -m mypy

fmt: $(generated)
isort $(PYTHON_SOURCE_DIRS)
black $(PYTHON_SOURCE_DIRS)
flake8: $(generated) $(VENV)
$(VENV_PYTHON) -m flake8 $(PYTHON_SOURCE_DIRS)

fmt-check: $(generated)
isort --check $(PYTHON_SOURCE_DIRS)
black --check $(PYTHON_SOURCE_DIRS)
pylint: $(generated) $(VENV)
$(VENV_PYTHON) -m pylint $(PYTHON_SOURCE_DIRS)

coverage:
$(PYTHON) -m pytest $(PYTEST_ARG) --cov-report term-missing --cov-branch \
fmt: $(generated) $(VENV)
$(VENV_PYTHON) -m isort $(PYTHON_SOURCE_DIRS)
$(VENV_PYTHON) -m black $(PYTHON_SOURCE_DIRS)

fmt-check: $(generated) $(VENV)
$(VENV_PYTHON) -m isort --check $(PYTHON_SOURCE_DIRS)
$(VENV_PYTHON) -m black --check $(PYTHON_SOURCE_DIRS)

coverage: $(VENV)
$(VENV_PYTHON) -m pytest $(PYTEST_ARG) --cov-report term-missing --cov-branch \
--cov-report xml:coverage.xml --cov pglookout test/

clean:
$(RM) -r *.egg-info/ build/ dist/
$(RM) ../pglookout_* test-*.xml $(generated)
$(RM) -r *.egg-info/ build/ dist/ $(VENV) .hypothesis
$(RM) ../pglookout_* test-*.xml $(generated) .coverage coverage.xml

deb: $(generated)
cp debian/changelog.in debian/changelog
Expand All @@ -59,15 +71,13 @@ rpm: $(generated)

build-dep-fed:
sudo dnf -y install --best --allowerasing \
python3-devel python3-pytest python3-pylint \
python3-mock python3-psycopg2 \
python3-requests rpm-build systemd-python3 \
python3-flake8 python3-pytest-cov python3-packaging
python3-devel python3-psycopg2 python3-requests \
rpm-build systemd-python3 python3-packaging

build-dep-deb:
sudo apt-get install \
build-essential devscripts dh-systemd \
python3-all python3-setuptools python3-psycopg2 python3-requests \
python3-packaging

.PHONY: rpm
.PHONY: rpm local-install
1 change: 0 additions & 1 deletion pglookout.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Source0: pglookout-rpm-src.tar
Obsoletes: python3-pglookout
Requires: python3-packaging, python3-psycopg2, python3-requests, python3-setuptools, systemd-python3, systemd
BuildRequires: python3-packaging, python3-psycopg2, python3-requests, python3-setuptools, systemd-python3, systemd
BuildRequires: python3-pytest, python3-pylint
BuildArch: noarch

%description
Expand Down
1 change: 1 addition & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ types-requests==2.28.11.16
types-setuptools==67.6.0.5
pylint==2.17.1
pytest==7.2.2
pytest-cov==4.0.0

0 comments on commit 9a0abae

Please sign in to comment.