Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "python_template",
"dockerComposeFile": [
"../docker-compose.yml",
"docker-compose.yml"
],
"service": "app",
"workspaceFolder": "/workspace",
"postCreateCommand": "bash .devcontainer/postCreateCommand.sh",
"userEnvProbe": "loginInteractiveShell",
"customizations": {
"vscode": {
"extensions": [
"ms-python.python",
"charliermarsh.ruff",
"bungcip.better-toml",
"ms-azuretools.vscode-docker"
]
}
}
}
11 changes: 11 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: "3.9"
services:
app:
container_name: app-dev
build:
args:
- PYTHON_BASE_IMAGE=mcr.microsoft.com/vscode/devcontainers/python
target: ${TARGET_STAGE:-dev} # override to use dev stage
command: sleep infinity
volumes:
- .:/workspace:cached
14 changes: 4 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,13 @@ repos:
- id: python-no-eval
- id: python-use-type-annotations

- repo: https://github.com/psf/black
# rev: 23.1.0
# The `refs/tags/<tag>:refs/tags/<tag>` is needed for black's required-version to work:
# https://github.com/psf/black/issues/2493#issuecomment-1081987650
rev: refs/tags/23.1.0:refs/tags/23.1.0
hooks:
- id: black
args: ["--config=pyproject.toml"]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.262
rev: v0.1.3
hooks:
# Run the Ruff linter.
- id: ruff
# Run the Ruff formatter.
- id: ruff-format

# NOTE: It doesn't use pyproject.toml configs. We might enable it the future.
# - repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.11
6 changes: 0 additions & 6 deletions .rtx.toml

This file was deleted.

