Skip to content

Commit

Permalink
chore(makefile): poetry in venv
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-ardouin committed Jan 10, 2022
1 parent 36f2f69 commit ddd9446
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -38,10 +38,10 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'

- name: Check the code quality
run: make check-code-quality
run: POETRY=poetry make check-code-quality

- name: Check if the code is correctly typed
run: make check-types
run: POETRY=poetry make check-types

Tests:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'

- name: Run the test suite
run: make test
run: POETRY=poetry make test

- name: Upload coverage to Codecov
if: matrix.python-version == 3.7
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi-publish.yml
Expand Up @@ -64,10 +64,10 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Build doc
run: make docs
run: POETRY=poetry make docs

- name: Publish doc
uses: peaceiris/actions-gh-pages@068dc23d9710f1ba62e86896f84735d869951305
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
publish_dir: ./site
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -22,6 +22,7 @@ http_cache.sqlite
# virtualenv
env/
venv/
.venv/


# doc
Expand Down
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Expand Up @@ -10,10 +10,16 @@ First install dependencies and setup pre-commits hooks
make setup
```

To setup using a different version of python, you may use the following:

```bash
PYTHON=python3.X make setup
```

Then to go in the poetry virtual env do

```
poetry shell
source .venv/bin/activate
```

You can run `make help` to see all available actions !
Expand Down
65 changes: 23 additions & 42 deletions Makefile
@@ -1,26 +1,24 @@
.DEFAULT_GOAL := help
.PHONY: check check-code-quality check-docs check-types clean docs-cp docs docs-serve docs-deploy help format setup test

PY_SRC := lumapps/
CI ?= false
TESTING ?= false
PYTHON ?= python3.7
PIP = .venv/bin/pip
POETRY ?= .venv/bin/poetry

.PHONY: check
check: check-docs check-code-quality check-types ## Check it all!

.PHONY: check-code-quality
check-code-quality: ## Check the code quality.
@poetry run failprint -t "Checking code quality" -- flake8 --config=config/flake8.ini $(PY_SRC)
@$(POETRY) run failprint -t "Checking code quality" -- flake8 --config=config/flake8.ini $(PY_SRC)


.PHONY: check-docs
check-docs: ## Check if the documentation builds correctly.
@poetry run failprint -t "Building documentation" -- mkdocs build -s
@$(POETRY) run failprint -t "Building documentation" -- mkdocs build -s

.PHONY: check-types
check-types: ## Check that the code is correctly typed.
@poetry run failprint -t "Type-checking" -- mypy --config-file config/mypy.ini $(PY_SRC)
@$(POETRY) run failprint -t "Type-checking" -- mypy --config-file config/mypy.ini $(PY_SRC)

.PHONY: clean
clean: ## Delete temporary files.
@rm -rf build 2>/dev/null
@rm -rf .coverage* 2>/dev/null
Expand All @@ -33,54 +31,37 @@ clean: ## Delete temporary files.
@rm -rf tests/__pycache__ 2>/dev/null
@find . -name "*.rej" -delete 2>/dev/null

.PHONY: docs-cp
docs-cp:
cp README.md docs/index.md
cp LICENSE.md docs/

.PHONY: docs
docs: docs-cp ## Build the documentation locally.
@poetry run mkdocs build
@$(POETRY) run mkdocs build

.PHONY: docs-serve
docs-serve: docs-cp ## Serve the documentation (localhost:8000).
@poetry run mkdocs serve
@$(POETRY) run mkdocs serve

.PHONY: docs-deploy
docs-deploy: docs-cp ## Deploy the documentation on GitHub pages.
@poetry run mkdocs gh-deploy
@$(POETRY) run mkdocs gh-deploy

.PHONY: help
help: ## Print this help.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort

.PHONY: format
format: ## Run formatting tools on the code.
@poetry run failprint -t "Formatting code" -- black $(PY_SRC)
@poetry run failprint -t "Ordering imports" -- isort -y -rc $(PY_SRC)

@$(POETRY) run failprint -t "Formatting code" -- black $(PY_SRC)
@$(POETRY) run failprint -t "Ordering imports" -- isort -y -rc $(PY_SRC)

.PHONY: setup
setup: ## Setup the development environment (install dependencies).
@if ! $(CI); then \
if ! command -v pipx &>/dev/null; then \
pip install pipx; \
fi; \
if ! command -v poetry &>/dev/null; then \
pipx install poetry; \
fi; \
fi; \
poetry config virtualenvs.in-project true
poetry install -v
@if ! $(CI); then \
poetry run pre-commit install; \
poetry run pre-commit install --hook-type commit-msg; \
fi; \
setup: .venv ## Setup the development environment (install dependencies).
$(POETRY) config virtualenvs.in-project true
$(POETRY) install -v
$(POETRY) run pre-commit install
$(POETRY) run pre-commit install --hook-type commit-msg


.PHONY: test
test: ## Run the test suite and report coverage. 2>/dev/null
@poetry run pytest -c config/pytest.ini
@poetry run coverage html --rcfile=config/coverage.ini

@$(POETRY) run pytest -c config/pytest.ini
@$(POETRY) run coverage html --rcfile=config/coverage.ini

.venv: ## Install the virtual env directory
$(PYTHON) -m venv .venv
$(PIP) install --quiet --upgrade pip
$(PIP) install poetry
2 changes: 1 addition & 1 deletion config/mypy.ini
Expand Up @@ -2,4 +2,4 @@
ignore_missing_imports = true

[mypy-lumapps.api.client]
ignore_errors = True
ignore_errors = true
12 changes: 12 additions & 0 deletions docs/CONTRIBUTING.md
Expand Up @@ -10,6 +10,18 @@ First install dependencies and setup pre-commits hooks
make setup
```

To setup using a different version of python, you may use the following:

```bash
PYTHON=python3.X make setup
```

Then to go in the poetry virtual env do

```
source .venv/bin/activate
```

You can run `make help` to see all available actions !

### Adding a new dependency
Expand Down

0 comments on commit ddd9446

Please sign in to comment.