Skip to content

Commit

Permalink
chore: Update makefile and deps
Browse files Browse the repository at this point in the history
  • Loading branch information
saattrupdan committed Nov 24, 2023
1 parent c22d02b commit 278270f
Show file tree
Hide file tree
Showing 4 changed files with 1,204 additions and 1,338 deletions.
17 changes: 8 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
repos:
- repo: https://github.com/ambv/black
rev: 22.6.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.290
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
types_or: [python, pyi, jupyter]
- repo: https://github.com/kynan/nbstripout
rev: 0.6.0
hooks:
- id: nbstripout
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
rev: v1.4.1
hooks:
- id: mypy
args: [--install-types, --non-interactive, --ignore-missing-imports, --show-error-codes]

169 changes: 90 additions & 79 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This ensures that we can call `make <target>` even if `<target>` exists as a file or
# directory.
.PHONY: notebook docs
.PHONY: docs help

# Exports all variables defined in the makefile available to scripts
.EXPORT_ALL_VARIABLES:
Expand All @@ -10,62 +10,121 @@ ifeq (,$(wildcard .env))
$(shell touch .env)
endif

# Create poetry env file if it does not already exist
ifeq (,$(wildcard ${HOME}/.poetry/env))
$(shell mkdir ${HOME}/.poetry)
$(shell touch ${HOME}/.poetry/env)
endif

# Includes environment variables from the .env file
include .env

# Set gRPC environment variables, which prevents some errors with the `grpcio` package
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1

install-poetry:
@echo "Installing poetry..."
@pipx install poetry==1.2.0
@$(eval include ${HOME}/.poetry/env)

uninstall-poetry:
@echo "Uninstalling poetry..."
@pipx uninstall poetry

install:
@echo "Installing..."
@if [ "$(shell which poetry)" = "" ]; then \
$(MAKE) install-poetry; \
# Ensure that `pipx` and `poetry` will be able to run, since `pip` and `brew` put these
# in the following folders on Unix systems
export PATH := ${HOME}/.local/bin:/opt/homebrew/bin:$(PATH)

# Prevent DBusErrorResponse during `poetry install`
# (see https://stackoverflow.com/a/75098703 for more information)
export PYTHON_KEYRING_BACKEND := keyring.backends.null.Keyring

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

install: ## Install dependencies
@echo "Installing the 'ScandiReddit' project..."
@$(MAKE) --quiet install-brew
@$(MAKE) --quiet install-gpg
@$(MAKE) --quiet generate-gpg-key
@$(MAKE) --quiet install-pipx
@$(MAKE) --quiet install-poetry
@$(MAKE) --quiet setup-poetry
@$(MAKE) --quiet setup-environment-variables
@$(MAKE) --quiet setup-git
@echo "Installed the 'ScandiReddit' project."

install-brew:
@if [ $$(uname) = "Darwin" ] && [ "$(shell which brew)" = "" ]; then \
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; \
echo "Installed Homebrew."; \
fi

install-gpg:
@if [ "$(shell which gpg)" = "" ] || [ "$(shell which gpg-agent)" = "" ]; then \
uname=$$(uname); \
case $${uname} in \
(*Linux*) distro=$$(lsb_release -i | sed 's/Distributor ID:\t//'); \
case $${distro} in \
(*Ubuntu*) installCmd='apt-get update && apt-get install -y gnupg gpg-agent'; ;; \
(*CentOS*) installCmd='yum install -y gnupg gpg-agent'; ;; \
(*) echo 'Could not automatically install gnupg for the $${distro} distribution. Please manually install gnupg and try again.'; exit 2; ;; \
esac; ;; \
(*Darwin*) installCmd='brew install gnupg pinentry-mac'; ;; \
(*) echo 'Could not automatically install gnupg. Please manually install gnupg and try again.'; exit 2; ;; \
esac; \
"$${installCmd}"; \
echo "Installed gnupg."; \
fi

generate-gpg-key:
@if [ "$(shell gpg --list-secret-keys --keyid-format=long | grep sec | sed -E 's/.*\/([^ ]+).*/\1/')" = "" ]; then \
echo "Generating a new GPG key - please follow the prompts."; \
gpg --full-generate-key; \
echo "Generated a new GPG key. Remember to register it to Github at https://github.com/settings/gpg/new, where you add the key generated by running 'gpg --armor --export <key>'"; \
fi