1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"ms-python.vscode-pylance",
"njpwerner.autodocstring",
"charliermarsh.ruff",
"ms-python.black-formatter",
// "ms-python.mypy-type-checker",
],
"unwantedRecommendations": [
Expand Down
7 changes: 1 addition & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"[python]": {
"editor.formatOnSave": true,
// "editor.defaultFormatter": "charliermarsh.ruff",
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
// "source.fixAll": true,
"source.organizeImports.ruff": true,
Expand All @@ -16,10 +15,6 @@
},
"python.languageServer": "Pylance",
// "python.analysis.autoImportCompletions": true,
"python.linting.enabled": true,
"python.linting.mypyEnabled": false,
"mypy.runUsingActiveInterpreter": true,
// "python.formatting.provider": "black",
"autoDocstring.generateDocstringOnEnter": true,
"autoDocstring.docstringFormat": "google",
"autoDocstring.customTemplatePath": "docs/templates/google-notypes.mustache",
Expand Down
126 changes: 44 additions & 82 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.ONESHELL:
SHELL=/bin/bash
ROOT_DIR=python-template
PACKAGE=python_template
PACKAGE=src/python_template
PYTHON = python
PYTHON_VERSION=3.10
DOC_DIR=./docs
Expand All @@ -12,6 +12,10 @@ TEST_MARKER=placeholder
TEST_OUTPUT_DIR=tests_outputs
PRECOMMIT_FILE_PATHS=./python_template/__init__.py
PROFILE_FILE_PATH=./python_template/__init__.py
DOCKER_IMAGE=python-template
DOCKER_TARGET=development

# TODO: add source for rye
PYPI_URLS=

.PHONY: help install test clean build publish doc pre-commit format lint profile
Expand All @@ -35,73 +39,39 @@ python-info: ## List information about the python environment
update-pip:
${PYTHON} -m pip install -U pip

install-poetry: ## Install poetry if it is not already installed (Installing poetry with official method is recommended)
$(MAKE) update-pip
! command -v poetry &> /dev/null && pip install poetry==1.4.2
# poetry config virtualenvs.create false
# poetry config repositories.private-pypi <PRIVATE_PYPI_URL>
# poetry config http-basic.private-pypi ${PYPI_USERNAME} ${PYPI_PASSWORD}

create-conda:
@conda create -n ${ROOT_DIR} python=${PYTHON_VERSION} -y
install-rye:
! command -v rye &> /dev/null && curl -sSf https://rye-up.com/get | bash

install-base: ## Installs only package dependencies
############# PIP ############
# $(MAKE) update-pip
# pip install ${PYPI_URLS} --editable .
########### POETRY ###########
$(MAKE) install-poetry
poetry install --only-root

install: ## Installs the development and test version of the package
############# PIP ############
# $(MAKE) update-pip
# pip install ${PYPI_URLS} --editable .[test,doc,dev]
########### POETRY ###########
$(MAKE) install-poetry
poetry install
rye sync --no-dev --no-lock

install: ## Installs the development version of the package
rye sync --no-lock
$(MAKE) install-precommit

install-no-cache: ## Installs the development and test version of the package
############# PIP ############
# $(MAKE) update-pip
# pip install --no-cache-dir ${PYPI_URLS} --editable .[test,dev]
########### POETRY ###########
$(MAKE) install-poetry
poetry install --no-cache

$(MAKE) install-precommit
# # FIXME: Currently not supported by rye
# install-no-cache: ## Installs the development version of the package

install-test: ## Install only test version of the package
############# PIP ############
# $(MAKE) update-pip
# pip install ${PYPI_URLS} .[test]
########### POETRY ###########
$(MAKE) install-poetry
poetry install --without dev
# FIXME: Currently not supported by rye
# install-test: ## Install only test version of the package

install-precommit: ## Install pre-commit hooks
pre-commit install

install-lint:
pip install black[d]==23.1.0 ruff==0.0.262

install-build:
############# PIP ############
# pip install build
########### POETRY ###########
$(MAKE) install-poetry

install-publish:
############# PIP ############
# pip install twine
########### POETRY ###########
$(MAKE) install-poetry
pip install ruff==0.1.3

install-doc:
pip install mkdocs mkdocs-material mkdocstrings[python]

update-dependencies: ## Updates the lockfiles and installs dependencies. Dependencies are updated if necessary
rye sync
# Updates the lockfiles without installing dependencies
# rye lock

upgrade-dependencies: ## Updates the lockfiles and installs the latest version of the dependencies
rye sync --update-all

test-one: ## Run specific tests with TEST_MARKER=<test_name>, default marker is `placeholder`
${PYTHON} -m pytest -m ${TEST_MARKER}

Expand Down Expand Up @@ -130,14 +100,11 @@ 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 ./build ./dist */*.egg-info *.egg-info
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 {} \;
Expand All @@ -154,31 +121,22 @@ clean-test: ## Clean test related files left after test

clean: clean-build clean-test ## Cleans build and test related files

# TODO: Remove poetry-installation
build: ## Make Python source distribution
############# PIP ############
# ${PYTHON} -m build --sdist --outdir dist
########### POETRY ###########
$(MAKE) install-poetry
poetry build --format sdist
$(MAKE) clean-build
rye build --sdist --out dist

# NOTE: Below will fail if there is no dist folder
# See: https://github.com/mitsuhiko/rye/issues/475
# rye build --clean --sdist --out dist

# TODO: Remove poetry-installation
build-wheel: ## Make Python wheel distribution
############# PIP ############
# ${PYTHON} -m build --wheel --outdir dist
########### POETRY ###########
$(MAKE) install-poetry
poetry build --format wheel
$(MAKE) clean-build
rye build --wheel --out dist

# TODO: Implement this
publish: ## Builds the project and publish the package to Pypi
$(MAKE) build

############# PIP ############
# twine upload dist/* --verbose --config-file .pypirc
########### POETRY ###########
# poetry publish -r private-pypi -u ${PYPI_USERNAME} -p ${PYPI_PASSWORD}
poetry publish -r private-pypi
# $(MAKE) build
rye publish dist/*
# rye publish --repository-url https://test.pypi.org/legacy/ dist/*

doc: ## Build documentation with mkdocs
mkdocs build
Expand All @@ -198,20 +156,21 @@ pre-commit: ## Run pre-commit for all package files
pre-commit-clean: ## Clean pre-commit cache
pre-commit clean

lint: ## Lint code with black, ruff
${PYTHON} -m black ${PACKAGE} --check --diff
lint: ## Lint code with ruff
${PYTHON} -m ruff format ${PACKAGE} --check --diff
${PYTHON} -m ruff ${PACKAGE}

lint-report: ## Lint report for gitlab
${PYTHON} -m black ${PACKAGE} --check --diff
${PYTHON} -m ruff format ${PACKAGE} --check --diff
${PYTHON} -m ruff ${PACKAGE} --format gitlab > gl-code-quality-report.json

format: ## Run black, ruff for all package files. CHANGES CODE
${PYTHON} -m black ${PACKAGE}
format: ## Run ruff for all package files. CHANGES CODE
${PYTHON} -m ruff format ${PACKAGE}
${PYTHON} -m ruff ${PACKAGE} --fix --show-fixes

typecheck: ## Checks code with mypy
${PYTHON} -m mypy --package ${PACKAGE}
# MYPYPATH=src ${PYTHON} -m mypy --package ${PACKAGE}

typecheck-no-cache: ## Checks code with mypy no cache
${PYTHON} -m mypy --package ${PACKAGE} --no-incremental
Expand All @@ -227,3 +186,6 @@ profile-gui: ## Profile the file with scalene and shows the report in the browse

profile-builtin: ## Profile the file with cProfile and shows the report in the terminal
${PYTHON} -m cProfile -s tottime ${PROFILE_FILE_PATH}

docker-build: ## Build docker image
docker build --tag ${DOCKER_IMAGE} --file docker/Dockerfile --target ${DOCKER_TARGET} .
Loading