Skip to content

Commit

Permalink
Merge pull request #123 from alexandrainst/chore/small-changes
Browse files Browse the repository at this point in the history
Chore/small changes
  • Loading branch information
saattrupdan authored Oct 26, 2023
2 parents 84c36c1 + 1ed9a0b commit 2e08512
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 262 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
### Changed
- Now requires Python 3.11 and above.

### Fixed
- Now catches a new `HFValidationError` caused when attempting to check if a model
exists on the Hugging Face Hub.

### Security
- Updated `urllib3` to 2.0.7 due to a security update.


## [v0.1.0] - 2023-02-22
### Added
Expand Down
157 changes: 82 additions & 75 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 help
.PHONY: docs help

# Exports all variables defined in the makefile available to scripts
.EXPORT_ALL_VARIABLES:
Expand All @@ -10,46 +10,103 @@ 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

# 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-poetry:
@if [ ! "$(shell poetry --version)" = "Poetry (version 1.4.0)" ]; then \
pip3 install --force --quiet poetry==1.4.0; \
echo "Installed Poetry."; \
install: ## Install dependencies
@echo "Installing the 'alexandra_ai_eval' 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 'alexandra_ai_eval' 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

uninstall-poetry:
@echo "Uninstalling poetry..."
@pip3 uninstall poetry
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

install: ## Install dependencies
@if [ "$(shell which gpg)" = "" ]; then \
echo "GPG not installed. Install GPG on MacOS with `brew install gnupg` or "; \
"on Ubuntu with `apt install gnupg` and run `make install` again."; \
else \
echo "Installing the 'alexandra_ai_eval' project..."; \
$(MAKE) --quiet install-poetry; \
$(MAKE) --quiet setup-poetry; \
$(MAKE) --quiet setup-environment-variables; \
$(MAKE) --quiet setup-git; \
echo "Installed the 'alexandra_ai_eval' project."; \
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

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

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

setup-environment-variables:
@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}
Expand All @@ -62,8 +119,6 @@ setup-git:
echo "Signed with GPG key ID ${GPG_KEY_ID}."; \
fi
@poetry run pre-commit install
@export GPG_TTY=$(tty)
@gpgconf --kill gpg-agent

docs: ## Generate documentation
@poetry run pdoc --docformat google src/alexandra_ai_eval -o docs
Expand All @@ -80,60 +135,12 @@ view-docs: ## View documentation
esac; \
"$${openCmd}" docs/alexandra_ai_eval.html

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

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 a major version

publish-minor: bump-minor publish ## Publish a minor version

publish-patch: bump-patch publish ## Publish a patch version

test: ## Run tests
@poetry run pytest && poetry run readme-cov

docker: ## Build Docker image and run container
@docker build -t alexandra_ai_eval .
@docker run -it --rm alexandra_ai_eval

tree: ## Print directory 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__ \
-I .ruff_cache \
-I .alexandra_ai_cache \
-I .hypothesis \
-I models \
.
@tree -a --gitignore -I .git .
Loading

0 comments on commit 2e08512

Please sign in to comment.