Skip to content

Commit

Permalink
chore(build): use poetry to manage deps
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Nov 13, 2024
1 parent e3170dd commit c86fda7
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:
with:
python-version: '3.11'
architecture: 'x64'
- run: pip install -r requirements.txt
- run: make install
- run: source $(shell poetry env info --path)/bin/activate
- name: Test pactflow-example-consumer-python against ${{ matrix.pact_provider }}
run: make test
env:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ build/
pacts/
logs/
*.log
.venv
.venv
poetry.lock
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example-consumer-python
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,45 @@ test_github_webhook:

.env:
touch .env

## ======================
## Python additions
## ======================
PROJECT := example-consumer-python
PYTHON_MAJOR_VERSION := 3.11

sgr0 := $(shell tput sgr0)
red := $(shell tput setaf 1)
green := $(shell tput setaf 2)

install: deps

deps:
pip3 install poetry
poetry install

activate:
. $(shell poetry env info --path)/bin/activate

venv:
@if [ -d "./.venv" ]; then echo "$(red).venv already exists, not continuing!$(sgr0)"; exit 1; fi
@type pyenv >/dev/null 2>&1 || (echo "$(red)pyenv not found$(sgr0)"; exit 1)

@echo "\n$(green)Try to find the most recent minor version of the major version specified$(sgr0)"
$(eval PYENV_VERSION=$(shell pyenv install -l | grep "\s\s$(PYTHON_MAJOR_VERSION)\.*" | tail -1 | xargs))
@echo "$(PYTHON_MAJOR_VERSION) -> $(PYENV_VERSION)"

@echo "\n$(green)Install the Python pyenv version if not already available$(sgr0)"
pyenv install $(PYENV_VERSION) -s

@echo "\n$(green)Make a .venv dir$(sgr0)"
~/.pyenv/versions/${PYENV_VERSION}/bin/python3 -m venv ${CURDIR}/.venv

@echo "\n$(green)Make it 'available' to pyenv$(sgr0)"
ln -sf ${CURDIR}/.venv ~/.pyenv/versions/${PROJECT}

@echo "\n$(green)Use it! (populate .python-version)$(sgr0)"
pyenv local ${PROJECT}

run:
python3 run.py
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tool.poetry]
name = "example-consumer-python"
version = "0.0.0"
description = "Example Python Consumer"
license = "MIT"
authors = ["Matt Fellows <[email protected]>", "Yousaf Nabi <[email protected]>"]
readme = 'README.md'
repository = "https://github.com/pactflow/example-consumer-python"
homepage = "https://github.com/pactflow/example-consumer-python"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.dependencies]
python = "^3.11"
Flask = "2.3.2"
requests = "2.28.0"

[tool.poetry.dev-dependencies]
pytest = "8.3.3"
pact-python = "^2.2.2"
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Flask==1.1.1
pytest==6.2.5
Flask==2.3.2
requests==2.28.0
pytest==6.2.5
pact_python==2.2.2

0 comments on commit c86fda7

Please sign in to comment.