diff --git a/.env b/.env new file mode 100644 index 0000000..39b8d72 --- /dev/null +++ b/.env @@ -0,0 +1,6 @@ +# This file is used to store sensitive information. +# It should be added to .gitignore and never committed to the repository. + +PYPI_USERNAME="" +PYPI_PASSWORD="" +PYPI_TOKEN="" diff --git a/.github/workflows/doc.yaml b/.github/workflows/doc.yaml index 5a02341..5b08af1 100644 --- a/.github/workflows/doc.yaml +++ b/.github/workflows/doc.yaml @@ -15,12 +15,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: '3.8' - - name: Pip updated + - name: Pip Update run: | - pip install --upgrade pip - - name: Doc installation + make update-pip + - name: Docs Dependency Installation run: | make install-doc - - name: Documenting + - name: Build the project documentation run: | - make doc + make doc-github diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 8a4af0c..47755b0 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -19,12 +19,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: '3.8' - - name: Pip updated + - name: Pip Update run: | - pip install --upgrade pip - - name: Lint installation + make update-pip + - name: Lint Dependency Installation run: | make install-lint - - name: Linting + - name: Lint the Project run: | make lint diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 60c5022..a961344 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -21,13 +21,18 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - - name: Install the module and its dependencies + - name: Disable Logger Outputs + run: | + sed -i "s/log_cli = true/log_cli = false/" pyproject.toml + - name: Pip Update + run: | + make update-pip + - name: Install the Project with Test Dependencies run: | - make install - - name: Show dependencies - run: python -m pip list - - name: Run tests + make install-test + # - name: Show dependencies + # run: python -m pip list + - name: Test the Project run: make test-parallel - - name: Publish code coverage - uses: codecov/codecov-action@v3 + # - name: Publish code coverage + # uses: codecov/codecov-action@v3 diff --git a/.gitignore b/.gitignore index eeb92aa..83f9f5f 100644 --- a/.gitignore +++ b/.gitignore @@ -213,7 +213,7 @@ celerybeat.pid *.sage.py # Environments -.env +# .env .venv env/ venv/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0723e34..97f9695 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,22 +9,26 @@ image: python:3.8 lint: stage: lint script: | - pip install --upgrade pip - echo "*********** Pip updated ***********" + echo "*********** Pip Update ***********" + make update-pip + echo "*********** Lint Dependency Installation ***********" make install-lint - echo "*********** Linter installed ***********" + echo "*********** Lint the Project ***********" make lint - echo "*********** Successfully linted the project ***********" only: - merge_requests tests: stage: tests script: | + echo "*********** Disable Logger Outputs ***********" sed -i "s/log_cli = true/log_cli = false/" pyproject.toml - python -m pip install --upgrade pip setuptools + echo "*********** Pip Update ***********" + make update-pip + echo "*********** Install the Project with Test Dependencies ***********" make install-test - make test + echo "*********** Test the Project ***********" + make test-parallel only: - merge_requests # artifacts: @@ -36,22 +40,28 @@ package: rules: - if: $CI_COMMIT_TAG # Run this job when a tag is created manually script: | + echo "*********** Rename `version` with COMMIT_TAG: $CI_COMMIT_TAG ***********" sed -i "s/0.0.0/$CI_COMMIT_TAG/" pyproject.toml - echo "*********** Renamed version with COMMIT_TAG: $CI_COMMIT_TAG ***********" + echo "*********** Pip Update ***********" + make update-pip + echo "*********** Build Dependency Installation ***********" + make install-build + echo "*********** Build the Project ***********" make build - echo "*********** Building finished ***********" + echo "*********** Publish Dependency Installation ***********" + make install-publish + echo "*********** Publish the Project ***********" make publish - echo "*********** Uploading finished ***********" pages: stage: doc script: | - pip install --upgrade pip - echo "*********** Pip updated ***********" + echo "*********** Pip Update ***********" + make update-pip + echo "*********** Docs Dependency Installation ***********" make install-doc - echo "*********** Docs dependencies installed ***********" + echo "*********** Build the project documentation ***********" make doc - echo "*********** Successfully builded the project documentation ***********" # only: # - main rules: diff --git a/Makefile b/Makefile index 3f8e938..5003287 100644 --- a/Makefile +++ b/Makefile @@ -10,143 +10,147 @@ DOC_DIR=./docs TEST_DIR=./tests TEST_MARKER=placeholder TEST_OUTPUT_DIR=tests_outputs -PRECOMMIT_FILE_PATHS=./python_template/placeholder.py +PRECOMMIT_FILE_PATHS=./python_template/__init__.py +PYPI_URLS= -.PHONY: help install install-test test test-parallel clean build publish doc doc-github pre-commit format lint +.PHONY: help install test clean build publish doc pre-commit format lint .DEFAULT_GOAL=help -.SILENT: help update_pip create_conda instal-base install install-no-cache install-test install-lint install-build test-one \ -test-one-parallel test-all test-all-parallel test-coverage test-coverage-parallel clean-build clean-test test-docs \ -build build-wheel publish doc doc-github doc-dev pre-commit-one pre-commit lint format typecheck typecheck-no-cache typecheck-report - - help: - grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) |\ + @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) |\ awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m\ %s\n", $$1, $$2}' -update_pip: - ${PYTHON} -m pip install -U pip +update-pip: + @${PYTHON} -m pip install -U pip -create_conda: - conda create -n ${ROOT_DIR} python=${PYTHON_VERSION} -y +create-conda: + @conda create -n ${ROOT_DIR} python=${PYTHON_VERSION} -y -install-base: update_pip ## Installs only package dependencies - pip install --editable . +install-base: ## Installs only package dependencies + $(MAKE) update-pip + @pip install ${PYPI_URLS} --editable . -install: update_pip ## Installs the development and test version of the package - pip install --editable .[test,doc,dev] - pre-commit install +install: ## Installs the development and test version of the package + $(MAKE) update-pip + @pip install ${PYPI_URLS} --editable .[test,doc,dev] + @pre-commit install install-no-cache: ## Installs the development and test version of the package - pip install --no-cache-dir --editable .[test,dev] - pre-commit install + @pip install --no-cache-dir ${PYPI_URLS} --editable .[test,dev] + @pre-commit install install-test: ## Install only test version of the package - pip install .[test] + @pip install ${PYPI_URLS} .[test] + +install-precommit: ## Install pre-commit hooks + @pip install pre-commit + @pre-commit install install-lint: - pip install black[d]==23.1.0 ruff==0.0.246 + @pip install black[d]==23.1.0 ruff==0.0.246 install-build: - pip install -U build + @pip install build + +install-publish: + @pip install twine install-doc: - pip install mkdocs mkdocs-material mkdocstrings[python] + @pip install mkdocs mkdocs-material mkdocstrings[python] test-one: ## Run specific tests with TEST_MARKER=, default marker is `placeholder` - ${PYTHON} -m pytest -m ${TEST_MARKER} + @${PYTHON} -m pytest -m ${TEST_MARKER} test-one-parallel: ## Run specific tests with TEST_MARKER= in parallel, default marker is `placeholder` - ${PYTHON} -m pytest -n auto -m ${TEST_MARKER} + @${PYTHON} -m pytest -n auto -m ${TEST_MARKER} test-all: ## Run all tests - #mkdir -p ${TEST_OUTPUT_DIR} - #cp .coveragerc ${TEST_OUTPUT_DIR} - #cp setup.cfg ${TEST_OUTPUT_DIR} - ${PYTHON} -m pytest + @# mkdir -p ${TEST_OUTPUT_DIR} + @# cp .coveragerc ${TEST_OUTPUT_DIR} + @# cp setup.cfg ${TEST_OUTPUT_DIR} + @${PYTHON} -m pytest test-all-parallel: ## Run all tests with parallelization - ${PYTHON} -m pytest -n auto + @${PYTHON} -m pytest -n auto test-coverage: ## Run all tests with coverage - ${PYTHON} -m pytest --cov=${PACKAGE} --cov-report=html:coverage + @${PYTHON} -m pytest --cov=${PACKAGE} --cov-report=html:coverage test-coverage-parallel: - ${PYTHON} -m pytest -n auto --cov=${PACKAGE} --cov-report=html:coverage + @${PYTHON} -m pytest -n auto --cov=${PACKAGE} --cov-report=html:coverage test-docs: ## Test documentation examples with doctest - ${PYTHON} -m pytest --doctest-modules ${PACKAGE} + @${PYTHON} -m pytest --doctest-modules ${PACKAGE} test: clean-test test-all ## Cleans and runs all tests test-parallel: clean-test test-all-parallel ## Cleans and runs all tests with parallelization clean-build: ## Clean build dist and egg directories left after install - rm -rf ./dist - rm -rf ./build - rm -rf ./junit - rm -rf ./$(PACKAGE).egg-info - rm -f MANIFEST - rm -rf ./dist/* - find . -type f -iname "*.so" -delete - find . -type f -iname '*.pyc' -delete - find . -type d -name '__pycache__' -empty -delete + @rm -rf ./dist + @rm -rf ./build + @rm -rf ./pytest_cache + @rm -rf ./junit + @rm -rf ./$(PACKAGE).egg-info + @find . -type f -iname "*.so" -delete + @find . -type f -iname '*.pyc' -delete + @# find . -type d -name '$(PACKAGE).egg-info' -empty -delete + @find . -type d -name '*.egg-info' -prune -exec rm -rf {} \; + @find . -type d -name '__pycache__' -prune -exec rm -rf {} \; + @find . -type d -name '.ruff_cache' -prune -exec rm -rf {} \; + @find . -type d -name '.mypy_cache' -prune -exec rm -rf {} \; clean-test: ## Clean test related files left after test - #rm -rf ./htmlcov - #rm -rf ./coverage.xml - find . -type f -regex '\.\/\.*coverage[^rc].*' -delete - rm -rf ${TEST_OUTPUT_DIR} - find ${TEST_DIR} -type f -regex '\.\/\.*coverage[^rc].*' -delete - find ${TEST_DIR} -type d -name 'htmlcov' -exec rm -r {} + - rm -rf ./.pytest_cache - rm -rf ./.mypy_cache - rm -rf ./.ruff_cache + @# rm -rf ./htmlcov + @# rm -rf ./coverage.xml + @find . -type f -regex '\.\/\.*coverage[^rc].*' -delete + @rm -rf ${TEST_OUTPUT_DIR} + @find ${TEST_DIR} -type f -regex '\.\/\.*coverage[^rc].*' -delete + @find ${TEST_DIR} -type d -name 'htmlcov' -exec rm -r {} + + @find . -type d -name '.pytest_cache' -prune -exec rm -rf {} \; clean: clean-build clean-test ## Cleans build and test related files -build: update_pip ## Build the package, creates source distribution - pip install build - ${PYTHON} -m build --sdist --outdir dist +build: ## Build the package, creates source distribution + @${PYTHON} -m build --sdist --outdir dist build-wheel: - ${PYTHON} -m build --wheel --outdir dist + @${PYTHON} -m build --wheel --outdir dist -publish: update_pip ## Publish the package to pypi - pip install twine - twine upload dist/* --verbose --config-file .pypirc +publish: ## Publish the package to pypi + @twine upload dist/* --verbose --config-file .pypirc doc: ## Build documentation with mkdocs - mkdocs build + @mkdocs build doc-github: ## Build documentation with mkdocs and deploy to github pages - mkdocs gh-deploy + @mkdocs gh-deploy doc-dev: ## Show documentation preview with mkdocs - mkdocs serve -w ${PACKAGE} + @mkdocs serve -w ${PACKAGE} pre-commit-one: ## Run pre-commit with specific files - pre-commit run --files ${PRECOMMIT_FILE_PATHS} + @pre-commit run --files ${PRECOMMIT_FILE_PATHS} pre-commit: ## Run pre-commit for all package files - pre-commit run --all-files + @pre-commit run --all-files pre-commit-clean: ## Clean pre-commit cache - pre-commit clean + @pre-commit clean lint: ## Lint code with black, ruff - ${PYTHON} -m black ${PACKAGE} --check --diff - ${PYTHON} -m ruff ${PACKAGE} + @${PYTHON} -m black ${PACKAGE} --check --diff + @${PYTHON} -m ruff ${PACKAGE} format: ## Run black, ruff for all package files. CHANGES CODE - ${PYTHON} -m black ${PACKAGE} - ${PYTHON} -m ruff ${PACKAGE} --fix + @${PYTHON} -m black ${PACKAGE} + @${PYTHON} -m ruff ${PACKAGE} --fix typecheck: ## Checks code with mypy - ${PYTHON} -m mypy --package ${PACKAGE} + @${PYTHON} -m mypy --package ${PACKAGE} typecheck-no-cache: ## Checks code with mypy no cache - ${PYTHON} -m mypy --package ${PACKAGE} --no-incremental + @${PYTHON} -m mypy --package ${PACKAGE} --no-incremental typecheck-report: ## Checks code with mypy and generates html report - ${PYTHON} -m mypy --package ${PACKAGE} --html-report mypy_report + @${PYTHON} -m mypy --package ${PACKAGE} --html-report mypy_report