-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into refactor-schema-synchronization
- Loading branch information
Showing
8 changed files
with
215 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
|
||
def find_vscode_stubs_folder() -> Path | None: | ||
# Possible locations of VSCode extensions | ||
possible_locations = [ | ||
Path.home() / ".vscode" / "extensions", # Linux and macOS | ||
Path.home() / ".vscode-server" / "extensions", # Remote development | ||
Path(os.environ.get("APPDATA", "")) / "Code" / "User" / "extensions", # Windows | ||
Path("/usr/share/code/resources/app/extensions"), # Some Linux distributions | ||
] | ||
for location in possible_locations: | ||
if location.exists(): | ||
# Look for Pylance extension folder | ||
pylance_folders = list(location.glob("ms-python.vscode-pylance-*")) | ||
if pylance_folders: | ||
# Sort to get the latest version | ||
latest_pylance = sorted(pylance_folders)[-1] | ||
stubs_folder = ( | ||
latest_pylance / "dist" / "bundled" / "stubs" / "django-stubs" | ||
) | ||
if stubs_folder.exists(): | ||
return stubs_folder | ||
|
||
return None | ||
|
||
|
||
def private_django_api(reverse=False): | ||
from django import db | ||
|
||
attributes = [ | ||
"DoesNotExist", | ||
"MultipleObjectsReturned", | ||
"add_to_class", | ||
"adelete", | ||
"refresh_from_db", | ||
"asave", | ||
"clean", | ||
"clean_fields", | ||
"date_error_message", | ||
"full_clean", | ||
"get_constraints", | ||
"get_deferred_fields", | ||
"prepare_database_save", | ||
"save_base", | ||
"serializable_value", | ||
"unique_error_message", | ||
"validate_constraints", | ||
"validate_unique", | ||
] | ||
if not reverse: | ||
attributes.append("a_refresh_from_db") | ||
else: | ||
attributes.append("arefresh_from_db") | ||
|
||
django_path = Path(db.__file__).parent.parent | ||
|
||
encoding = "utf8" if os.name == "nt" else None | ||
|
||
def prune_file(file_path): | ||
content = file_path.read_text(encoding=encoding) | ||
original_content = content | ||
|
||
for attr in attributes: | ||
old_name = f"_{attr}" if reverse else attr | ||
new_name = attr if reverse else f"_{attr}" | ||
content = content.replace(old_name, new_name) | ||
|
||
if not reverse: | ||
content = content.replace("Field_DoesNotExist", "FieldDoesNotExist") | ||
content = content.replace("Object_DoesNotExist", "ObjectDoesNotExist") | ||
|
||
if content != original_content: | ||
file_path.write_text(content, encoding=encoding) | ||
|
||
for file_path in django_path.rglob("*.py"): | ||
prune_file(file_path) | ||
|
||
pylance_path = find_vscode_stubs_folder() | ||
if pylance_path is not None: | ||
for file_path in pylance_path.rglob("*.pyi"): | ||
prune_file(file_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from __future__ import annotations | ||
|
||
import subprocess | ||
from pathlib import Path | ||
|
||
import lamindb_setup as ln_setup | ||
from lamindb_setup.core.hashing import hash_dir | ||
|
||
|
||
def test_auto_connect(): | ||
current_state = ln_setup.settings.auto_connect | ||
ln_setup.settings.auto_connect = True | ||
assert ln_setup.settings._auto_connect_path.exists() | ||
ln_setup.settings.auto_connect = False | ||
assert not ln_setup.settings._auto_connect_path.exists() | ||
ln_setup.settings.auto_connect = current_state | ||
|
||
|
||
def test_private_django_api(): | ||
from django import db | ||
|
||
django_dir = Path(db.__file__).parent.parent | ||
|
||
# below, we're checking whether a repo is clean via the internal hashing | ||
# function | ||
# def is_repo_clean() -> bool: | ||
# from django import db | ||
|
||
# django_dir = Path(db.__file__).parent.parent | ||
# print(django_dir) | ||
# result = subprocess.run( | ||
# ["git", "diff"], | ||
# capture_output=True, | ||
# text=True, | ||
# cwd=django_dir, | ||
# ) | ||
# print(result.stdout) | ||
# print(result.stderr) | ||
# return result.stdout.strip() == "" and result.stderr.strip() == "" | ||
|
||
_, orig_hash, _, _ = hash_dir(django_dir) | ||
current_state = ln_setup.settings.private_django_api | ||
ln_setup.settings.private_django_api = True | ||
# do not run below on CI, but only locally | ||
# installing django via git didn't succeed | ||
# assert not is_repo_clean() | ||
_, hash, _, _ = hash_dir(django_dir) | ||
assert hash != orig_hash | ||
assert ln_setup.settings._private_django_api_path.exists() | ||
ln_setup.settings.private_django_api = False | ||
# assert is_repo_clean() | ||
_, hash, _, _ = hash_dir(django_dir) | ||
assert hash == orig_hash | ||
assert not ln_setup.settings._private_django_api_path.exists() | ||
ln_setup.settings.private_django_api = current_state |