Skip to content

Commit ad07bde

Browse files
Merge master into pre/v2.1
2 parents 9c8b196 + a8a1814 commit ad07bde

File tree

7 files changed

+36
-136
lines changed

7 files changed

+36
-136
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ DataJoint is a framework for scientific data pipelines based on the **Relational
1010
**Documentation:** https://docs.datajoint.com
1111

1212
> **📘 Upgrading from legacy DataJoint (pre-2.0)?**
13-
> See the **[Migration Guide](https://docs.datajoint.com/how-to/migrate-from-0x/)** for a step-by-step upgrade path.
13+
> See the **[Migration Guide](https://docs.datajoint.com/how-to/migrate-to-v20/)** for a step-by-step upgrade path.
1414
1515
<table>
1616
<tr>
@@ -78,8 +78,8 @@ conda install -c conda-forge datajoint
7878
- **[Documentation](https://docs.datajoint.com)** — Complete guides and reference
7979
- [Tutorials](https://docs.datajoint.com/tutorials/) — Learn by example
8080
- [How-To Guides](https://docs.datajoint.com/how-to/) — Task-oriented guides
81-
- [API Reference](https://docs.datajoint.com/reference/api/) — Complete API documentation
82-
- [Migration Guide](https://docs.datajoint.com/how-to/migrate-from-0x/) — Upgrade from legacy versions
81+
- [API Reference](https://docs.datajoint.com/api/) — Complete API documentation
82+
- [Migration Guide](https://docs.datajoint.com/how-to/migrate-to-v20/) — Upgrade from legacy versions
8383
- **[DataJoint Elements](https://datajoint.com/docs/elements/)** — Example pipelines for neuroscience
8484
- **[GitHub Discussions](https://github.com/datajoint/datajoint-python/discussions)** — Community support
8585

src/datajoint/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"Top",
4040
"U",
4141
"Diagram",
42-
"kill",
4342
"MatCell",
4443
"MatStruct",
4544
# Codec API
@@ -94,8 +93,6 @@
9493
# Diagram imports networkx and matplotlib
9594
"Diagram": (".diagram", "Diagram"),
9695
"diagram": (".diagram", None), # Return the module itself
97-
# kill imports pymysql via connection
98-
"kill": (".admin", "kill"),
9996
# cli imports click
10097
"cli": (".cli", "cli"),
10198
}

src/datajoint/admin.py

Lines changed: 0 additions & 101 deletions
This file was deleted.

src/datajoint/connection.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import re
1212
import warnings
1313
from contextlib import contextmanager
14-
from getpass import getpass
1514
from typing import Callable
1615

1716
from . import errors
@@ -71,9 +70,9 @@ def conn(
7170
host : str, optional
7271
Database hostname.
7372
user : str, optional
74-
MySQL username.
73+
Database username. Required if not set in config.
7574
password : str, optional
76-
MySQL password. Prompts if not provided.
75+
Database password. Required if not set in config.
7776
init_fun : callable, optional
7877
Initialization function called after connection.
7978
reset : bool, optional
@@ -86,15 +85,24 @@ def conn(
8685
-------
8786
Connection
8887
Persistent database connection.
88+
89+
Raises
90+
------
91+
DataJointError
92+
If user or password is not provided and not set in config.
8993
"""
9094
if not hasattr(conn, "connection") or reset:
9195
host = host if host is not None else config["database.host"]
9296
user = user if user is not None else config["database.user"]
9397
password = password if password is not None else config["database.password"]
9498
if user is None:
95-
user = input("Please enter DataJoint username: ")
99+
raise errors.DataJointError(
100+
"Database user not configured. Set datajoint.config['database.user'] or pass user= argument."
101+
)
96102
if password is None:
97-
password = getpass(prompt="Please enter DataJoint password: ")
103+
raise errors.DataJointError(
104+
"Database password not configured. Set datajoint.config['database.password'] or pass password= argument."
105+
)
98106
init_fun = init_fun if init_fun is not None else config["connection.init_function"]
99107
use_tls = use_tls if use_tls is not None else config["database.use_tls"]
100108
conn.connection = Connection(host, user, password, None, init_fun, use_tls)

src/datajoint/schemas.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class Schema:
7272
create_schema : bool, optional
7373
If False, raise error if schema doesn't exist. Default True.
7474
create_tables : bool, optional
75-
If False, raise error when accessing missing tables. Default True.
75+
If False, raise error when accessing missing tables.
76+
Default from ``dj.config.database.create_tables`` (True unless configured).
7677
add_objects : dict, optional
7778
Additional objects for the declaration context.
7879
@@ -93,7 +94,7 @@ def __init__(
9394
*,
9495
connection: Connection | None = None,
9596
create_schema: bool = True,
96-
create_tables: bool = True,
97+
create_tables: bool | None = None,
9798
add_objects: dict[str, Any] | None = None,
9899
) -> None:
99100
"""
@@ -110,15 +111,16 @@ def __init__(
110111
create_schema : bool, optional
111112
If False, raise error if schema doesn't exist. Default True.
112113
create_tables : bool, optional
113-
If False, raise error when accessing missing tables. Default True.
114+
If False, raise error when accessing missing tables.
115+
Default from ``dj.config.database.create_tables`` (True unless configured).
114116
add_objects : dict, optional
115117
Additional objects for the declaration context.
116118
"""
117119
self.connection = connection
118120
self.database = None
119121
self.context = context
120122
self.create_schema = create_schema
121-
self.create_tables = create_tables
123+
self.create_tables = create_tables if create_tables is not None else config.database.create_tables
122124
self.add_objects = add_objects
123125
self.declare_list = []
124126
if schema_name:

src/datajoint/settings.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
"database.password": "DJ_PASS",
6666
"database.backend": "DJ_BACKEND",
6767
"database.port": "DJ_PORT",
68+
"database.schema_prefix": "DJ_SCHEMA_PREFIX",
69+
"database.create_tables": "DJ_CREATE_TABLES",
6870
"loglevel": "DJ_LOG_LEVEL",
6971
"display.diagram_direction": "DJ_DIAGRAM_DIRECTION",
7072
}
@@ -196,6 +198,18 @@ class DatabaseSettings(BaseSettings):
196198
port: int | None = Field(default=None, validation_alias="DJ_PORT")
197199
reconnect: bool = True
198200
use_tls: bool | None = Field(default=None, validation_alias="DJ_USE_TLS")
201+
schema_prefix: str = Field(
202+
default="",
203+
validation_alias="DJ_SCHEMA_PREFIX",
204+
description="Project-specific prefix for schema names. "
205+
"Not automatically applied; use dj.config.database.schema_prefix when creating schemas.",
206+
)
207+
create_tables: bool = Field(
208+
default=True,
209+
validation_alias="DJ_CREATE_TABLES",
210+
description="Default for Schema create_tables parameter. "
211+
"Set to False for production mode to prevent automatic table creation.",
212+
)
199213

200214
@model_validator(mode="after")
201215
def set_default_port_from_backend(self) -> "DatabaseSettings":

tests/unit/test_lazy_imports.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,6 @@ def test_lazy_diagram_import():
2727
assert Diagram.__name__ == "Diagram"
2828

2929

30-
def test_lazy_admin_import():
31-
"""Admin module should not be loaded until dj.kill is accessed."""
32-
# Remove datajoint from sys.modules to get fresh import
33-
modules_to_remove = [key for key in sys.modules if key.startswith("datajoint")]
34-
for mod in modules_to_remove:
35-
del sys.modules[mod]
36-
37-
# Import datajoint
38-
import datajoint as dj
39-
40-
# Admin module should not be loaded yet
41-
assert "datajoint.admin" not in sys.modules, "admin module loaded eagerly"
42-
43-
# Access kill - should trigger lazy load
44-
kill = dj.kill
45-
assert "datajoint.admin" in sys.modules, "admin module not loaded after access"
46-
assert callable(kill)
47-
48-
4930
def test_lazy_cli_import():
5031
"""CLI module should not be loaded until dj.cli is accessed."""
5132
# Remove datajoint from sys.modules to get fresh import
@@ -103,5 +84,4 @@ def test_core_imports_available():
10384

10485
# Heavy modules should still not be loaded
10586
assert "datajoint.diagram" not in sys.modules
106-
assert "datajoint.admin" not in sys.modules
10787
assert "datajoint.cli" not in sys.modules

0 commit comments

Comments
 (0)