From 284a348dce4f2eb45ce150ad052ab7df64280889 Mon Sep 17 00:00:00 2001 From: "Jeffrey A. Clark" Date: Fri, 1 Aug 2025 08:01:05 -0400 Subject: [PATCH] Refactor with typer --- django_mongodb_cli/repo.py | 231 ++++++++++++++++++++++++++--------- django_mongodb_cli/utils.py | 236 ++++++++++++++++++++++++++---------- justfile | 2 + pyproject.toml | 168 +++++++++++++------------ test/settings/django.py | 6 +- 5 files changed, 441 insertions(+), 202 deletions(-) diff --git a/django_mongodb_cli/repo.py b/django_mongodb_cli/repo.py index 25ce1ad..c696aae 100644 --- a/django_mongodb_cli/repo.py +++ b/django_mongodb_cli/repo.py @@ -1,4 +1,5 @@ import typer +import os from .utils import Package, Repo, Test @@ -42,48 +43,42 @@ def main( raise typer.Exit() -@repo.command() -def status( - repo_name: str = typer.Argument(None), - all_repos: bool = typer.Option( - False, "--all-repos", "-a", help="Show status of all repos" - ), - reset: bool = typer.Option( - False, "--reset", "-r", help="Reset the status of the repository" - ), -): - repo = Repo() - if reset: - repo.set_reset(reset) - repo_command( - all_repos, - repo_name, - all_msg="Showing status for all repositories...", - missing_msg="Please specify a repository name or use --all-repos to show all repositories.", - single_func=lambda name: repo.get_repo_status(name), - all_func=lambda name: repo.get_repo_status(name), - ) - - @repo.command() def branch( repo_name: str = typer.Argument(None), branch_name: str = typer.Argument(None), + list_branches: bool = typer.Option( + False, "--list-branches", "-l", help="List branches of the repository" + ), all_repos: bool = typer.Option( False, "--all-repos", "-a", help="Show branches of all repositories" ), ): + """ + Checkout or create a branch in a repository. + If branch_name is provided, switch to that branch or create it if it doesn't exist. + If --all-repos is used, show branches for all repositories. + """ repo = Repo() if branch_name: repo.set_branch(branch_name) + # else: + # typer.echo( + # typer.style( + # "Create or set branch cannot be used with --all-repos.", + # fg=typer.colors.RED, + # ) + # ) + # return + repo_command( all_repos, repo_name, all_msg="Showing branches for all repositories...", missing_msg="Please specify a repository name or use --all-repos to show branches of all repositories.", - single_func=lambda name: repo.get_repo_branches(name), - all_func=lambda name: repo.get_repo_branches(name), + single_func=lambda repo_name: repo.get_repo_branch(repo_name), + all_func=lambda repo_name: repo.get_repo_branch(repo_name), ) @@ -97,6 +92,12 @@ def clone( False, "--install", "-i", help="Install after cloning" ), ): + """ + Clone a repository. + If --all-repos is used, clone all repositories. + If --install is used, install the package after cloning. + """ + def clone_repo(name): Repo().clone_repo(name) if install: @@ -120,17 +121,23 @@ def commit( ), message: str = typer.Argument(None, help="Commit message"), ): + """ + Commit changes in a repository with message provided or prompt for message. + """ + + if all_repos: + typer.echo( + typer.style("Commit cannot be used with --all-repos.", fg=typer.colors.RED) + ) + def do_commit(name): - if not message: - typer.echo(typer.style("Commit message is required.", fg=typer.colors.RED)) - raise typer.Exit(1) Repo().commit_repo(name, message) repo_command( all_repos, repo_name, all_msg="Committing all repositories...", - missing_msg="Please specify a repository name or use --all-repos to commit all repositories.", + missing_msg="Please specify a repository name.", single_func=do_commit, all_func=do_commit, ) @@ -146,6 +153,12 @@ def delete( False, "--uninstall", "-u", help="Uninstall after deleting" ), ): + """ + Delete the specified repository. + If --all-repos is used, delete all repositories. + If --uninstall is used, uninstall the package before deleting. + """ + def do_delete(name): if uninstall: Package().uninstall_package(name) @@ -169,13 +182,17 @@ def install( False, "--all-repos", "-a", help="Install all repositories" ), ): + """ + Install Python package found in the specified repository. + If --all-repos is used, install packages for all repositories. + """ repo_command( all_repos, repo_name, all_msg="Installing all repositories...", missing_msg="Please specify a repository name or use --all-repos to install all repositories.", - single_func=lambda name: Package().install_package(name), - all_func=lambda name: Package().install_package(name), + single_func=lambda repo_name: Package().install_package(repo_name), + all_func=lambda repo_name: Package().install_package(repo_name), ) @@ -186,13 +203,17 @@ def log( False, "--all-repos", "-a", help="Show logs of all repositories" ), ): + """ + Show logs for the specified repository. + If --all-repos is used, show logs for all repositories. + """ repo_command( all_repos, repo_name, all_msg="Showing logs for all repositories...", missing_msg="Please specify a repository name or use --all-repos to show logs of all repositories.", - single_func=lambda name: Repo().get_repo_log(repo_name), - all_func=lambda name: Repo().get_repo_log(repo_name), + single_func=lambda repo_name: Repo().get_repo_log(repo_name), + all_func=lambda repo_name: Repo().get_repo_log(repo_name), ) @@ -203,13 +224,17 @@ def open( False, "--all-repos", "-a", help="Open all repositories" ), ): + """ + Open the specified repository in the default web browser. + If --all-repos is used, open all repositories. + """ repo_command( all_repos, repo_name, all_msg="Opening all repositories...", missing_msg="Please specify a repository name or use --all-repos to open all repositories.", - single_func=lambda name: Repo().open_repo(repo_name), - all_func=lambda name: Repo().open_repo(repo_name), + single_func=lambda repo_name: Repo().open_repo(repo_name), + all_func=lambda repo_name: Repo().open_repo(repo_name), ) @@ -221,16 +246,45 @@ def origin( False, "--all-repos", "-a", help="Show origin of all repositories" ), ): + """ + Show or set the origin of a repository. + """ repo = Repo() + if repo_user and all_repos: + typer.echo( + typer.style( + "Set origin cannot be used with --all-repos.", + fg=typer.colors.RED, + ) + ) + return if repo_user: repo.set_user(repo_user) + repo_command( all_repos, repo_name, all_msg="Showing origin for all repositories...", missing_msg="Please specify a repository name or use --all-repos to show origins of all repositories.", single_func=lambda name: repo.get_repo_origin(name), - all_func=lambda name: repo.get_repo_origin(name), + all_func=lambda repo_name: repo.get_repo_origin(repo_name), + ) + + +@repo.command() +def patch( + repo_name: str = typer.Argument(None), +): + """ + Create an evergreen patch for the specified repository. + """ + repo_command( + False, + repo_name, + all_msg="Running evergreen...", + missing_msg="Please specify a repository name.", + single_func=lambda repo_name: Test().patch_repo(repo_name), + all_func=lambda repo_name: Test().patch_repo(repo_name), ) @@ -241,60 +295,110 @@ def pr( False, "--all-repos", "-a", help="Create pull requests for all repositories" ), ): + """ + Create a pull request for the specified repository. + """ repo_command( all_repos, repo_name, all_msg="Creating pull requests for all repositories...", missing_msg="Please specify a repository name or use --all-repos to create pull requests for all repositories.", - single_func=lambda name: Repo().create_pr(repo_name), - all_func=lambda name: Repo().create_pr(repo_name), + single_func=lambda repo_name: Repo().create_pr(repo_name), + all_func=lambda repo_name: Repo().create_pr(repo_name), ) @repo.command() -def sync( +def reset( repo_name: str = typer.Argument(None), all_repos: bool = typer.Option( - False, "--all-repos", "-a", help="Sync all repositories" + False, "--all-repos", "-a", help="Reset all repositories" ), ): + """ + Reset a repository to its initial state. + If --all-repos is used, reset all repositories. + """ + + def reset_repo(name): + Repo().reset_repo(name) + repo_command( all_repos, repo_name, - all_msg="Syncing all repositories...", - missing_msg="Please specify a repository name or use --all-repos to sync all repositories.", - single_func=lambda name: Repo().sync_repo(name), - all_func=lambda name: Repo().sync_repo(name), + all_msg="Resetting all repositories...", + missing_msg="Please specify a repository name or use --all-repos to reset all repositories.", + single_func=reset_repo, + all_func=reset_repo, ) @repo.command() -def patch( +def status( repo_name: str = typer.Argument(None), + all_repos: bool = typer.Option( + False, "--all-repos", "-a", help="Show status of all repos" + ), ): + """ + Show the status of a repository. + If --all-repos is used, show the status for all repositories. + """ + repo = Repo() repo_command( - False, + all_repos, repo_name, - all_msg="Running evergreen...", - missing_msg="Please specify a repository name.", - single_func=lambda name: Test().patch_repo(name), - all_func=lambda name: Test().patch_repo(name), + all_msg="Showing status for all repositories...", + missing_msg="Please specify a repository name or use --all-repos to show all repositories.", + single_func=lambda repo_name: repo.get_repo_status(repo_name), + all_func=lambda repo_name: repo.get_repo_status(repo_name), ) @repo.command() -def test( +def sync( repo_name: str = typer.Argument(None), - modules: list[str] = typer.Argument(None), all_repos: bool = typer.Option( - False, "--all-repos", "-a", help="Run tests for all repositories" + False, "--all-repos", "-a", help="Sync all repositories" ), +): + """ + Sync a repository with its remote counterpart. + If --all-repos is used, sync all repositories. + """ + repo = Repo() + if not repo.map: + typer.echo( + typer.style( + f"No repositories found in {os.path.join(os.getcwd(), repo.pyproject_file)}.", + fg=typer.colors.RED, + ) + ) + raise typer.Exit() + + repo_command( + all_repos, + repo_name, + all_msg="Syncing all repositories...", + missing_msg="Please specify a repository name or use --all-repos to sync all repositories.", + single_func=lambda repo_name: repo.sync_repo(repo_name), + all_func=lambda repo_name: repo.sync_repo(repo_name), + ) + + +@repo.command() +def test( + repo_name: str = typer.Argument(None), + modules: list[str] = typer.Argument(None), keep_db: bool = typer.Option( False, "--keepdb", help="Keep the database after tests" ), keyword: str = typer.Option( None, "--keyword", "-k", help="Run tests with the specified keyword" ), + list_tests: bool = typer.Option( + False, "--list-tests", "-l", help="List tests instead of running them" + ), setenv: bool = typer.Option( False, "--setenv", @@ -302,6 +406,13 @@ def test( help="Set DJANGO_SETTINGS_MODULE environment variable", ), ): + """ + Run tests for a repository. + If --modules is provided, run tests for the specified modules. + If --keepdb is used, keep the database after tests. + If --keyword is provided, run tests with the specified keyword. + If --setenv is used, set the DJANGO_SETTINGS_MODULE environment variable. + """ test_runner = Test() if modules: test_runner.set_modules(modules) @@ -311,13 +422,15 @@ def test( test_runner.set_keyword(keyword) if setenv: test_runner.set_env(setenv) + if list_tests: + test_runner.set_list_tests(list_tests) repo_command( - all_repos, + False, repo_name, - all_msg="Running tests for all repositories...", - missing_msg="Please specify a repository name or use --all-repos to run tests for all repositories.", - single_func=lambda name: test_runner.run_tests(name), - all_func=lambda name: test_runner.run_tests(name), - repo_list=test_runner.map, # Use Test().map instead of Repo().map + all_msg=None, + missing_msg="Please specify a repository name.", + single_func=lambda repo_name: test_runner.run_tests(repo_name), + repo_list=test_runner.map, + all_func=None, ) diff --git a/django_mongodb_cli/utils.py b/django_mongodb_cli/utils.py index 5c27d8a..5d3db21 100644 --- a/django_mongodb_cli/utils.py +++ b/django_mongodb_cli/utils.py @@ -7,6 +7,7 @@ import tempfile from git import Repo as GitRepo +from git import GitCommandError from pathlib import Path URL_PATTERN = re.compile(r"git\+ssh://(?:[^@]+@)?([^/]+)/([^@]+)") @@ -25,11 +26,12 @@ class Repo: def __init__(self, pyproject_file: Path = Path("pyproject.toml")): self.pyproject_file = pyproject_file self.config = self._load_config() - self.path = Path(self.config["tool"]["django_mongodb_cli"]["path"]) + self.path = Path( + self.config.get("tool", {}).get("django-mongodb-cli", {}).get("path", ".") + ).resolve() self.map = self.get_map() self.branch = None self.user = None - self.reset = False def _load_config(self) -> dict: return toml.load(self.pyproject_file) @@ -259,14 +261,66 @@ def get_repo_log(self, repo_name: str) -> None: def get_map(self) -> dict: """ Return a dict mapping repo_name to repo_url from repos in - [tool.django_mongodb_cli.repos]. + [tool.django-mongodb-cli.repos]. """ return { repo.split("@", 1)[0].strip(): repo.split("@", 1)[1].strip() - for repo in self.config["tool"]["django_mongodb_cli"].get("repos", []) + for repo in self.config.get("tool", {}) + .get("django-mongodb-cli", {}) + .get("repos", []) if "@" in repo } + def get_repo_branch(self, repo_name: str) -> list: + """ + Get the current branch of the specified repository. + If the repository does not exist, return an empty list. + """ + path = self.get_repo_path(repo_name) + repo = self.get_repo(path) + + # Checkout or create branch if self.branch is set + if self.branch: + try: + typer.echo( + typer.style( + f"Checking out branch: {self.branch}", fg=typer.colors.CYAN + ) + ) + repo.git.checkout(self.branch) + return + except GitCommandError: + typer.echo( + typer.style( + f"Branch '{self.branch}' does not exist. Creating new branch.", + fg=typer.colors.YELLOW, + ) + ) + repo.git.checkout("-b", self.branch) + return + + typer.echo( + typer.style(f"Getting current branch for {repo_name}", fg=typer.colors.CYAN) + ) + + if not os.path.exists(path): + typer.echo( + typer.style( + f"Repository '{repo_name}' not found at path: {path}", + fg=typer.colors.RED, + ) + ) + return [] + + current_branch = repo.active_branch.name + typer.echo( + typer.style( + f"Current branch for {repo_name}: {current_branch}", + fg=typer.colors.GREEN, + ) + ) + return [current_branch] + def get_repo_branches(self, repo_name: str) -> list: """ Get a list of both local and remote branches for the specified repository. @@ -295,13 +349,6 @@ def get_repo_branches(self, repo_name: str) -> list: if ref.name != "origin/HEAD" ] - if self.branch: - typer.echo( - typer.style(f"Checking out branch: {self.branch}", fg=typer.colors.CYAN) - ) - repo.git.checkout(self.branch) - return - typer.echo( typer.style( f"Getting branches for repository: {repo_name}", fg=typer.colors.CYAN @@ -336,23 +383,28 @@ def get_repo_origin(self, repo_name: str) -> str: repo = self.get_repo(path) origin_url = repo.remotes.origin.url origin_users = ( - self.config.get("tool").get("django_mongodb_cli").get("origin", []) + self.config.get("tool").get("django-mongodb-cli").get("origin", []) ) if repo_name in origin_users and self.user: for user in origin_users[repo_name]: if user.get("user") == self.user: + typer.echo( + typer.style( + f"Setting origin URL for {repo_name}: {origin_url}", + fg=typer.colors.GREEN, + ) + ) origin_url = user.get("repo") origin = repo.remotes.origin origin.set_url(origin_url) - typer.echo( - typer.style( - f"Origin URL for {repo_name}: {origin_url}", fg=typer.colors.GREEN - ) + typer.echo( + typer.style( + f"Origin URL for {repo_name}: {origin_url}", fg=typer.colors.GREEN ) - return origin_url + ) - def get_repo_path(self, name: str) -> Path: - return (self.path / name).resolve() + def get_repo_path(self, repo_name: str) -> Path: + return (self.path / repo_name).resolve() def get_repo(self, path: str) -> GitRepo: return GitRepo(path) @@ -361,32 +413,6 @@ def get_repo_status(self, repo_name: str) -> str: """ Get the status of a repository. """ - if self.reset: - typer.echo( - typer.style(f"Resetting repository: {repo_name}", fg=typer.colors.CYAN) - ) - path = self.get_repo_path(repo_name) - if not os.path.exists(path): - typer.echo( - typer.style( - f"Repository '{repo_name}' not found at path: {path}", - fg=typer.colors.RED, - ) - ) - return - repo = self.get_repo(path) - repo.git.reset("--hard") - typer.echo( - typer.style( - f"✅ Repository {repo_name} has been reset.", fg=typer.colors.GREEN - ) - ) - return - typer.echo( - typer.style( - f"Getting status for repository: {repo_name}", fg=typer.colors.CYAN - ) - ) path = self.get_repo_path(repo_name) if not os.path.exists(path): @@ -540,16 +566,10 @@ def open_repo(self, repo_name: str) -> None: ) ) - def run_tests(self, repo_name: str) -> None: - """ - Run tests for the specified repository. - """ + def reset_repo(self, repo_name: str) -> None: typer.echo( - typer.style( - f"Running tests for repository: {repo_name}", fg=typer.colors.CYAN - ) + typer.style(f"Resetting repository: {repo_name}", fg=typer.colors.CYAN) ) - path = self.get_repo_path(repo_name) if not os.path.exists(path): typer.echo( @@ -559,15 +579,63 @@ def run_tests(self, repo_name: str) -> None: ) ) return + repo = self.get_repo(path) + repo.git.reset("--hard") + typer.echo( + typer.style( + f"✅ Repository {repo_name} has been reset.", fg=typer.colors.GREEN + ) + ) - Test().run_tests(repo_name) + def _list_tests(self, repo_name: str) -> None: + """ + List all tests for the specified repository. + """ typer.echo( typer.style( - f"✅ Tests completed successfully for {repo_name}.", - fg=typer.colors.GREEN, + f"Listing tests for repository: {repo_name}", fg=typer.colors.CYAN ) ) + test_dir = ( + self.config.get("tool") + .get("django-mongodb-cli") + .get("test") + .get(repo_name) + .get("test_dir") + ) + if not os.path.exists(test_dir): + typer.echo( + typer.style( + f"Test directory '{test_dir}' does not exist for {repo_name}.", + fg=typer.colors.RED, + ) + ) + return + try: + test_files = [ + f + for f in os.listdir(test_dir) + if f.endswith(".py") and not f.startswith("__") + ] + if not test_files: + typer.echo( + typer.style( + f"No tests found in {test_dir} for {repo_name}.", + fg=typer.colors.YELLOW, + ) + ) + return + typer.echo(typer.style("Found tests:", fg=typer.colors.GREEN)) + for test_file in sorted(test_files): + typer.echo(f" - {test_file}") + except Exception as e: + typer.echo( + typer.style( + f"❌ Failed to list tests for {repo_name}: {e}", fg=typer.colors.RED + ) + ) + def set_branch(self, branch: str) -> None: self.branch = branch @@ -575,12 +643,7 @@ def set_reset(self, reset: bool) -> None: self.reset = reset def set_user(self, user: str) -> None: - """ - Set the user for the repository operations. - This can be used to specify which user to use for operations like cloning. - """ self.user = user - typer.echo(typer.style(f"User set to: {self.user}", fg=typer.colors.CYAN)) def sync_repo(self, repo_name: str) -> None: """ @@ -734,6 +797,7 @@ def __init__(self, pyproject_file: Path = Path("pyproject.toml")): self.keep_db = False self.keyword = None self.setenv = False + self.list_tests = False def copy_settings(self, repo_name: str) -> None: """ @@ -801,21 +865,21 @@ def patch_repo(self, repo_name: str) -> None: ) project_name = ( self.config.get("tool", {}) - .get("django_mongodb_cli", {}) + .get("django-mongodb-cli", {}) .get("evergreen", {}) .get(repo_name) .get("project_name") ) subprocess.run( - ["evergreen", "patch", "-p", project_name, "-u", "--finalize"], + ["evergreen", "patch", "-p", project_name, "-u"], check=True, cwd=self.get_repo_path(repo_name), ) - def run_tests(self, repo_name: str) -> None: + def _run_tests(self, repo_name: str) -> None: self.test_settings = ( self.config.get("tool", {}) - .get("django_mongodb_cli", {}) + .get("django-mongodb-cli", {}) .get("test", {}) .get(repo_name, {}) ) @@ -867,6 +931,44 @@ def run_tests(self, repo_name: str) -> None: cwd=test_dir, ) + def run_tests(self, repo_name: str) -> None: + """ + Run tests for the specified repository. + """ + + if self.list_tests: + typer.echo( + typer.style( + f"Listing tests for repository: {repo_name}", fg=typer.colors.CYAN + ) + ) + self._list_tests(repo_name) + return + + typer.echo( + typer.style( + f"Running tests for repository: {repo_name}", fg=typer.colors.CYAN + ) + ) + + path = self.get_repo_path(repo_name) + if not os.path.exists(path): + typer.echo( + typer.style( + f"Repository '{repo_name}' not found at path: {path}", + fg=typer.colors.RED, + ) + ) + return + + self._run_tests(repo_name) + typer.echo( + typer.style( + f"✅ Tests completed successfully for {repo_name}.", + fg=typer.colors.GREEN, + ) + ) + def set_modules(self, modules: list) -> None: self.modules = modules @@ -878,6 +980,10 @@ def set_keyword(self, keyword: str) -> None: """Set a keyword to filter tests.""" self.keyword = keyword + def set_list_tests(self, list_tests: bool) -> None: + """Set whether to list tests instead of running them.""" + self.list_tests = list_tests + def set_env(self, setenv: bool) -> None: """Set whether to set DJANGO_SETTINGS_MODULE environment variable.""" self.setenv = setenv diff --git a/justfile b/justfile index 2551f41..5ad8cef 100644 --- a/justfile +++ b/justfile @@ -11,6 +11,8 @@ git-clone: dm repo clone django --install dm repo clone django-mongodb-app dm repo clone django-mongodb-backend --install + dm repo origin django-mongodb-backend aclark4life + dm repo sync django-mongodb-backend dm repo clone django-mongodb-extensions --install dm repo clone django-mongodb-project dm repo clone mongo-python-driver --install diff --git a/pyproject.toml b/pyproject.toml index 4f5b2e6..0da43d2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,34 +2,44 @@ name = "django-mongodb-cli" version = "0.1.0" dependencies = [ - "GitPython", # For git integration - "Sphinx", # For django-mongodb-backend documentation - "black", - "django-extensions", # <3 django-extensions + # --- allauth --- + "django-ninja", + "fido2", + "psycopg2", + "python3-openid", + "python3-saml", + "pyjwt[crypto]", + "requests-oauthlib", + + # --- DRF --- + "pytest-django", + "setuptools", + + # --- debug toolbar --- "django-debug-toolbar", - "django-ninja", # For django-allauth - "dj-database-url", # For startproject and testing with postgres - "fido2", # For django-allauth - "html5lib", # Required by django-debug-toolbar - "psycopg2", # For django-allauth - "python3-openid", # For django-allauth - "python3-saml", # For django-allauth - "pyjwt[crypto]", # For django-allauth - "pymongocrypt", # For django-mongodb-backend QE - "pymongo-auth-aws", # For django-mongodb-backend QE + "html5lib", + "pytest-django", + + # --- filter --- + "pytz", + + # --- everything else --- + "GitPython", + "Sphinx", + "black", + "django-extensions", + "dj-database-url", + "pymongocrypt", + "pymongo-auth-aws", "pytest", "pytest-html", - "pytest-django", # For django-rest-framework and django-debug-toolbar - "python-webpack-boilerplate", # For startproject - "pytz", # For django-filter - "requests-oauthlib", # For django-allauth + "python-webpack-boilerplate", "rich", - "setuptools", # For django-rest-framework - "sphinx-autobuild", # For django-mongodb-backend documentation - "sphinx-copybutton", # For django-mongodb-backend documentation + "sphinx-autobuild", + "sphinx-copybutton", "toml", "typer", - "wagtail", # For django-mongodb-templates + "wagtail", ] [project.scripts] @@ -38,42 +48,49 @@ dm = "django_mongodb_cli:dm" [tool.setuptools] packages = ["django_mongodb_cli"] -[tool.django_mongodb_cli] +[tool.django-mongodb-cli] repos = [ - "django @ git+ssh://git@github.com/mongodb-forks/django@mongodb-5.2.x", + # 1. Third-Party Libs "django-allauth @ git+ssh://git@github.com/pennersr/django-allauth@main", - "django-debug-toolbar @ git+ssh://git@github.com/django-commons/django-debug-toolbar@main", + "xmlsec @ git+ssh://git@github.com/xmlsec/python-xmlsec@main", + "django-rest-framework @ git+ssh://git@github.com/encode/django-rest-framework@main", "django-filter @ git+ssh://git@github.com/carltongibson/django-filter@main", + "django-debug-toolbar @ git+ssh://git@github.com/django-commons/django-debug-toolbar@main", + "wagtail @ git+ssh://git@github.com/mongodb-forks/wagtail@main", + "wagtail-mongodb-project @ git+ssh://git@github.com/mongodb-labs/wagtail-mongodb-project@main", + + # 2. Django MongoDB Backend + "django @ git+ssh://git@github.com/mongodb-forks/django@mongodb-5.2.x", "django-mongodb-app @ git+ssh://git@github.com/mongodb-labs/django-mongodb-app@5.2.x", "django-mongodb-backend @ git+ssh://git@github.com/mongodb/django-mongodb-backend@main", "django-mongodb-extensions @ git+ssh://git@github.com/mongodb-labs/django-mongodb-extensions@main", "django-mongodb-project @ git+ssh://git@github.com/mongodb-labs/django-mongodb-project@5.2.x", "django-mongodb-project-benchmark @ git+ssh://git@github.com/NoahStapp/django-mongodb-backend-benchmark.git@main", - "django-rest-framework @ git+ssh://git@github.com/encode/django-rest-framework@main", + "mongo-python-driver @ git+ssh://git@github.com/mongodb/mongo-python-driver@master", + + # 3. QE + "pymongo-auth-aws @ git+ssh://git@github.com/mongodb/pymongo-auth-aws@master", + "libmongocrypt @ git+ssh://git@github.com/mongodb-labs/libmongocrypt@master", + + # 4. MongoDB "drivers-evergreen-tools @ git+ssh://git@github.com/mongodb-labs/drivers-evergreen-tools@master", "docs @ git+ssh://git@github.com/mongodb/docs@main", "flask-pymongo @ git+ssh://git@github.com/mongodb-labs/flask-pymongo", "langchain-mongodb @ git+ssh://git@github.com/langchain-ai/langchain-mongodb@main", - "libmongocrypt @ git+ssh://git@github.com/mongodb-labs/libmongocrypt@master", "mongo-arrow @ git+ssh://git@github.com/mongodb-labs/mongo-arrow@main", "mongo-orchestration @ git+ssh://git@github.com/mongodb-labs/mongo-orchestration@master", - "mongo-python-driver @ git+ssh://git@github.com/mongodb/mongo-python-driver@master", - "pymongo-auth-aws @ git+ssh://git@github.com/mongodb/pymongo-auth-aws@master", "specifications @ git+ssh://git@github.com/mongodb/specifications@master", - "wagtail @ git+ssh://git@github.com/mongodb-forks/wagtail@main", - "wagtail-mongodb-project @ git+ssh://git@github.com/mongodb-labs/wagtail-mongodb-project@main", "winkerberos @ git+ssh://git@github.com/mongodb-labs/winkerberos@main", - "xmlsec @ git+ssh://git@github.com/xmlsec/python-xmlsec@main", ] path = "src" -[tool.django_mongodb_cli.test.mongo-python-driver] +[tool.django-mongodb-cli.test.mongo-python-driver] test_command = "just" test_dir = "src/mongo-python-driver/test" clone_dir = "src/mongo-python-driver" test_dirs = ["src/mongo-python-driver/test"] -[tool.django_mongodb_cli.test.django] +[tool.django-mongodb-cli.test.django] test_command = "./runtests.py" test_options = [ "--parallel", @@ -87,75 +104,75 @@ test_dir = "src/django/tests" clone_dir = "src/django" test_dirs = [ "src/django/tests", "src/django-mongodb-backend/tests" ] -[tool.django_mongodb_cli.test.django.migrations_dir] +[tool.django-mongodb-cli.test.django.migrations_dir] source = "mongo_migrations" target = "src/django/tests/mongo_migrations" -[tool.django_mongodb_cli.test.django.settings.test] +[tool.django-mongodb-cli.test.django.settings.test] source = "test/settings/django.py" target = "src/django/tests/mongo_settings.py" -[tool.django_mongodb_cli.test.django.settings.migrations] +[tool.django-mongodb-cli.test.django.settings.migrations] source = "test/settings/django_migrations.py" target = "src/django/tests/mongo_settings.py" -[tool.django_mongodb_cli.test.django.settings.module] +[tool.django-mongodb-cli.test.django.settings.module] test = "mongo_settings" migrations = "mongo_settings" -[tool.django_mongodb_cli.test.django-filter] +[tool.django-mongodb-cli.test.django-filter] test_command = "./runtests.py" test_dir = "src/django-filter" clone_dir = "src/django-filter" test_dirs = ["src/django-filter/tests"] -[tool.django_mongodb_cli.test.django-filter.apps_file] +[tool.django-mongodb-cli.test.django-filter.apps_file] source = "test/apps/django_filter.py" target = "src/django-filter/tests/mongo_apps.py" -[tool.django_mongodb_cli.test.django-filter.migrations_dir] +[tool.django-mongodb-cli.test.django-filter.migrations_dir] source = "mongo_migrations" target = "src/django-filter/tests/mongo_migrations" -[tool.django_mongodb_cli.test.django-filter.settings.test] +[tool.django-mongodb-cli.test.django-filter.settings.test] source = "test/settings/django_filter.py" target = "src/django-filter/tests/settings.py" -[tool.django_mongodb_cli.test.django-filter.settings.migrations] +[tool.django-mongodb-cli.test.django-filter.settings.migrations] source = "test/settings/django_filter.py" target = "src/django-filter/tests/settings.py" -[tool.django_mongodb_cli.test.django-filter.settings.module] +[tool.django-mongodb-cli.test.django-filter.settings.module] test = "tests.settings" migrations = "tests.settings" -[tool.django_mongodb_cli.test.django-rest-framework] +[tool.django-mongodb-cli.test.django-rest-framework] test_command = "./runtests.py" test_dir = "src/django-rest-framework" clone_dir = "src/django-rest-framework" test_dirs = ["src/django-rest-framework/tests"] -[tool.django_mongodb_cli.test.django-rest-framework.apps_file] +[tool.django-mongodb-cli.test.django-rest-framework.apps_file] source = "test/apps/rest_framework.py" target = "src/django-rest-framework/tests/mongo_apps.py" -[tool.django_mongodb_cli.test.django-rest-framework.migrations_dir] +[tool.django-mongodb-cli.test.django-rest-framework.migrations_dir] source = "mongo_migrations" target = "src/django-rest-framework/tests/mongo_migrations" -[tool.django_mongodb_cli.test.django-rest-framework.settings.test] +[tool.django-mongodb-cli.test.django-rest-framework.settings.test] source = "test/settings/rest_framework.py" target = "src/django-rest-framework/tests/conftest.py" -[tool.django_mongodb_cli.test.django-rest-framework.settings.migrations] +[tool.django-mongodb-cli.test.django-rest-framework.settings.migrations] source = "test/settings/rest_framework_migrations.py" target = "src/django-rest-framework/tests/conftest.py" -[tool.django_mongodb_cli.test.django-rest-framework.settings.module] +[tool.django-mongodb-cli.test.django-rest-framework.settings.module] test = "tests.conftest" migrations = "tests.conftest" -[tool.django_mongodb_cli.test.wagtail] +[tool.django-mongodb-cli.test.wagtail] test_command = "./runtests.py" test_dir = "src/wagtail" clone_dir = "src/wagtail" @@ -164,71 +181,71 @@ test_dirs = [ "src/wagtail/wagtail/test" ] -[tool.django_mongodb_cli.test.wagtail.apps_file] +[tool.django-mongodb-cli.test.wagtail.apps_file] source = "test/apps/wagtail.py" target = "src/wagtail/wagtail/test/mongo_apps.py" -[tool.django_mongodb_cli.test.wagtail.migrations_dir] +[tool.django-mongodb-cli.test.wagtail.migrations_dir] source = "mongo_migrations" target = "src/wagtail/wagtail/test/mongo_migrations" -[tool.django_mongodb_cli.test.wagtail.settings.test] +[tool.django-mongodb-cli.test.wagtail.settings.test] source = "test/settings/wagtail.py" target = "src/wagtail/wagtail/test/mongo_settings.py" -[tool.django_mongodb_cli.test.wagtail.settings.migrations] +[tool.django-mongodb-cli.test.wagtail.settings.migrations] source = "test/settings/wagtail.py" target = "src/wagtail/wagtail/test/mongo_settings.py" -[tool.django_mongodb_cli.test.wagtail.settings.module] +[tool.django-mongodb-cli.test.wagtail.settings.module] test = "wagtail.test.mongo_settings" migrations = "wagtail.test.mongo_settings" -[tool.django_mongodb_cli.test.django-debug-toolbar] +[tool.django-mongodb-cli.test.django-debug-toolbar] test_command = "pytest" test_dir = "src/django-debug-toolbar" clone_dir = "src/django-debug-toolbar" test_dirs = ["src/django-debug-toolbar/tests"] -[tool.django_mongodb_cli.test.django-debug-toolbar.apps_file] +[tool.django-mongodb-cli.test.django-debug-toolbar.apps_file] source = "test/apps/debug_toolbar.py" target = "src/django-debug-toolbar/debug_toolbar/mongo_apps.py" -[tool.django_mongodb_cli.test.django-debug-toolbar.settings.test] +[tool.django-mongodb-cli.test.django-debug-toolbar.settings.test] source = "test/settings/debug_toolbar.py" target = "src/django-debug-toolbar/debug_toolbar/mongo_settings.py" -[tool.django_mongodb_cli.test.django-debug-toolbar.settings.migrations] +[tool.django-mongodb-cli.test.django-debug-toolbar.settings.migrations] source = "test/settings/debug_toolbar.py" target = "src/django-debug-toolbar/debug_toolbar/mongo_settings.py" -[tool.django_mongodb_cli.test.django-debug-toolbar.settings.module] +[tool.django-mongodb-cli.test.django-debug-toolbar.settings.module] test = "debug_toolbar.mongo_settings" migrations = "debug_toolbar.mongo_settings" -[tool.django_mongodb_cli.test.django-mongodb-extensions] +[tool.django-mongodb-cli.test.django-mongodb-extensions] test_command = "pytest" test_dir = "src/django-mongodb-extensions" clone_dir = "src/django-mongodb-extensions" test_dirs = ["src/django-mongodb-extensions/django_mongodb_extensions/tests"] -[tool.django_mongodb_cli.test.django-mongodb-extensions.apps_file] +[tool.django-mongodb-cli.test.django-mongodb-extensions.apps_file] source = "test/apps/django_mongodb_extensions.py" target = "src/django-mongodb-extensions/django_mongodb_extensions/mongo_apps.py" -[tool.django_mongodb_cli.test.django-mongodb-extensions.settings.test] +[tool.django-mongodb-cli.test.django-mongodb-extensions.settings.test] source = "test/settings/django_mongodb_extensions.py" target = "src/django-mongodb-extensions/django_mongodb_extensions/mongo_settings.py" -[tool.django_mongodb_cli.test.django-mongodb-extensions.settings.migrations] +[tool.django-mongodb-cli.test.django-mongodb-extensions.settings.migrations] source = "test/extensions/debug_toolbar_settings.py" target = "src/django-mongodb-extensions/django_mongodb_extensions/mongo_settings.py" -[tool.django_mongodb_cli.test.django-mongodb-extensions.settings.module] +[tool.django-mongodb-cli.test.django-mongodb-extensions.settings.module] test = "django_mongodb_extensions.mongo_settings" migrations = "django_mongodb_extensions.mongo_settings" -[tool.django_mongodb_cli.test.django-allauth] +[tool.django-mongodb-cli.test.django-allauth] test_command = "pytest" test_dir = "src/django-allauth" clone_dir = "src/django-allauth" @@ -259,33 +276,34 @@ test_dirs = [ "src/django-allauth/tests" ] -[tool.django_mongodb_cli.test.django-allauth.apps_file] +[tool.django-mongodb-cli.test.django-allauth.apps_file] source = "test/apps/allauth.py" target = "src/django-allauth/allauth/mongo_apps.py" -[tool.django_mongodb_cli.test.django-allauth.settings.test] +[tool.django-mongodb-cli.test.django-allauth.settings.test] source = "test/settings/allauth.py" target = "src/django-allauth/allauth/mongo_settings.py" -[tool.django_mongodb_cli.test.django-allauth.settings.migrations] +[tool.django-mongodb-cli.test.django-allauth.settings.migrations] source = "test/settings/allauth.py" target = "src/django-allauth/allauth/mongo_settings.py" -[tool.django_mongodb_cli.test.django-allauth.settings.module] +[tool.django-mongodb-cli.test.django-allauth.settings.module] test = "allauth.mongo_settings" migrations = "allauth.mongo_settings" -[tool.django_mongodb_cli.test.django-allauth.migrations_dir] +[tool.django-mongodb-cli.test.django-allauth.migrations_dir] source = "mongo_migrations" target = "src/django-allauth/allauth/mongo_migrations" -[[tool.django_mongodb_cli.origin.django-mongodb-backend]] +[[tool.django-mongodb-cli.origin.django-mongodb-backend]] user = "aclark4life" repo = "git+ssh://git@github.com/aclark4life/django-mongodb-backend" -[[tool.django_mongodb_cli.origin.django-mongodb-backend]] +[[tool.django-mongodb-cli.origin.django-mongodb-backend]] user = "mongodb" repo = "git+ssh://git@github.com/mongodb/django-mongodb-backend" -[tool.django_mongodb_cli.evergreen.django-mongodb-backend] +[tool.django-mongodb-cli.evergreen.django-mongodb-backend] project_name = "django-mongodb" +tasks = ["run-tests"] diff --git a/test/settings/django.py b/test/settings/django.py index 6a2d870..042a234 100644 --- a/test/settings/django.py +++ b/test/settings/django.py @@ -111,7 +111,7 @@ DATABASE_URL, db_name="test", ), - "my_encrypted_database": parse_uri( + "other": parse_uri( DATABASE_URL, options={ "auto_encryption_opts": AutoEncryptionOpts( @@ -120,10 +120,10 @@ # schema_map=EXPECTED_ENCRYPTED_FIELDS_MAP, ) }, - db_name="my_encrypted_database", + db_name="other", ), } -DATABASES["my_encrypted_database"]["KMS_CREDENTIALS"] = encryption.KMS_CREDENTIALS +DATABASES["other"]["KMS_CREDENTIALS"] = encryption.KMS_CREDENTIALS DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField" PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",)