britodfbr

Makefile_v2

Dec 10th, 2021 (edited)
1,340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .DEFAULT_GOAL := help
  2. DIRECTORIES = $$(find -wholename ./src -o -wholename ./incolumepy -o -wholename ./tests)
  3. PKGNAME = 'incolumepy'
  4. REPORT_DIR = 'coverage_report'
  5. PYTHON_VERSION := 3.10
  6. URLCOMPARE := 'https://github.com/incolumepy-prospections/incolumepy.dataclass/compare/'
  7. CHANGELOGFILE := 'CHANGELOG.md'
  8.  
  9. .PHONY: black
  10. black:   ##Apply code style black format
  11.     @poetry run black $(DIRECTORIES) && git commit -m "style: Applied Code style Black format automaticly at `date +"%F %T"`" . || echo
  12.     @echo ">>>  Checked code style Black format automaticly  <<<"
  13.  
  14. .PHONY: clean
  15. clean:   ## Shallow clean into environment (.pyc, .cache, .egg, .log, et all)
  16.     @echo -n "Starting cleanning environment .."
  17.     @find ./ -name '*.pyc' -exec rm -f {} \;
  18.     @find ./ -name '*~' -exec rm -f {} \;
  19.     @find ./ -name 'Thumbs.db' -exec rm -f {} \;
  20.     @find ./ -name '*.log' -exec rm -f {} \;
  21.     @find ./ -name '*.log.*' -exec rm -f {} \;
  22.     @find ./ -name ".cache" -exec rm -fr {} \;
  23.     @find ./ -name "*.egg-info" -exec rm -rf {} \;
  24.     @find ./ -name "*.coverage" -exec rm -rf {} \;
  25.     @find ./ -maxdepth 1 -type d -name "*cov*" -exec rm -rf {} \;
  26.     @rm -fv cov.xml
  27.     @rm -rf docs/_build
  28.     @echo " finished!"
  29.  
  30. .PHONY: clean-all
  31. clean-all: clean   ## Deep cleanning into environment (dist, build, htmlcov, .tox, *_cache, et all)
  32.     @echo "Starting Deep cleanning .."
  33.     @rm -rf dist
  34.     @rm -rf build
  35.     @rm -rf htmlcov
  36.     @rm -rf coverage_report
  37.     @rm -rf .tox
  38.     @find ./ \( -name "*_cache" -o -name '*cache__' \) -exec rm -rf {} 2> /dev/null \;
  39.     @#fuser -k 8000/tcp &> /dev/null
  40.     @poetry env list|awk '{print $$1}'|while read a; do poetry env remove $${a} 2> /dev/null && echo "$${a} removed."|| echo "$${a} not removed."; done
  41.     @echo "Deep cleaning finished!"
  42.  
  43. .PHONY: check-black
  44. check-black: ## black checking
  45.     @echo "Black checking .."
  46.     @poetry run black --check $(DIRECTORIES)
  47.  
  48. .PHONY: check-flake8
  49. check-flake8: ## flake8 checking
  50.     @echo "flake8 checking .."
  51.     @poetry run flake8 --config pyproject.toml $(DIRECTORIES)
  52.  
  53. .PHONY: check-isort
  54. check-isort:  ## check isort
  55.     @echo "isort checking .."
  56.     @poetry run isort --check --atomic --py all $(DIRECTORIES)
  57.  
  58. .PHONY: check-mypy
  59. check-mypy: ## mypy checking
  60.     @echo "mypy checking .."
  61.     @poetry run mypy $(DIRECTORIES)
  62.  
  63. .PHONY: check-pylint
  64. check-pylint: ## pylint checking
  65.     @echo "pylint checking .."
  66.     @poetry run pylint $(DIRECTORIES)
  67.  
  68. .PHONY: check-pydocstyle
  69. check-pydocstyle: ## docstring checking
  70.     @echo "pydocstyle checking .."
  71.     @poetry run pydocstyle $(DIRECTORIES)
  72.  
  73. .PHONY: changelog
  74. changelog:   ## Update changelog file
  75.     @poetry run python -c "from incolumepy.utils import update_changelog; \
  76.     update_changelog($(CHANGELOGFILE), urlcompare=$(URLCOMPARE))"
  77.     @echo 'Atualização de CHANGESLOG realizada com sucesso.'
  78.  
  79. .PHONY: docsgen
  80. docsgen: clean changelog    ## Generate documentation
  81.     @ cd docs; make html; cd -
  82.     @ git config core.hooksPath None
  83.     @ git commit -m "docs: Updated documentation (`date +%F@%T`)" docs/ CHANGELOG.md
  84.     @ git config core.hooksPath .git-hooks
  85.  
  86. .PHONY: format
  87. format: isort black   ## Formate project code with code style (isort, black)
  88.  
  89. .PHONY: help
  90. help:  ## Show this instructions
  91.     @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
  92.  
  93. .PHOMY: install
  94. install: setup  ## Install this package using poetry and all dependences
  95.     @poetry install
  96. #   @poetry add $(PKGNAME)
  97.  
  98. .PHONY: isort
  99. isort:  ## isort apply
  100.     @poetry run isort --atomic --py all $(DIRECTORIES) && git commit -m "style: Applied Code style isort format automaticly at `date +%F@%T`" . || echo
  101.     @echo ">>>  Checked code style isort format automaticly  <<<"
  102.  
  103. .PHONY: lint
  104. lint:  ## Run all linters (check-isort, check-black, flake8, pylint, mypy, pydocstyle)
  105. lint: check-mypy check-pylint check-flake8 check-pydocstyle check-isort check-black
  106.  
  107. .PHONY: premajor
  108. premajor:   ## Generate new premajor commit version default semver
  109.     @ git config core.hooksPath None
  110.     @v=$$(poetry version premajor); poetry run pytest tests/ && git commit -m "$$v" pyproject.toml $$(find -name version.txt)  #sem tag
  111.     @ git config core.hooksPath .git-hooks
  112.  
  113. .PHONY: premajor-force
  114. premajor-force:    ## Generate new premajor commit version default semver and your tag forcing merge into main branch
  115.     @ git config core.hooksPath None
  116.     @msg=$$(poetry version premajor); poetry run pytest tests/; \
  117. git commit -m "$$msg" pyproject.toml $$(find -name version.txt) \
  118. && git tag -f $$(poetry version -s) -m "$$msg"; \
  119. git checkout main; git merge --no-ff dev -m "$$msg" \
  120. && git tag -f $$(poetry version -s) -m "$$msg" \
  121. && git checkout dev    #com tag
  122.     @ git config core.hooksPath .git-hooks
  123.  
  124. .PHONY: preminor
  125. preminor:  ## Generate new preminor commit version default semver
  126.     @ git config core.hooksPath None
  127.     @v=$$(poetry version preminor); poetry run pytest -m "not slow" tests/ && git commit -m "$$v" pyproject.toml $$(find -name version.txt)  #sem tag
  128.     @ git config core.hooksPath .git-hooks
  129.  
  130. .PHONY: preminor-force
  131. preminor-force:    ## Generate new preminor commit version default semver and your tag forcing merge into main branch
  132.     @ git config core.hooksPath None
  133.     @msg=$$(poetry version preminor); poetry run pytest tests/; \
  134. git commit -m "$$msg" pyproject.toml $$(find -name version.txt) \
  135. && git tag -f $$(poetry version -s) -m "$$msg"; \
  136. git checkout main; git merge --no-ff dev -m "$$msg" \
  137. && git tag -f $$(poetry version -s) -m "$$msg" \
  138. && git checkout dev    #com tag
  139.     @ git config core.hooksPath .git-hooks
  140.  
  141. .PHONY: prepatch
  142. prepatch:  ## Generate new prepatch commit version default semver
  143.     @ git config core.hooksPath None
  144.     @v=$$(poetry version prepatch); poetry run pytest -m "not slow" tests/ && git commit -m "$$v" pyproject.toml $$(find -name version.txt)  #sem tag
  145.     @ git config core.hooksPath .git-hooks
  146.  
  147. .PHONY: prerelease
  148. prerelease:   ## Generate new prerelease commit version default semver
  149.     @ git config core.hooksPath None
  150.     @v=$$(poetry version prerelease); poetry run pytest tests && git commit -m "$$v" pyproject.toml $$(find -name version.txt)  #sem tag
  151.     @ git config core.hooksPath .git-hooks
  152.  
  153. .PHONY: prerelease-force
  154. prerelease-force:   ## Generate new prerelease commit version default semver and your tag forcing merge into main branch
  155.     @ git config core.hooksPath None
  156.     @msg=$$(poetry version prerelease); poetry run pytest tests/; \
  157. git commit -m "$$msg" pyproject.toml $$(find -name version.txt) \
  158. && git tag -f $$(poetry version -s) -m "$$msg"; \
  159. git checkout main; git merge --no-ff dev -m "$$msg" \
  160. && git tag -f $$(poetry version -s) -m "$$msg" \
  161. && git checkout dev    #com tag
  162.     @ git config core.hooksPath .git-hooks
  163.  
  164. .PHONY: publish-testing
  165. publish-testing: ## Publish on test.pypi.org
  166.     @poetry publish -r testpypi --build
  167.  
  168. .PHONY: release
  169. release:    ## Generate new release commit with version/tag default semver
  170.     @ git config core.hooksPath None
  171.     @msg=$$(poetry version patch); poetry run pytest tests/; \
  172. git commit -m "$$msg" pyproject.toml $$(find -name version.txt) \
  173. && git tag -f $$(poetry version -s) -m "$$msg"; \
  174. git checkout main; git merge --no-ff dev -m "$$msg" \
  175. && git tag -f $$(poetry version -s) -m "$$msg" \
  176. && git checkout dev    #com tag
  177.     @ git config core.hooksPath .git-hooks
  178.  
  179. .PHONY: retrocompatibility
  180. retrocompatibility: ## Run tox and check retrompatibility betwen python versions
  181.     @poetry run tox -e py36,py37,py38,py39,py310
  182.  
  183. .PHONY: safety
  184. safety:  ## Check safety of packages into project.
  185.     @poetry run safety check --full-report
  186.  
  187. .PHOMY: setup
  188. setup: ## setup environment python with poetry
  189.     @poetry env use $(PYTHON_VERSION)
  190.     @git config core.hooksPath .git-hooks
  191. #   @poetry shell
  192.  
  193. .PHONY: stats
  194. stats: ## Run all tests avaliable and generate html coverage
  195.     @poetry run pytest -sxv --cov=$(PKGNAME) --cov-report html:$(REPORT_DIR)/html --cov-report xml:$(REPORT_DIR)/cov.xml --cov-report annotate:$(REPORT_DIR)/annotate --cov-report term-missing:skip-covered tests/
  196.  
  197. .PHONY: test
  198. test:   ## Tun all tests on venv
  199.     @poetry run pytest tests/
  200.  
Add Comment
Please, Sign In to add comment