install-pipx:
@if [ "$(shell which pipx)" = "" ]; then \
uname=$$(uname); \
case $${uname} in \
(*Darwin*) installCmd='brew install pipx'; ;; \
(*CYGWIN*) installCmd='py -3 -m pip install --upgrade --user pipx'; ;; \
(*) installCmd='python3 -m pip install --upgrade --user pipx'; ;; \
esac; \
$${installCmd}; \
pipx ensurepath --force; \
echo "Installed pipx."; \
fi
@if [ "$(shell which gpg)" = "" ]; then \
echo "GPG not installed, so an error will occur. Install GPG on MacOS with "\
"`brew install gnupg` or on Ubuntu with `apt install gnupg` and run "\
"`make install` again."; \

install-poetry:
@if [ ! "$(shell poetry --version)" = "Poetry (version 1.5.1)" ]; then \
python3 -m pip uninstall -y poetry poetry-core poetry-plugin-export; \
pipx install --force poetry==1.5.1; \
echo "Installed Poetry."; \
fi
@$(MAKE) setup-poetry
@$(MAKE) setup-environment-variables
@$(MAKE) setup-git

setup-poetry:
@poetry env use python3 && poetry install
@poetry env use python3.11 && poetry install

setup-environment-variables:
@poetry run python3 -m src.scripts.fix_dot_env_file
@poetry run python src/scripts/fix_dot_env_file.py

setup-environment-variables-non-interactive:
@poetry run python src/scripts/fix_dot_env_file.py --non-interactive

setup-git:
@git config --global init.defaultBranch main
@git init
@git config --local user.name ${GIT_NAME}
@git config --local user.email ${GIT_EMAIL}
@if [ ${GPG_KEY_ID} = "" ]; then \
echo "No GPG key ID specified. Skipping GPG signing."; \
git config --local commit.gpgsign false; \
else \
echo "Signing with GPG key ID ${GPG_KEY_ID}..."; \
echo 'If you get the "failed to sign the data" error when committing, try running `export GPG_TTY=$$(tty)`.'; \
git config --local commit.gpgsign true; \
git config --local user.signingkey ${GPG_KEY_ID}; \
echo "Signed with GPG key ID ${GPG_KEY_ID}."; \
fi
@poetry run pre-commit install

docs:
docs: ## Generate documentation
@poetry run pdoc --docformat google src/scandi_reddit -o docs
@echo "Saved documentation."

view-docs:
view-docs: ## View documentation
@echo "Viewing API documentation..."
@uname=$$(uname); \
case $${uname} in \
Expand All @@ -76,56 +135,8 @@ view-docs:
esac; \
"$${openCmd}" docs/scandi_reddit.html

bump-major:
@poetry run python -m src.scripts.versioning --major
@echo "Bumped major version!"
test: ## Run tests
@poetry run pytest && poetry run readme-cov

bump-minor:
@poetry run python -m src.scripts.versioning --minor
@echo "Bumped minor version!"

bump-patch:
@poetry run python -m src.scripts.versioning --patch
@echo "Bumped patch version!"

publish:
@if [ ${PYPI_API_TOKEN} = "" ]; then \
echo "No PyPI API token specified in the '.env' file, so cannot publish."; \
else \
echo "Publishing to PyPI..."; \
poetry publish --build --username "__token__" --password ${PYPI_API_TOKEN}; \
fi
@echo "Published!"

publish-major: bump-major publish

publish-minor: bump-minor publish

publish-patch: bump-patch publish

test:
@poetry run pytest && readme-cov

tree:
@tree -a \
-I .git \
-I .mypy_cache \
-I .env \
-I .venv \
-I poetry.lock \
-I .ipynb_checkpoints \
-I dist \
-I .gitkeep \
-I docs \
-I .pytest_cache \
-I outputs \
-I .DS_Store \
-I .cache \
-I raw \
-I processed \
-I final \
-I checkpoint-* \
-I .coverage* \
-I .DS_Store \
-I __pycache__ \
.
tree: ## Print directory tree
@tree -a --gitignore -I .git .
Loading

0 comments on commit 278270f

Please sign in to comment.