[V3 Downloader] Revision tracking #2571
No reviewers
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot!2571
Loading…
Reference in a new issue
No description provided.
Delete branch "V3/issue_2527"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Description of the changes
This PR implements features proposed in #2527. (closes #2527)
Fully fixes #1866 - as said in #2605, the change was easier to do after this PR is finished so I decided to do it in this PR as well so that it actually gets done before 3.2 release.
Fixes #2927 - I added a check for installed cogs that have the same name and added a attribute to
InstalledModulethat keeps repo name as it was saved in Config.Due to size of the changes, I added myself to
CODEOWNERSfile.I know this doesn't actually give any benefit to people that don't have write permission to the repo but I saw other big fella devs doing this, so I assume this is what I should do.
Internal info: All function parameters are explicitly called
hash, if it can only be commit's full sha1 hash orrevif it can be anything that names a commit object, see linkDownloader cog - changed/added commands:
[p]repo updateupdates repos without updating any cogs[p]cog installcan now install multiple cogs[p]cog installversionallows you to install cogs from specific revision of repo[p]cog installversion <repo_name> <revision> <cogs>[p]cog pinand[p]cog unpinallows you to pin and unpin cogs (block/unblock updates)[p]cog checkforupdateschecks for available cog updates (listing will include pinned cogs)[p]cog updateallfromreposupdates all cogs from given repos[p]cog updatetoversionupdates chosen (or all) cogs to specific revision of repo[p]cog updatetoversion <repo_name> <revision [cogs]Downloader's tests:
Here's somewhat big change, I added git integration tests that will make sure that all the git commands we use give expected output. Most git commands require a repo to operate on so along with this I added a test repo and a new (cool) script at
tools/edit_testrepo.pythat will allow devs to easily import and export that repo from git fast-import format. I'm not gonna list all of the new tests but other changes that were done indirectly to tests are:asyncio.subprocessand default Windows loop doesn't work with it)pytest-mockrequirement totestsextra as mocking was very needed to tests Downloader's logic without depending on calling git part.Aaaaand, here you have changes that are rather boring for average reader:
Unfortunately, few public methods had to have their behaviour changed and therefore this PR is breaking change for devs using Downloader framework. To make it a little easier, I added [BREAKING] at the end of each change, which can be considered breaking (hopefully I haven't missed anything).
Downloader cog - internal changes:
installed_cogs = {'repo_name': {'cog_name': cog_json}}_maybe_update_config()installed_libraries()gives you installed libraries andinstalled_modules()gives you installed cogs and librariesRepoManagerandInstallableclasses - changes:RepoManagernow hasreposattribute which gives youtupleofRepoRepoManager.get_all_cogs()gets all cogs from all reposRepoManager.update_repo()returns 2-tuple instead of dictionary with one key [BREAKING]Installableholds commit information nowInstallablenow hasrepoattribute containing repo object orNoneif repo ismissing
InstalledModuleclass inheriting fromInstallable- all installed cogs/libraries should be represented by thisfrom_installable()method ofInstalledModulecreates instance fromInstallableto_json()andfrom_json()methods moved fromInstallabletoInstalledModulecog_namekey in internal cog's json changed its name tomodule_name, new keyscommitandpinned(only for cogs) addedRepoclass - changes:Repoholds commit information nowRepo.is_ancestor()checks if one revision is ancestor of the other.Repo.is_on_branch()checks if repo is currently on branchRepo.get_last_module_occurrence()tries to get module from last commit in which it still occurs (if it couldn't, it returnsNone)Repo.get_modified_modules()gets modified modules between two revisions and if any module doesn't exist in new revision, it will try usingRepo.get_last_module_occurrence()to find it.Repo.get_full_sha1()gets full sha1 object name from given revision.Repo.checkout()checks out repo to provided revision. The method can be awaited or used as async ctx manager:exit_to_revargument)revisNone, method won't do anything and whenforce_checkoutis set toTrue, checkout will be done even ifRepo.commitequalsrev/exit_to_revRepo.current_branch()will now properly error out if repo is in detached HEAD state instead of returning "HEAD" [BREAKING]Repo.current_commit()now returns commit, which the repo is on, instead of latest commit of branch,Repo.latest_commit()provides old behavior of this method [BREAKING]Repo._get_file_update_statuses()will now work properly with paths with spaces and with renames (treating them separately as addition and removal)Repo._run()calls will redirect stderr to debug log, if valid exit code is returned by process or to error log otherwiseRepo.install_cog()returnsInstalledModuleinstance now instead of bool representing success of install [BREAKING]CopyingErrorRepo.install_libraries()returns 2-tuple of installed and failed libraries instead of bool representing the success of install [BREAKING]Okay, I think, this is ready for review now, I added all things from my TODO list (which you can find in previous revision of issue description) and I changed whole issue description and updated it with all changes this PR does.
At the end, I have one question, should I make any new unit tests? I don't have a lot of experience with those, so I didn't add any, but if I should, I'll look into it.
I've marked this for 3.2 due to breakage concerns. While we haven't explicitly exposed some of this, changes to downloader have a large potential for negative impact if we don't announce every potential change in behavior with advance warning.
This PR is now ready for review. I updated PR's description with all the new stuff (splited into more and less interesting parts).
This PR's goal is especially adding support for revision tracking, later on I also decided on adding various tests for Downloader so this is here too. I might have fixed some things (bugs that have an open issue are mentioned in PR's description, but there might have been some other fixes) but there is still a lot of smaller QoL changes I will want to do after this PR gets merged - especially better error handling for git errors, but also replacing
subprocesswithasyncio.subprocess, option to auto-reinstall cogs from backup, looking for performance improvements in install/update processes and other stuff that have been mentioned before or has issue created.// not entirely sure if the breaking change label here is needed
Works great.