Spells (API reference)
This is an API reference for the all the Invoke tasks and helper functions that are included in the Conjuring package.
conjuring.spells.aws
AWS: ECR login.
clean_ecr_url(c, url=None)
Clean an AWS ECR URL.
ecr_login(c, url='')
Log in to AWS ECR.
Using Amazon ECR with the AWS CLI - Amazon ECR
Source code in src/conjuring/spells/aws.py
fzf_aws_account(c)
fzf_aws_profile(c, partial_name=None)
Select an AWS profile from a partial profile name using fzf.
Source code in src/conjuring/spells/aws.py
fzf_aws_region(c)
list_aws_profiles(c)
run_aws_vault(c, *pieces, profile=None)
Run AWS vault commands in a subshell, or open a subshell if no commands were provided.
Source code in src/conjuring/spells/aws.py
conjuring.spells.direnv
direnv: init local dir.
init(c, source_up=False, dotenv=False, all_=False)
Configure direnv in the local dir.
Source code in src/conjuring/spells/direnv.py
conjuring.spells.docker
Docker: remove containers and volumes.
rm_containers(c, container='', all_=False, exited=False)
Remove Docker containers.
Source code in src/conjuring/spells/docker.py
rm_volumes(c, dangling=False)
Remove Docker volumes.
Source code in src/conjuring/spells/docker.py
conjuring.spells.duplicity
Backup and restore with Duplicity.
backup(c)
Backup files with Duplicity.
Source code in src/conjuring/spells/duplicity.py
list_current_files(c)
List all files included in the current duplicity backup.
Source code in src/conjuring/spells/duplicity.py
print_hostname(c)
restore(c)
Restore files with Duplicity. You will be prompted to choose the source dir. Restore dir is ~/Downloads.
Source code in src/conjuring/spells/duplicity.py
conjuring.spells.fork
GitHub forks: configure remote and sync.
remote(c, username, remote_='upstream')
Configure a remote for a fork.
Source code in src/conjuring/spells/fork.py
sync(c, remote_='upstream')
Source code in src/conjuring/spells/fork.py
conjuring.spells.generic
Generic spells: list to-do items in files.
Location
dataclass
Location of a to-do item in a file.
Source code in src/conjuring/spells/generic.py
ToDoItem
dataclass
A to-do item.
Source code in src/conjuring/spells/generic.py
sort_key
property
Key to sort the instance.
String concatenation works.
Checking both fields separately with and conditions didn't work: sort order was not as expected
(meaning fix-me tasks first, then to-do tasks).
todo(c, cz=False, valid=True, invalid=True, short=False, priority='', markdown=False, dir_='')
List to-dos and fix-mes in code. Optionally check if the description follows Conventional Commits (cz check).
Source code in src/conjuring/spells/generic.py
conjuring.spells.git
Git: update all, extract subtree, rewrite history, ...
Git
Git helpers.
Source code in src/conjuring/spells/git.py
github_username
property
The GitHub username configured in the global settings.
checkout(*branches)
Try checking out the specified branches in order.
Source code in src/conjuring/spells/git.py
choose_local_branch(branch)
current_branch()
default_branch()
Return the default branch name (master/main/develop/development).
PrefixBranch
dataclass
body(c, prefix=False, original_order=False)
Prepare a commit body to be used on pull requests and squashed commits.
Source code in src/conjuring/spells/git.py
changes_since_tag(c, tag='', files=False, verbose=False, by_author=False)
Display changes (commits or files) since the last tag (or a chosen tag).
Source code in src/conjuring/spells/git.py
dirty(c, dir_)
Find Git dirs in multiple directories recursively and print the ones which are dirty.
Source code in src/conjuring/spells/git.py
extract_subtree(c, new_project_dir, reset=False)
Extract files from subdirectories of the current Git repo to another repo, using git-filter-repo.
This function extracts a subset of files from the current repository's entire Git history into a new repository, preserving all commits that touched those files.
Steps: 1. Prepare new project directory (clone from origin or reset if requested) 2. Gather all files from Git history including deleted files 3. Interactive selection with fzf (TAB to select/deselect) 4. Filter repository history using git-filter-repo with selected paths 5. Display next steps and instructions
Prerequisites:
- Install git-filter-repo: pipx install git-filter-repo
- Current directory must be a Git repository with a remote origin
Warning: - Rewrites Git history in the new repository - Do NOT push filtered repository to the same remote as the original
Source code in src/conjuring/spells/git.py
global_config()
cached
history(c, full=False, files=False, author=False, dates=False)
Grep the whole Git log and display information.
Source code in src/conjuring/spells/git.py
import_repos(c, target, source='', dir_='', yes=False, rollback=False)
Merge a Git repository into a target repository as a subdirectory, preserving history.
This function safely merges a source repository into a target repository locally, without pushing any changes. All operations are Git-reversible using standard Git commands.
The current branch of the source repository will be used for the merge. If the destination directory is not specified, the source repository name will be used.
Detailed steps: 1. Validate repositories and check that destination directory doesn't exist 2. Create a temporary clone of the source repository 3. Rewrite the temporary clone's history to move all files into the destination subdirectory 4. Add the rewritten repository as a temporary remote and fetch it 5. Merge the unrelated histories into the target repository 6. Clean up temporary remote and clone directory 7. Display rollback instructions
Prerequisites: - Install git-filter-repo: pipx install git-filter-repo - Target repository must exist and be a Git repository - Source repository must exist and be a Git repository
Safety features: - No git push commands - all changes are local only - Source repository is never modified (temporary clone is used) - Target repository can be rolled back using git reset - Creates a tag before merging for easy rollback
Note: git-extras has a git-merge-repo command, but I only found out about it after I had written this function, which does a lot of verifications that git-merge-repo doesn't.
Example usage
invoke git.import-repos --target=/path/to/target --source=/path/to/source --dir_=my-subdir invoke git.import-repos --source=/path/to/source # Uses source repo name as destination dir
Rollback
invoke git.import-repos --target=/path/to/target --rollback
Source code in src/conjuring/spells/git.py
746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 | |
is_valid_git_repository(repo_path)
Check if the given path is a valid Git repository.
merge_default(c, remote=False, update=True, push=True, rebase=False)
Merge the default branch of the repo. Also set it with "git config", if not already set.
Source code in src/conjuring/spells/git.py
new_branch(c, title)
Create a new Git branch with a slugified title while keeping the Jira ticket in uppercase.
Source code in src/conjuring/spells/git.py
rewrite(c, commit='--root', gpg=True, author=True)
Rewrite a range of commits, signing with GPG and setting the author.
https://git-scm.com/docs/git-commit https://git-scm.com/docs/git-rebase
Source code in src/conjuring/spells/git.py
set_default_branch(c, remote=False)
Set the default branch config on the repo, if not configured yet.
Source code in src/conjuring/spells/git.py
switch_url_to(c, remote='origin', https=False)
Set an SSH or HTTPS URL for a remote.
Source code in src/conjuring/spells/git.py
tidy_up(c)
Prune remotes, update all branches of the repo, delete merged/squashed branches.
Source code in src/conjuring/spells/git.py
update_all(c, group='')
Run gita super to update and clean branches.
Source code in src/conjuring/spells/git.py
watch(c)
Watch a build on GitHub Actions, then open a pull request or repo after the build is over.
Source code in src/conjuring/spells/git.py
conjuring.spells.jrnl
Query tags and entries with the jrnl note-taking tool.
edit_last(c, journal='')
query(c, n=0, contains='', edit=False, fancy=False, short=False, journal='')
Query jrnl entries.
Source code in src/conjuring/spells/jrnl.py
tags(c, sort=False, rg='', journal='')
Query jrnl tags.
Source code in src/conjuring/spells/jrnl.py
conjuring.spells.k8s
Kubernetes: get pods, show variables from config maps, validate score and more.
Kubectl
dataclass
Kubectl commands.
Source code in src/conjuring/spells/k8s.py
choose_apps(partial_name=None, *, multi=False)
Select apps from Kubernetes deployments, using a partial app name and fzf.
Use the current dir as the app name if no partial app name is provided.
Source code in src/conjuring/spells/k8s.py
cmd_get(resource, apps)
run_get(resource, apps)
config_map(c, app, rg='')
Show the config map for an app.
Source code in src/conjuring/spells/k8s.py
exec_(c, app='')
Exec into the first pod found for the chosen app.
Source code in src/conjuring/spells/k8s.py
pods(c, app='', replica_set=False)
Show the pods and replica sets for an app.
Source code in src/conjuring/spells/k8s.py
validate_score(c)
Validate and score files that were changed from the master branch.
Source code in src/conjuring/spells/k8s.py
conjuring.spells.media
Media files: remove empty dirs, clean up picture dirs, download YouTube videos, transcribe audio.
CompareDirsAction
Bases: Enum
Actions to take when comparing two directories.
Source code in src/conjuring/spells/media.py
cleanup(c, browse=False)
Cleanup pictures.
Source code in src/conjuring/spells/media.py
compare_dirs(c, from_dir, to_dir, count=MAX_COUNT, size=MAX_SIZE, delete=False, move=False, wildcard_search=False)
Compare files in two directories. Stops when it reaches max count or size.
Source code in src/conjuring/spells/media.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
empty_dirs(c, dir_, delete=False, fd=True)
Remove some hidden files first, then remove empty dirs.
The ending slash is needed to search OneDrive, now that its behaviour changed in macOS Monterey.
Source code in src/conjuring/spells/media.py
invidious(c)
Parse Invidious instances to be used in the Chrome plugin random instance pool.
"Invidious random instance pool (comma-separated)" text field config from Privacy Redirect.
Source code in src/conjuring/spells/media.py
slideshow(c, start_at='')
Show pictures in the current dir with feh.
Source code in src/conjuring/spells/media.py
sync_subtitle(c, episode)
Sync subtitles for an episode or movie.
Source code in src/conjuring/spells/media.py
unzip_tree(c, dir_, count=1, delete=False)
Unzip .tar.gz files in a directory tree.
Source code in src/conjuring/spells/media.py
whisper(c, dir_)
Transcribe multiple audio file that haven't been transcribed yet, using whisper.
Source code in src/conjuring/spells/media.py
youtube_dl(c, url, min_height=360, download_archive_path='')
Download video URLs, try different low-res formats until it finds one.
Source code in src/conjuring/spells/media.py
zip_tree(c, dir_, count=1, depth=5, delete=False)
Zip files in a directory tree, creating a .tar.gz file.
Source code in src/conjuring/spells/media.py
conjuring.spells.mkdocs
MkDocs spells: install, build, deploy to GitHub, serve locally.
browse(c)
build(c)
deploy(c)
install(c, force=False)
Install MkDocs globally with the Material plugin. Upgrade if it already exists.
Source code in src/conjuring/spells/mkdocs.py
serve(c, browse=True)
Start the live-reloading server to test the docs locally. The "serve" command already builds the docs.
Source code in src/conjuring/spells/mkdocs.py
conjuring.spells.mr
myrepos repository management tool: grep text in repos.
MyRepos
dataclass
Find and interact with myrepos config files.
Source code in src/conjuring/spells/mr.py
find_configs(partial_name, echo=False)
Find config files in the current dir or dirs above.
Source code in src/conjuring/spells/mr.py
grep(c, search_text, config='', echo=False)
Grep mr repositories with a search text and print the directories in which the text was found.
Needs mr to be preconfigured with files starting with the ".mrconfig" prefix.
Source code in src/conjuring/spells/mr.py
conjuring.spells.onedrive
OneDrive: list files with conflicts.
conflicts(c, dir_)
List files with conflicts.
Source code in src/conjuring/spells/onedrive.py
force_downloads(c, dir_)
Force downloads of remote OneDrive files by reading them with a dummy "diff".
Source code in src/conjuring/spells/onedrive.py
conjuring.spells.paperless
Paperless: maintenance, renamer, sanity, delete duplicates.
Document
dataclass
A paperless document.
Source code in src/conjuring/spells/paperless.py
url
property
Return the URL to the document details page.
__repr__()
Return a string representation of the document.
OrphanFile
dataclass
delete_failed_duplicates(c, max_delete=100)
Delete records marked as duplicate but that cannot be downloaded. So the PDF files can be reimported.
Source code in src/conjuring/spells/paperless.py
empty_consume_dir(c, instance)
Empty the consume dir.
Source code in src/conjuring/spells/paperless.py
maintenance(c, instance, reindex=True, optimize=True, thumbnails=True)
Reindex all docs and optionally optimize them.
https://docs.paperless-ngx.com/administration/#index https://docs.paperless-ngx.com/administration/#thumbnails
Source code in src/conjuring/spells/paperless.py
paperless_cmd(instance='')
Command to run Paperless with Docker.
Source code in src/conjuring/spells/paperless.py
paperless_root_dir(instance='')
Root directory for Paperless.
Source code in src/conjuring/spells/paperless.py
paperless_token()
paperless_url()
rename(c, instance)
Rename files.
https://docs.paperless-ngx.com/administration/#renamer
sanity(c, instance, hide=False, orphans=False, thumbnails=False, documents=False, unknown=True, errors='', together=False, fix=False, move=False)
Sanity checker. Optionally fix orphan files (copies or movies them to the download dir).
https://docs.paperless-ngx.com/administration/#sanity-checker
Source code in src/conjuring/spells/paperless.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
conjuring.spells.pre_commit
pre-commit: install, uninstall, run/autoupdate selected hooks.
auto(c, repo='', bleed=False)
Autoupdate a Git hook or all hooks with the latest tag. Needs fzf and yq.
Source code in src/conjuring/spells/pre_commit.py
get_hook_types(commit_msg, desired_hooks=None)
Prepare a list of hook types to install/uninstall.
Source code in src/conjuring/spells/pre_commit.py
install(c, before, gc=False, commit_msg=True)
Install pre-commit with prek.
Source code in src/conjuring/spells/pre_commit.py
run(c, hooks)
Run all pre-commit hooks or a specific one using prek. Don't stop on failures. Needs fzf and yq.
Source code in src/conjuring/spells/pre_commit.py
uninstall(c, gc=False, commit_msg=True)
Uninstall ALL pre-commit hooks with prek.
Source code in src/conjuring/spells/pre_commit.py
conjuring.spells.py
Install venvs, run tests and coverage, install debug tools.
Poetry
dataclass
Poetry-related tasks.
Source code in src/conjuring/spells/py.py
guess_python_version()
Guess Python version from pyproject.toml.
Source code in src/conjuring/spells/py.py
parse_python_version(venv)
staticmethod
remove_venv(python_version)
use_venv(python_version)
used_in_project(display_error=True)
Check if Poetry is being used.
Source code in src/conjuring/spells/py.py
PyEnv
dataclass
pyenv-related tasks.
Source code in src/conjuring/spells/py.py
has_local()
list_versions(python_version=None)
List all installed Python versions, or only the ones matching the desired version.
Source code in src/conjuring/spells/py.py
Pytest
Pytest-related tasks.
Source code in src/conjuring/spells/py.py
coverage(c, show_all=False, s=False)
Run tests with pytest and coverage.
Source code in src/conjuring/spells/py.py
debug_tools(c, all_=False, ipython=False, ipdb=False, pudb=False, icecream=False, devtools=False, watch=False, watcher=False)
Install debug tools.
Source code in src/conjuring/spells/py.py
editable(c, inject='')
Hack to install a Poetry package as editable until Poetry supports PEP660 hooks.
It won't be needed anymore when https://github.com/python-poetry/poetry-core/pull/182 is merged.
Source code in src/conjuring/spells/py.py
install(c, version='', force=False, delete_all=False, pipx=False, editable=False)
Install a Python virtual environment. For now, only works with Poetry.
Source code in src/conjuring/spells/py.py
test(c, s=False)
Run tests with pytest.
Source code in src/conjuring/spells/py.py
watch(c)
conjuring.spells.shell
Shell: install/uninstall completion.
completion_install(c, app)
Install shell completion. For now, only for the Bash shell, and only for Click projects.
- Shell Completion — Click Documentation (8.0.x)
- click-contrib/click-completion: Add or enhance bash, fish, zsh and powershell completion in Click
Source code in src/conjuring/spells/shell.py
completion_list(c)
completion_uninstall(c, app)
Uninstall shell completion from both completion dirs.