Skip to content

Commit b52012e

Browse files
authored
Merge pull request #31 from aclark4life/main
Misc updates
2 parents 6d20e7b + 9f41347 commit b52012e

File tree

6 files changed

+125
-121
lines changed

6 files changed

+125
-121
lines changed

config/django/django_settings.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import os
2-
import django_mongodb_backend
32

4-
kms_providers = django_mongodb_backend.get_kms_providers()
3+
from django_mongodb_backend import encryption, parse_uri
4+
5+
kms_providers = encryption.get_kms_providers()
56

67
HOME = os.environ.get("HOME")
78

8-
auto_encryption_opts = django_mongodb_backend.get_auto_encryption_opts(
9+
auto_encryption_opts = encryption.get_auto_encryption_opts(
910
kms_providers=kms_providers,
1011
crypt_shared_lib_path=f"{HOME}/Downloads/mongo_crypt_shared_v1-macos-arm64-enterprise-8.0.10/lib/mongo_crypt_v1.dylib",
1112
)
1213

1314
DATABASE_URL = os.environ.get("MONGODB_URI", "mongodb://localhost:27017/djangotests")
1415
DATABASES = {
15-
"default": django_mongodb_backend.parse_uri(DATABASE_URL),
16-
"encryption": django_mongodb_backend.parse_uri(
16+
"default": parse_uri(
1717
DATABASE_URL, options={"auto_encryption_opts": auto_encryption_opts}
1818
),
1919
}

django_mongodb_cli/repo.py

Lines changed: 79 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
repo_clone,
1313
repo_install,
1414
repo_status,
15-
repo_update,
1615
)
1716

1817

@@ -68,7 +67,7 @@ def repo(ctx, list_repos):
6867
@click.pass_context
6968
@pass_repo
7069
def clone(repo, ctx, repo_names, all_repos, install):
71-
"""Clone repositories from `pyproject.toml`."""
70+
"""Clone and install repositories from `pyproject.toml`."""
7271
repos, url_pattern, branch_pattern = get_repos("pyproject.toml")
7372

7473
if repo_names:
@@ -100,75 +99,39 @@ def clone(repo, ctx, repo_names, all_repos, install):
10099
click.echo(ctx.get_help())
101100

102101

103-
@repo.command()
104-
@click.option(
105-
"-a",
106-
"--all-repos",
107-
is_flag=True,
108-
)
109-
@click.argument("repo_names", nargs=-1)
110-
@click.pass_context
111-
@pass_repo
112-
def install(repo, ctx, repo_names, all_repos):
113-
"""Install cloned repositories with `pip install -e`."""
114-
115-
if repo_names:
116-
for repo_name in repo_names:
117-
clone_path = os.path.join(ctx.obj.home, repo_name)
118-
if os.path.exists(clone_path):
119-
repo_install(clone_path)
120-
else:
121-
click.echo(f"Repository '{repo_name}' not found.")
122-
return
123-
124-
if all_repos:
125-
repos, url_pattern, branch_pattern = get_repos("pyproject.toml")
126-
for repo_entry in repos:
127-
url_match = url_pattern.search(repo_entry)
128-
if url_match:
129-
repo_url = url_match.group(0)
130-
repo_name = os.path.basename(repo_url)
131-
clone_path = os.path.join(ctx.obj.home, repo_name)
132-
if os.path.exists(clone_path):
133-
repo_install(clone_path)
134-
return
135-
136-
if ctx.args == []:
137-
click.echo(ctx.get_help())
138-
139-
140-
@repo.command()
141-
@click.argument("repo_names", nargs=-1)
142-
@click.option(
143-
"-a",
144-
"--all-repos",
145-
is_flag=True,
146-
)
147-
@click.pass_context
148-
@pass_repo
149-
def update(repo, ctx, repo_names, all_repos):
150-
"""Update cloned repositories with `git pull`."""
151-
repos, url_pattern, _ = get_repos("pyproject.toml")
152-
if repo_names:
153-
for repo_name in repo_names:
154-
for repo_entry in repos:
155-
if (
156-
os.path.basename(url_pattern.search(repo_entry).group(0))
157-
== repo_name
158-
):
159-
repo_update(repo_entry, url_pattern, repo)
160-
return
161-
click.echo(f"Repository '{repo_name}' not found.")
162-
return
163-
164-
if all_repos:
165-
click.echo(f"Updating {len(repos)} repositories...")
166-
for repo_entry in repos:
167-
repo_update(repo_entry, url_pattern, repo)
168-
return
169-
170-
if ctx.args == []:
171-
click.echo(ctx.get_help())
102+
# @repo.command()
103+
# @click.argument("repo_names", nargs=-1)
104+
# @click.option(
105+
# "-a",
106+
# "--all-repos",
107+
# is_flag=True,
108+
# )
109+
# @click.pass_context
110+
# @pass_repo
111+
# def update(repo, ctx, repo_names, all_repos):
112+
# """Update cloned repositories with `git pull`."""
113+
# repos, url_pattern, _ = get_repos("pyproject.toml")
114+
# if repo_names:
115+
# for repo_name in repo_names:
116+
# for repo_entry in repos:
117+
# if (
118+
# os.path.basename(url_pattern.search(repo_entry).group(0))
119+
# == repo_name
120+
# ):
121+
# repo_update(repo_entry, url_pattern, repo)
122+
# return
123+
# click.echo(f"Repository '{repo_name}' not found.")
124+
# return
125+
#
126+
# if all_repos:
127+
# click.echo(f"Updating {len(repos)} repositories...")
128+
# for repo_entry in repos:
129+
# repo_update(repo_entry, url_pattern, repo)
130+
# return
131+
#
132+
# if ctx.args == []:
133+
# click.echo(ctx.get_help())
134+
#
172135

173136

174137
@repo.command(context_settings={"ignore_unknown_options": True})
@@ -240,16 +203,14 @@ def makemigrations(
240203
@click.argument("modules", nargs=-1)
241204
@click.option("-k", "--keyword", help="Filter tests by keyword")
242205
@click.option("-l", "--list-tests", help="List tests", is_flag=True)
243-
@click.option("-s", "--setup", help="Setup tests (pymongo only)", is_flag=True)
244-
@click.option("--show", help="Show settings", is_flag=True)
206+
@click.option("-s", "--show", help="Show settings", is_flag=True)
245207
@click.pass_context
246208
def test(
247209
ctx,
248210
repo_name,
249211
modules,
250212
keyword,
251213
list_tests,
252-
setup,
253214
show,
254215
):
255216
"""
@@ -259,6 +220,7 @@ def test(
259220
if repo_name:
260221
# Show test settings
261222
if show:
223+
click.echo(f"⚙️ Test settings for 📦 {repo_name}:")
262224
if repo_name in test_settings_map.keys():
263225
from rich import print
264226
from black import format_str as format
@@ -286,7 +248,7 @@ def test(
286248
test_dirs = test_settings_map[repo_name]["test_dirs"]
287249
if list_tests:
288250
for test_dir in test_dirs:
289-
click.echo(click.style(f"{test_dir}", fg="blue"))
251+
click.echo(f"📂 {test_dir}")
290252
try:
291253
modules = sorted(os.listdir(test_dir))
292254
count = 0
@@ -297,9 +259,17 @@ def test(
297259
and module != "__init__.py"
298260
):
299261
if count == len(modules):
300-
click.echo(f" └── {module}")
262+
click.echo(
263+
click.style(
264+
f" └── {module}", fg="green"
265+
)
266+
)
301267
else:
302-
click.echo(f" ├── {module}")
268+
click.echo(
269+
click.style(
270+
f" └── {module}", fg="green"
271+
)
272+
)
303273
click.echo()
304274
except FileNotFoundError:
305275
click.echo(
@@ -347,6 +317,7 @@ def test(
347317
"3",
348318
"--debug-sql",
349319
"--noinput",
320+
"--keepdb",
350321
]
351322
)
352323
if keyword:
@@ -407,9 +378,19 @@ def test(
407378
"--diff",
408379
is_flag=True,
409380
)
381+
@click.option(
382+
"-b",
383+
"--branch",
384+
is_flag=True,
385+
)
386+
@click.option(
387+
"-u",
388+
"--update",
389+
is_flag=True,
390+
)
410391
@click.pass_context
411392
@pass_repo
412-
def status(repo, ctx, repo_names, all_repos, reset, diff):
393+
def status(repo, ctx, repo_names, all_repos, reset, diff, branch, update):
413394
"""Repository status."""
414395
repos, url_pattern, _ = get_repos("pyproject.toml")
415396
if repo_names:
@@ -420,17 +401,34 @@ def status(repo, ctx, repo_names, all_repos, reset, diff):
420401
os.path.basename(url_pattern.search(repo_entry).group(0))
421402
== repo_name
422403
):
423-
repo_status(repo_entry, url_pattern, repo, reset=reset, diff=diff)
404+
repo_status(
405+
repo_entry,
406+
url_pattern,
407+
repo,
408+
reset=reset,
409+
diff=diff,
410+
branch=branch,
411+
update=update,
412+
)
424413
return
425414
else:
426415
not_found.add(repo_name)
427-
click.echo(f"Repository '{not_found.pop()}' not found.")
416+
if not_found:
417+
click.echo(f"Repository '{not_found.pop()}' not found.")
428418
return
429419

430420
if all_repos:
431421
click.echo(f"Status of {len(repos)} repositories...")
432422
for repo_entry in repos:
433-
repo_status(repo_entry, url_pattern, repo, reset=reset, diff=diff)
423+
repo_status(
424+
repo_entry,
425+
url_pattern,
426+
repo,
427+
reset=reset,
428+
diff=diff,
429+
branch=branch,
430+
update=update,
431+
)
434432
return
435433

436434
if ctx.args == []:

django_mongodb_cli/utils.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def repo_clone(repo_entry, url_pattern, branch_pattern, repo):
106106
clone_path = os.path.join(repo.home, repo_name)
107107

108108
if os.path.exists(clone_path):
109-
click.echo(f"Skipping: {repo_name} already exists.")
109+
click.echo(f"Skipping {repo_name}: already exists at {clone_path}")
110110
else:
111111
click.echo(
112112
f"Cloning {repo_name} from {repo_url} into {clone_path} (branch: {branch})"
@@ -122,7 +122,7 @@ def repo_clone(repo_entry, url_pattern, branch_pattern, repo):
122122
click.echo(f"Failed to clone repository: {e}")
123123
subprocess.run(["pre-commit", "install"], cwd=clone_path)
124124
else:
125-
click.echo(f"Skipping {repo_url} in {clone_path} (branch: {branch})")
125+
click.echo(f"Skipping {repo_url}: already exists at {clone_path}")
126126

127127

128128
def repo_install(clone_path):
@@ -149,30 +149,31 @@ def repo_install(clone_path):
149149
)
150150

151151

152-
def repo_update(repo_entry, url_pattern, repo):
152+
def repo_update(repo_entry, url_pattern, clone_path):
153153
"""Helper function to update a single repository."""
154154
url_match = url_pattern.search(repo_entry)
155155
if not url_match:
156156
return
157157

158158
repo_url = url_match.group(0)
159159
repo_name = os.path.basename(repo_url)
160-
clone_path = os.path.join(repo.home, repo_name)
161160

162161
if os.path.exists(clone_path):
163-
click.echo(f"Updating {repo_name}...")
164162
try:
163+
click.echo(f"Updating 📦 {repo_name}")
165164
repo = git.Repo(clone_path)
166-
click.echo(click.style(repo.git.pull(), fg="blue"))
165+
click.echo(repo.git.pull())
167166
except git.exc.NoSuchPathError:
168-
click.echo("Not a valid Git repository.")
167+
click.echo(click.style("Not a valid Git repository.", fg="red"))
169168
except git.exc.GitCommandError:
170169
click.echo(click.style(f"Failed to update {repo_name}", fg="red"))
171170
else:
172-
click.echo(f"Skipping {repo_name}: Repository not found at {clone_path}")
171+
click.echo(click.style(f"Skipping {repo_name}", fg="blue"))
173172

174173

175-
def repo_status(repo_entry, url_pattern, repo, reset=False, diff=False):
174+
def repo_status(
175+
repo_entry, url_pattern, repo, reset=False, diff=False, branch=False, update=False
176+
):
176177
"""Helper function to update a single repository."""
177178
url_match = url_pattern.search(repo_entry)
178179
if not url_match:
@@ -185,14 +186,17 @@ def repo_status(repo_entry, url_pattern, repo, reset=False, diff=False):
185186
if os.path.exists(clone_path):
186187
try:
187188
repo = git.Repo(clone_path)
188-
click.echo(f"=== {repo_name} ===")
189+
click.echo(f"📦 {repo_name}")
189190
if reset:
190-
click.echo(click.style(repo.git.reset("--hard"), fg="blue"))
191+
click.echo(click.style(f"Resetting {repo_name}", fg="red"))
192+
click.echo(repo.git.reset("--hard"))
191193
else:
192-
click.echo("Remote URLs:")
193194
click.echo(
194195
"".join(
195-
[f"- {remote.name}:{remote.url}" for remote in repo.remotes]
196+
[
197+
f"On remote {remote.name} at {remote.url}"
198+
for remote in repo.remotes
199+
]
196200
),
197201
)
198202
click.echo(repo.git.status())
@@ -202,12 +206,17 @@ def repo_status(repo_entry, url_pattern, repo, reset=False, diff=False):
202206
click.echo(click.style(diff_output, fg="red"))
203207
else:
204208
click.echo(click.style("No diff output", fg="yellow"))
209+
if branch:
210+
click.echo(repo.git.branch("--all"))
211+
if update:
212+
repo_update(repo_entry, url_pattern, clone_path)
213+
click.echo()
205214
except git.exc.NoSuchPathError:
206215
click.echo("Not a valid Git repository.")
207216
else:
208217
click.echo(
209218
click.style(
210-
f"Skipping {repo_name}: Repository not found at {clone_path}",
211-
fg="yellow",
219+
f"Skipping 📦 {repo_name}",
220+
fg="blue",
212221
)
213222
)

0 commit comments

Comments
 (0)