11.ONESHELL :
22ENV_PREFIX =$(shell python -c "if __import__('pathlib') .Path('.venv/bin/pip').exists(): print('.venv/bin/')")
3+ USING_POETRY =$(shell grep "tool.poetry" pyproject.toml && echo "yes")
34
45.PHONY : help
56help : # # Show the help.
@@ -12,14 +13,16 @@ help: ## Show the help.
1213.PHONY : show
1314show : # # Show the current environment.
1415 @echo " Current environment:"
16+ @if [ " $( USING_POETRY) " ]; then poetry env info && exit ; fi
1517 @echo " Running using $( ENV_PREFIX) "
1618 @$(ENV_PREFIX ) python -V
1719 @$(ENV_PREFIX ) python -m site
1820
1921.PHONY : install
2022install : # # Install the project in dev mode.
23+ @if [ " $( USING_POETRY) " ]; then poetry install && exit ; fi
2124 @echo " Don't forget to run 'make virtualenv' if you got errors."
22- @if [ ! -f pyproject.toml ] ; then $(ENV_PREFIX ) pip install -e .[test]; else poetry install --dev ; fi
25+ $(ENV_PREFIX ) pip install -e .[test]
2326
2427.PHONY : fmt
2528fmt : # # Format code using black & isort.
@@ -62,6 +65,7 @@ clean: ## Clean unused files.
6265
6366.PHONY : virtualenv
6467virtualenv : # # Create a virtual environment.
68+ @if [ " $( USING_POETRY) " ]; then poetry install && exit ; fi
6569 @echo " creating virtualenv ..."
6670 @rm -rf .venv
6771 @python3 -m venv .venv
@@ -94,12 +98,18 @@ switch-to-poetry: ## Switch to poetry package manager.
9498 @echo " Switching to poetry ..."
9599 @if ! poetry --version > /dev/null; then echo ' poetry is required, install from https://python-poetry.org/' ; exit 1; fi
96100 @rm -rf .venv
97- @poetry init --name=project_name --author=author_name
98- @for item in $(cat requirements.txt ) ; do poetry add " ${item} " ; done
99- @for item in $(cat requirements-test.txt ) ; do poetry add --dev " ${item} " ; done
100- @poetry install
101+ @poetry init --no-interaction --name=a_flask_test --author=rochacbruno
102+ @echo " " >> pyproject.toml
103+ @echo " [tool.poetry.scripts]" >> pyproject.toml
104+ @echo " project_name = 'project_name.__main__:main'" >> pyproject.toml
105+ @cat requirements.txt | while read in ; do poetry add --no-interaction " $$ {in}" ; done
106+ @cat requirements-test.txt | while read in ; do poetry add --no-interaction " $$ {in}" --dev; done
107+ @poetry install --no-interaction
108+ @mkdir -p .github/backup
109+ @mv requirements* .github/backup
110+ @mv setup.py .github/backup
101111 @echo " You have switched to https://python-poetry.org/ package manager."
102- @echo " Run ` poetry shell` "
112+ @echo " Please run ' poetry shell' or 'poetry run project_name' "
103113
104114.PHONY : init
105115init : # # Initialize the project based on an application template.
0 commit comments