Skip to content

Commit c3efd75

Browse files
authored
Merge pull request #48 from aclark4life/main
Misc updates
2 parents 284ce65 + 3bdd4e9 commit c3efd75

File tree

9 files changed

+580
-166
lines changed

9 files changed

+580
-166
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ django_mongodb_cli/__pycache__/
44
.idea
55
server.log
66
mongocryptd.pid
7+
.python-version
8+
build/
9+
uv.lock

WARP.md

Lines changed: 328 additions & 0 deletions
Large diffs are not rendered by default.

django_mongodb_cli/repo.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from .utils import Package, Repo, Test
55

6-
repo = typer.Typer()
6+
repo = typer.Typer(help="Manage Git repositories")
77
repo_remote = typer.Typer()
88
repo.add_typer(repo_remote, name="remote", help="Manage Git repositories")
99

@@ -35,9 +35,7 @@ def main(
3535
list_repos: bool = typer.Option(
3636
False, "--list-repos", "-l", help="List available repositories."
3737
),
38-
quiet: bool = typer.Option(
39-
False, "--quiet", "-q", help="Suppress output messages."
40-
),
38+
quiet: bool = typer.Option(True, "--quiet", "-q", help="Suppress output messages."),
4139
):
4240
if list_repos:
4341
Repo().list_repos()
@@ -104,7 +102,28 @@ def remote_remove(
104102

105103

106104
@repo.command()
107-
def branch(
105+
def cd(
106+
ctx: typer.Context,
107+
repo_name: str = typer.Argument(None),
108+
):
109+
"""
110+
Change directory to the specified repository.
111+
"""
112+
repo = Repo()
113+
repo.ctx = ctx
114+
115+
repo_command(
116+
False,
117+
repo_name,
118+
all_msg=None,
119+
missing_msg="Please specify a repository name.",
120+
single_func=repo.cd_repo,
121+
all_func=repo.cd_repo,
122+
)
123+
124+
125+
@repo.command()
126+
def checkout(
108127
ctx: typer.Context,
109128
repo_name: str = typer.Argument(None),
110129
branch_name: str = typer.Argument(None, help="Branch name"),
@@ -129,7 +148,14 @@ def branch(
129148
repo.ctx = ctx
130149
repo_list = repo.map
131150

132-
# Repo().checkout_branch(repo_name, branch_name)
151+
if (all_repos and not list_branches) or (all_repos and repo_name):
152+
typer.echo(
153+
typer.style(
154+
"Cannot use --all-repos with repo name or without --list-branches.",
155+
fg=typer.colors.RED,
156+
)
157+
)
158+
raise typer.Exit()
133159

134160
if delete_branch and branch_name:
135161
repo.delete_branch(repo_name, branch_name)
@@ -141,34 +167,13 @@ def branch(
141167
all_repos,
142168
repo_name,
143169
all_msg=None,
144-
missing_msg="Please specify a repository name or use -a,--all-repos to show branches of all repositories.",
170+
missing_msg="Please specify a repository name or use -a,--all-repos with -l,list-repos to show branches of all repositories.",
145171
single_func=lambda repo_name: repo.get_repo_branch(repo_name, branch_name),
146172
all_func=lambda repo_name: repo.get_repo_branch(repo_name, branch_name),
147173
repo_list=repo_list,
148174
)
149175

150176

151-
@repo.command()
152-
def cd(
153-
ctx: typer.Context,
154-
repo_name: str = typer.Argument(None),
155-
):
156-
"""
157-
Change directory to the specified repository.
158-
"""
159-
repo = Repo()
160-
repo.ctx = ctx
161-
162-
repo_command(
163-
False,
164-
repo_name,
165-
all_msg=None,
166-
missing_msg="Please specify a repository name.",
167-
single_func=repo.cd_repo,
168-
all_func=repo.cd_repo,
169-
)
170-
171-
172177
@repo.command()
173178
def clone(
174179
repo_name: str = typer.Argument(None),
@@ -230,7 +235,8 @@ def do_commit(name):
230235

231236

232237
@repo.command()
233-
def delete(
238+
def remove(
239+
ctx: typer.Context,
234240
repo_name: str = typer.Argument(None),
235241
all_repos: bool = typer.Option(
236242
False, "--all-repos", "-a", help="Delete all repositories"
@@ -244,11 +250,13 @@ def delete(
244250
If --all-repos is used, delete all repositories.
245251
If --uninstall is used, uninstall the package before deleting.
246252
"""
253+
repo = Repo()
254+
repo.ctx = ctx
247255

248256
def do_delete(name):
249257
if uninstall:
250258
Package().uninstall_package(name)
251-
Repo().delete_repo(name)
259+
repo.delete_repo(name)
252260

253261
repo_command(
254262
all_repos,

django_mongodb_cli/utils.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ def err(self, text: str) -> None:
5555
def title(self, text: str) -> None:
5656
typer.echo(text)
5757

58-
def run(self, args, cwd: Path | str | None = None, check: bool = True) -> bool:
58+
def run(
59+
self,
60+
args,
61+
cwd: Path | str | None = None,
62+
check: bool = True,
63+
env: str | None = None,
64+
) -> bool:
5965
try:
60-
subprocess.run(args, cwd=str(cwd) if cwd else None, check=check)
66+
subprocess.run(args, cwd=str(cwd) if cwd else None, check=check, env=env)
6167
return True
6268
except subprocess.CalledProcessError as e:
6369
self.err(f"Command failed: {' '.join(str(a) for a in args)} ({e})")
@@ -68,7 +74,7 @@ def ensure_repo(
6874
) -> tuple[Path | None, GitRepo | None]:
6975
path = self.get_repo_path(repo_name)
7076
if must_exist and not path.exists():
71-
if not self.ctx.obj.get("quiet", False):
77+
if not self.ctx.obj.get("quiet", True):
7278
self.err(f"Repository '{repo_name}' not found at path: {path}")
7379
return None, None
7480
repo = self.get_repo(str(path)) if path.exists() else None
@@ -221,6 +227,7 @@ def delete_repo(self, repo_name: str) -> None:
221227
self.info(f"Deleting repository: {repo_name}")
222228
path, _ = self.ensure_repo(repo_name)
223229
if not path:
230+
self.err(f"❌ Failed to delete {repo_name}: path not found.")
224231
return
225232
try:
226233
shutil.rmtree(path)
@@ -278,7 +285,7 @@ def get_repo_remote(self, repo_name: str) -> None:
278285
if not repo:
279286
return
280287

281-
quiet = self.ctx.obj.get("quiet", False)
288+
quiet = self.ctx.obj.get("quiet", True)
282289
self.info(f"Remotes for {repo_name}:")
283290
for remote in repo.remotes:
284291
try:
@@ -506,9 +513,13 @@ def open_repo(self, repo_name: str) -> None:
506513
self.ok(f"✅ Successfully opened {repo_name} in browser.")
507514

508515
def reset_repo(self, repo_name: str) -> None:
509-
self.info(f"Resetting repository: {repo_name}")
510516
_, repo = self.ensure_repo(repo_name)
517+
quiet = self.ctx.obj.get("quiet", True)
518+
if not quiet:
519+
self.info(f"Resetting repository: {repo_name}")
511520
if not repo:
521+
if not quiet:
522+
self.err(f"❌ Failed to reset {repo_name}: path not found.")
512523
return
513524
try:
514525
repo.git.reset("--hard")
@@ -570,7 +581,7 @@ def remote_add(self, remote_name: str, remote_url: str) -> None:
570581
try:
571582
repo.create_remote(remote_name, remote_url)
572583
self.ok(
573-
f"Successfully added remote '{remote_name}' with URL '{remote_url}'."
584+
f"Successfully added remote '{remote_name}' with URL '{remote_url}'."
574585
)
575586
except Exception:
576587
self.info(
@@ -579,7 +590,7 @@ def remote_add(self, remote_name: str, remote_url: str) -> None:
579590
repo.delete_remote(remote_name)
580591
repo.create_remote(remote_name, remote_url)
581592
self.ok(
582-
f"Successfully added remote '{remote_name}' with URL '{remote_url}'."
593+
f"Successfully added remote '{remote_name}' with URL '{remote_url}'."
583594
)
584595

585596
def remote_remove(self, remote_name: str) -> None:
@@ -634,7 +645,16 @@ def install_package(self, repo_name: str) -> None:
634645
path = Path(path / install_dir).resolve()
635646
self.info(f"Using custom install directory: {path}")
636647

637-
if self.run(["uv", "pip", "install", "-e", str(path)]):
648+
env = os.environ.copy()
649+
env_vars_list = (
650+
self.tool_cfg.get("install", {}).get(repo_name, {}).get("env_vars")
651+
)
652+
if env_vars_list:
653+
typer.echo("Setting environment variables for installation:")
654+
typer.echo(env_vars_list)
655+
env.update({item["name"]: str(item["value"]) for item in env_vars_list})
656+
657+
if self.run(["uv", "pip", "install", "-e", str(path)], env=env):
638658
self.ok(f"Installed {repo_name}")
639659

640660
def uninstall_package(self, repo_name: str) -> None:
@@ -751,7 +771,7 @@ def _list_tests(self, repo_name: str) -> None:
751771
test_files = [
752772
f for f in files if f.endswith(".py") and not f.startswith("__")
753773
]
754-
quiet = self.ctx.obj.get("quiet", False)
774+
quiet = self.ctx.obj.get("quiet", True)
755775

756776
if not quiet or test_files:
757777
self.ok(f"\n📂 {display_path}")
@@ -826,9 +846,9 @@ def run_tests(self, repo_name: str) -> None:
826846
self._list_tests(repo_name)
827847
return
828848

829-
self.info(f"Running tests for repository: {repo_name}")
830849
path, _ = self.ensure_repo(repo_name)
831850
if not path:
851+
self.err(f"❌ Failed to run tests for {repo_name}: path not found.")
832852
return
833853

834854
self._run_tests(repo_name)
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
.. _test_suites:
2-
1+
===========
32
Test suites
4-
-----------
3+
===========
4+
5+
For each third-party library that is supported, the following tasks are performed:
6+
7+
#. **Configure the test suite to run with Django MongoDB Backend**
58

6-
For each third party library that is supported, the following tasks are performed:
9+
a. Evaluate test runner configuration
710

8-
#. **The test suite is configured to run with Django MongoDB Backend.**
11+
i. Depending on the test runner, updating the settings may require
12+
copying ``mongo_apps.py`` and ``mongo_migrations`` to a module
13+
that is already included in ``sys.path``.
914

10-
a. Evaluate test runner configuration
15+
b. Update Django settings
1116

12-
i. Depending on the test runner, updating the settings may require
13-
copying ``mongo_apps.py`` and ``mongo_migrations`` to a module that is
14-
already included in ``sys.path``.
17+
i. Replace the database backend with ``django_mongodb_backend``
18+
#. Replace contrib apps with MongoDB-compatible apps
19+
#. Replace test suite apps with MongoDB-compatible apps
1520

16-
b. Update django settings
21+
c. Update or disable migrations
1722

18-
i. Replace the database backend with ``django_mongodb_backend``
19-
#. Replace contrib apps with MongoDB compatible apps
20-
#. Replace test suite apps with MongoDB compatible apps
23+
i. Use MongoDB-compatible migrations if not disabled
2124

22-
c. Update or disable migrations
25+
#. **Run the test suite with Django MongoDB Backend configured**
2326

24-
i. Use MongoDB compatible migrations if not disabled
27+
#. **Log the test run results**
2528

26-
2. **The test suite is run with Django MongoDB Backend configured.**
27-
#. **The test run results are logged.**
28-
#. **The test suite tests are updated as needed.**
29+
#. **Update test suite tests as needed**
2930

30-
a. Replace static primary key references with dynamic references or static ``ObjectId`` references
31+
a. Replace static primary key references with dynamic references
32+
or static ``ObjectId`` references

jira/qe.py renamed to jira/INTPYTHON-527.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
from pymongo import MongoClient
33
from pymongo.encryption import ClientEncryption, AutoEncryptionOpts
44
from pymongo.errors import EncryptedCollectionError
5+
import os
56

6-
from django_mongodb_backend.encryption import KMS_PROVIDERS
7-
8-
KEY_VAULT_NAMESPACE = "encryption.__keyVault"
97

108
client = MongoClient(
119
auto_encryption_opts=AutoEncryptionOpts(
12-
key_vault_namespace=KEY_VAULT_NAMESPACE,
13-
kms_providers=KMS_PROVIDERS,
10+
key_vault_namespace="encryption.__keyVault",
11+
kms_providers={"local": {"key": os.urandom(96)}},
1412
)
1513
)
1614

1715
codec_options = CodecOptions()
1816
client_encryption = ClientEncryption(
19-
KMS_PROVIDERS, KEY_VAULT_NAMESPACE, client, codec_options
17+
client.options.auto_encryption_opts._kms_providers,
18+
client.options.auto_encryption_opts._key_vault_namespace,
19+
client,
20+
codec_options,
2021
)
2122

2223
COLLECTION_NAME = "patient"

0 commit comments

Comments
 (0)