From 7eff6ac1b8805bbae7b2ab2cc33d914c9da5eb95 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Fri, 17 Feb 2023 15:44:52 +0200 Subject: [PATCH 1/3] add fetch-tags option to git plugin --- .gitignore | 1 + Makefile | 8 ++++++++ peru/resources/plugins/git/git_plugin.py | 13 +++++++++---- peru/resources/plugins/git/plugin.yaml | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index fe7dd1f7..e178a5ce 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__ peru.egg-info build/ dist/ +.venv/* diff --git a/Makefile b/Makefile index 1c06d933..8209cbb8 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,14 @@ deps-dev: ## Install development dependencies ##@ Utility +.PHONY: install +install: ## Install peru + $(PYTHON) setup.py install --user + +.PHONY: uninstall +uninstall: ## Uninstall peru + $(PIP) uninstall peru + .PHONY: help help: ## Display this help @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[\#a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) diff --git a/peru/resources/plugins/git/git_plugin.py b/peru/resources/plugins/git/git_plugin.py index 4f1b9b6b..11831852 100755 --- a/peru/resources/plugins/git/git_plugin.py +++ b/peru/resources/plugins/git/git_plugin.py @@ -153,12 +153,16 @@ def plugin_sync(url, rev): checkout_tree(url, rev, os.environ['PERU_SYNC_DEST']) -def plugin_reup(url, reup): +def plugin_reup(url, reup, fetchTags): reup_output = os.environ['PERU_REUP_OUTPUT'] repo_path = clone_if_needed(url) git_fetch(url, repo_path) - output = git( - 'rev-parse', reup, git_dir=repo_path, capture_output=True).output + if fetchTags: + output = git('describe', '--tags', '--abbrev=0', git_dir=repo_path, + capture_output=True).output + else: + output = git( + 'rev-parse', reup, git_dir=repo_path, capture_output=True).output with open(reup_output, 'w') as out_file: print('rev:', output.strip(), file=out_file) @@ -188,12 +192,13 @@ def main(): default_branch = git_default_branch(URL) REV = os.environ['PERU_MODULE_REV'] or default_branch REUP = os.environ['PERU_MODULE_REUP'] or default_branch + FETCH_TAGS = os.environ['PERU_MODULE_FETCH-TAGS'] == 'true' command = os.environ['PERU_PLUGIN_COMMAND'] if command == 'sync': plugin_sync(URL, REV) elif command == 'reup': - plugin_reup(URL, REUP) + plugin_reup(URL, REUP, FETCH_TAGS) else: raise RuntimeError('Unknown command: ' + repr(command)) diff --git a/peru/resources/plugins/git/plugin.yaml b/peru/resources/plugins/git/plugin.yaml index 7c09f072..6ad464b7 100644 --- a/peru/resources/plugins/git/plugin.yaml +++ b/peru/resources/plugins/git/plugin.yaml @@ -6,5 +6,6 @@ optional fields: - rev - reup - submodules + - fetch-tags cache fields: - url From f42c1ca78915284e74fdf0dc8cabc903acdc2951 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Fri, 17 Feb 2023 16:00:20 +0200 Subject: [PATCH 2/3] update docs --- CONTRIBUTING.md | 11 +++++++++++ README.md | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5ebff7ae..d8641eb1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,6 +80,17 @@ If you are working on a new feature please add tests to ensure the feature works Tests are stored in `peru/tests` and verify the current implementation to see how your test will fit in. +## Installing Locally + +To test your changes, you can install/uninstall the project locally: + +```bash +make install +``` +```bash +make uninstall +``` + ## Making a Pull Request Once you have made your changes and are ready to make a Pull Request please ensure tests and linting pass locally before pushing to GitHub. diff --git a/README.md b/README.md index e5ba9d5d..e253a0e4 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,11 @@ git module vim-solarized: url: https://github.com/altercation/vim-colors-solarized # Fetch this exact commit, instead of master or main. rev: 7a7e5c8818d717084730133ed6b84a3ffc9d0447 + +git module dracula: + url: https://github.com/dracula/vim + fetch-tags: true + rev: v1.5.0 ``` The contents of the `dircolors` module are copied to the root of our repo. The @@ -186,6 +191,12 @@ index 15c758d..7f0e26b 100644 url: https://github.com/altercation/vim-colors-solarized - rev: 7a7e5c8818d717084730133ed6b84a3ffc9d0447 + rev: 528a59f26d12278698bb946f8fb82a63711eec21 + + git module dracula: + url: https://github.com/dracula/vim + fetch-tags: true +- rev: v1.5.0 ++ rev: v2.0.0 ``` Peru made three changes: @@ -231,6 +242,7 @@ For cloning repos. These types all provide the same fields: - `rev`: optional, the specific revision/branch/tag to fetch - `reup`: optional, the branch/tag to get the latest rev from when running `peru reup` +- `fetch-tags`: optional, whether to fetch the latest tag instead of the latest commit hash when running `peru reup` The `git` type also supports setting `submodules: false` to skip fetching git submodules. Otherwise they're included by default. From 49d44f344bc1fe240324f68f1e5e44cf41d26ee5 Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Fri, 17 Feb 2023 18:30:35 +0200 Subject: [PATCH 3/3] rename `fetch-tags` to `reup-tag` --- README.md | 6 +++--- peru/resources/plugins/git/git_plugin.py | 8 ++++---- peru/resources/plugins/git/plugin.yaml | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index e253a0e4..80ac6204 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ git module vim-solarized: git module dracula: url: https://github.com/dracula/vim - fetch-tags: true + reup-tag: true rev: v1.5.0 ``` @@ -194,7 +194,7 @@ index 15c758d..7f0e26b 100644 git module dracula: url: https://github.com/dracula/vim - fetch-tags: true + reup-tag: true - rev: v1.5.0 + rev: v2.0.0 ``` @@ -242,7 +242,7 @@ For cloning repos. These types all provide the same fields: - `rev`: optional, the specific revision/branch/tag to fetch - `reup`: optional, the branch/tag to get the latest rev from when running `peru reup` -- `fetch-tags`: optional, whether to fetch the latest tag instead of the latest commit hash when running `peru reup` +- `reup-tag`: optional, whether to update the rev with the latest tag instead of the latest commit hash when running `peru reup` The `git` type also supports setting `submodules: false` to skip fetching git submodules. Otherwise they're included by default. diff --git a/peru/resources/plugins/git/git_plugin.py b/peru/resources/plugins/git/git_plugin.py index 11831852..a02ee631 100755 --- a/peru/resources/plugins/git/git_plugin.py +++ b/peru/resources/plugins/git/git_plugin.py @@ -153,11 +153,11 @@ def plugin_sync(url, rev): checkout_tree(url, rev, os.environ['PERU_SYNC_DEST']) -def plugin_reup(url, reup, fetchTags): +def plugin_reup(url, reup, reup_tag): reup_output = os.environ['PERU_REUP_OUTPUT'] repo_path = clone_if_needed(url) git_fetch(url, repo_path) - if fetchTags: + if reup_tag: output = git('describe', '--tags', '--abbrev=0', git_dir=repo_path, capture_output=True).output else: @@ -192,13 +192,13 @@ def main(): default_branch = git_default_branch(URL) REV = os.environ['PERU_MODULE_REV'] or default_branch REUP = os.environ['PERU_MODULE_REUP'] or default_branch - FETCH_TAGS = os.environ['PERU_MODULE_FETCH-TAGS'] == 'true' + REUP_TAG = os.environ['PERU_MODULE_REUP-TAG'] == 'true' command = os.environ['PERU_PLUGIN_COMMAND'] if command == 'sync': plugin_sync(URL, REV) elif command == 'reup': - plugin_reup(URL, REUP, FETCH_TAGS) + plugin_reup(URL, REUP, REUP_TAG) else: raise RuntimeError('Unknown command: ' + repr(command)) diff --git a/peru/resources/plugins/git/plugin.yaml b/peru/resources/plugins/git/plugin.yaml index 6ad464b7..c0c450f5 100644 --- a/peru/resources/plugins/git/plugin.yaml +++ b/peru/resources/plugins/git/plugin.yaml @@ -6,6 +6,6 @@ optional fields: - rev - reup - submodules - - fetch-tags + - reup-tag cache fields: - url