djmux 1.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- djmux-1.0.1/.gitignore +71 -0
- djmux-1.0.1/CITATION.cff +34 -0
- djmux-1.0.1/LICENSE +31 -0
- djmux-1.0.1/PKG-INFO +150 -0
- djmux-1.0.1/README.md +97 -0
- djmux-1.0.1/VERSION +1 -0
- djmux-1.0.1/pyproject.toml +130 -0
- djmux-1.0.1/src/djmux/__init__.py +39 -0
- djmux-1.0.1/src/djmux/_version.py +24 -0
- djmux-1.0.1/src/djmux/activation.py +71 -0
- djmux-1.0.1/src/djmux/config.py +65 -0
- djmux-1.0.1/src/djmux/prefixes.py +38 -0
- djmux-1.0.1/src/djmux/py.typed +0 -0
- djmux-1.0.1/tests/conftest.py +1 -0
- djmux-1.0.1/tests/integration/test_integration_placeholder.py +6 -0
- djmux-1.0.1/tests/unit/test_unit_placeholder.py +8 -0
djmux-1.0.1/.gitignore
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.pyo
|
|
5
|
+
*.pyd
|
|
6
|
+
*.so
|
|
7
|
+
*.egg
|
|
8
|
+
*.egg-info/
|
|
9
|
+
dist/
|
|
10
|
+
build/
|
|
11
|
+
eggs/
|
|
12
|
+
parts/
|
|
13
|
+
var/
|
|
14
|
+
sdist/
|
|
15
|
+
develop-eggs/
|
|
16
|
+
.installed.cfg
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
wheels/
|
|
20
|
+
|
|
21
|
+
# Virtual environments
|
|
22
|
+
.venv/
|
|
23
|
+
venv/
|
|
24
|
+
env/
|
|
25
|
+
ENV/
|
|
26
|
+
.python-version
|
|
27
|
+
|
|
28
|
+
# uv
|
|
29
|
+
uv.lock
|
|
30
|
+
|
|
31
|
+
# Distribution / packaging
|
|
32
|
+
MANIFEST
|
|
33
|
+
|
|
34
|
+
# Testing
|
|
35
|
+
.pytest_cache/
|
|
36
|
+
.coverage
|
|
37
|
+
.coverage.*
|
|
38
|
+
coverage.xml
|
|
39
|
+
htmlcov/
|
|
40
|
+
*.cover
|
|
41
|
+
.hypothesis/
|
|
42
|
+
|
|
43
|
+
# Type checking
|
|
44
|
+
.mypy_cache/
|
|
45
|
+
.dmypy.json
|
|
46
|
+
dmypy.json
|
|
47
|
+
.pytype/
|
|
48
|
+
.pyre/
|
|
49
|
+
|
|
50
|
+
# Build artifacts (hatch-vcs generated)
|
|
51
|
+
src/*/_version.py
|
|
52
|
+
|
|
53
|
+
# Jupyter
|
|
54
|
+
.ipynb_checkpoints
|
|
55
|
+
*.ipynb
|
|
56
|
+
|
|
57
|
+
# IDEs
|
|
58
|
+
.idea/
|
|
59
|
+
.vscode/
|
|
60
|
+
*.swp
|
|
61
|
+
*.swo
|
|
62
|
+
*~
|
|
63
|
+
|
|
64
|
+
# OS
|
|
65
|
+
.DS_Store
|
|
66
|
+
Thumbs.db
|
|
67
|
+
|
|
68
|
+
# Secrets / local config
|
|
69
|
+
.env
|
|
70
|
+
.env.*
|
|
71
|
+
!.env.example
|
djmux-1.0.1/CITATION.cff
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use this software, please cite it as below."
|
|
3
|
+
type: software
|
|
4
|
+
title: "djmux"
|
|
5
|
+
version: "1.0.1"
|
|
6
|
+
repository-code: https://github.com/larsrollik/djmux
|
|
7
|
+
url: https://github.com/larsrollik/djmux
|
|
8
|
+
license: GPL-3.0
|
|
9
|
+
authors:
|
|
10
|
+
- family-names: Rollik
|
|
11
|
+
given-names: Lars
|
|
12
|
+
orcid: https://orcid.org/0000-0000-0000-0000 # replace with your ORCID
|
|
13
|
+
|
|
14
|
+
# Zenodo integration (optional):
|
|
15
|
+
# 1. Enable the Zenodo webhook at zenodo.org/account/settings/github
|
|
16
|
+
# 2. After first tag release, copy the concept DOI from Zenodo and add:
|
|
17
|
+
#
|
|
18
|
+
# identifiers:
|
|
19
|
+
# - type: doi
|
|
20
|
+
# value: 10.5281/zenodo.XXXXXXX
|
|
21
|
+
# description: Zenodo concept DOI
|
|
22
|
+
#
|
|
23
|
+
# preferred-citation:
|
|
24
|
+
# type: software
|
|
25
|
+
# title: "djmux"
|
|
26
|
+
# authors:
|
|
27
|
+
# - family-names: ...
|
|
28
|
+
# given-names: ...
|
|
29
|
+
# orcid: https://orcid.org/...
|
|
30
|
+
# year: 2026
|
|
31
|
+
# publisher:
|
|
32
|
+
# name: Zenodo
|
|
33
|
+
# doi: 10.5281/zenodo.XXXXXXX
|
|
34
|
+
# url: https://doi.org/10.5281/zenodo.XXXXXXX
|
djmux-1.0.1/LICENSE
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
|
|
2
|
+
BSD 3-Clause License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026-present, Lars B. Rollik
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer.
|
|
12
|
+
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
18
|
+
may be used to endorse or promote products derived from this software
|
|
19
|
+
without specific prior written permission.
|
|
20
|
+
|
|
21
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
24
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
25
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
26
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
27
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
28
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
29
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
30
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
31
|
+
POSSIBILITY OF SUCH DAMAGE.
|
djmux-1.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: djmux
|
|
3
|
+
Version: 1.0.1
|
|
4
|
+
Summary: Shared DataJoint connection and multi-prefix schema activation
|
|
5
|
+
Project-URL: Homepage, https://github.com/larsrollik/djmux
|
|
6
|
+
Project-URL: Documentation, https://larsrollik.github.io/djmux/
|
|
7
|
+
Project-URL: Issue Tracker, https://github.com/larsrollik/djmux/issues
|
|
8
|
+
Author-email: "Lars B. Rollik" <code@rollik.me>
|
|
9
|
+
License:
|
|
10
|
+
BSD 3-Clause License
|
|
11
|
+
|
|
12
|
+
Copyright (c) 2026-present, Lars B. Rollik
|
|
13
|
+
All rights reserved.
|
|
14
|
+
|
|
15
|
+
Redistribution and use in source and binary forms, with or without
|
|
16
|
+
modification, are permitted provided that the following conditions are met:
|
|
17
|
+
|
|
18
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
19
|
+
this list of conditions and the following disclaimer.
|
|
20
|
+
|
|
21
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
22
|
+
this list of conditions and the following disclaimer in the documentation
|
|
23
|
+
and/or other materials provided with the distribution.
|
|
24
|
+
|
|
25
|
+
3. Neither the name of the copyright holder nor the names of its contributors
|
|
26
|
+
may be used to endorse or promote products derived from this software
|
|
27
|
+
without specific prior written permission.
|
|
28
|
+
|
|
29
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
30
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
31
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
32
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
33
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
34
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
35
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
36
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
37
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
38
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
39
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
40
|
+
License-File: LICENSE
|
|
41
|
+
Requires-Python: >=3.10
|
|
42
|
+
Requires-Dist: datajoint>=0.14
|
|
43
|
+
Requires-Dist: pyyaml>=6.0
|
|
44
|
+
Provides-Extra: dev
|
|
45
|
+
Requires-Dist: commitizen; extra == 'dev'
|
|
46
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
47
|
+
Requires-Dist: pre-commit; extra == 'dev'
|
|
48
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
49
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
50
|
+
Provides-Extra: docs
|
|
51
|
+
Requires-Dist: mkdocs-material; extra == 'docs'
|
|
52
|
+
Description-Content-Type: text/markdown
|
|
53
|
+
|
|
54
|
+
# djmux
|
|
55
|
+
|
|
56
|
+
**One config, many DataJoint packages on one server.** `djmux` lets several DataJoint
|
|
57
|
+
table-set packages run side-by-side on the same MySQL server — each under its own schema
|
|
58
|
+
**prefix** — from a single shared config file. It patches nothing else about DataJoint.
|
|
59
|
+
|
|
60
|
+
## Why
|
|
61
|
+
|
|
62
|
+
DataJoint natively supports a *single* schema prefix. As soon as you have more than one table-set
|
|
63
|
+
package on a server — a shared lab pipeline, a couple of per-user downstream packages, a `v1` and a
|
|
64
|
+
`v2` of the same schema — they either collide or need each package to hardcode a prefix. `djmux`
|
|
65
|
+
solves this with **one YAML file** that provides:
|
|
66
|
+
|
|
67
|
+
- the shared MySQL connection (standard `dj.config` keys), and
|
|
68
|
+
- a **map of schema prefixes keyed by package**.
|
|
69
|
+
|
|
70
|
+
Each package's schemas are then named `<prefix>__<name>`, so many packages activate together with
|
|
71
|
+
**no package hardcoding a prefix**, and versioning (`v1 → v2`) is a one-line config edit. Everything
|
|
72
|
+
else works exactly like stock DataJoint — `djmux` only patches `dj.config`.
|
|
73
|
+
|
|
74
|
+
## Install
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
pip install djmux
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Use
|
|
81
|
+
|
|
82
|
+
A single config file (`~/.djmux.yaml`, or point `$DJMUX_CONFIG` at it):
|
|
83
|
+
|
|
84
|
+
```yaml
|
|
85
|
+
datajoint: # standard DataJoint connection
|
|
86
|
+
host: db.lab
|
|
87
|
+
port: 3306
|
|
88
|
+
user: alice
|
|
89
|
+
password: ...
|
|
90
|
+
use_tls: true
|
|
91
|
+
prefixes: # one prefix per table-set package (v1 -> v2 = edit here)
|
|
92
|
+
mypipeline: mypipeline_v1 # shared pipeline package -> schemas mypipeline_v1__<name>
|
|
93
|
+
mine: alice_replay # your downstream package -> schemas alice_replay__<name>
|
|
94
|
+
stores: # optional filepath@ external store(s)
|
|
95
|
+
tree: { location: /data/store }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Then several packages activate together, each under its own prefix:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
import djmux, mypipeline, my_replay
|
|
102
|
+
djmux.load("~/.djmux.yaml") # sets the shared connection + prefix map (once)
|
|
103
|
+
mypipeline.activate() # -> mypipeline_v1__*
|
|
104
|
+
my_replay.activate() # -> alice_replay__*
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
A package makes itself djmux-aware by decorating tables with a **deferred** schema and delegating
|
|
108
|
+
activation:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
import datajoint as dj, djmux
|
|
112
|
+
schema = dj.Schema() # deferred (unnamed)
|
|
113
|
+
|
|
114
|
+
@schema
|
|
115
|
+
class Session(dj.Manual): ...
|
|
116
|
+
|
|
117
|
+
def activate(**kw):
|
|
118
|
+
djmux.activate(schema, key="mypipeline", name="core", linking_module=__name__, **kw)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## API
|
|
122
|
+
|
|
123
|
+
| function | purpose |
|
|
124
|
+
|---|---|
|
|
125
|
+
| `djmux.load(path=None)` | read the YAML, patch `dj.config` (connection + `custom.prefixes` + `stores`); enables `filepath@` |
|
|
126
|
+
| `djmux.activate(schema, key, name, ...)` | activate a deferred `dj.Schema()` as `<prefix>__<name>` (prefix from config `key`) |
|
|
127
|
+
| `djmux.get_datajoint_schema(file, module, key)` | eager per-file modular schema, `<prefix>__<filestem>` (orm-patterns style) |
|
|
128
|
+
| `djmux.schema_name(key, name)` / `resolve_prefix(key)` | naming helpers |
|
|
129
|
+
|
|
130
|
+
Prefix resolution order: explicit `override=` arg → `$DJMUX_PREFIX_<KEY>` env → config `prefixes[key]`.
|
|
131
|
+
Credentials may live in `~/.datajoint_config.json` instead and be omitted from the djmux config.
|
|
132
|
+
|
|
133
|
+
## Development
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
git clone https://github.com/larsrollik/djmux.git
|
|
137
|
+
cd djmux
|
|
138
|
+
uv sync --extra dev
|
|
139
|
+
uv run pre-commit install --hook-type pre-commit --hook-type commit-msg
|
|
140
|
+
uv run pytest
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Release
|
|
144
|
+
|
|
145
|
+
Bump `VERSION`, merge to `main`; the tag triggers a GitHub release + **OIDC trusted-publish** to PyPI
|
|
146
|
+
(no tokens). See `.github/workflows/release.yml`.
|
|
147
|
+
|
|
148
|
+
## License
|
|
149
|
+
|
|
150
|
+
BSD-3-Clause — see [LICENSE](LICENSE).
|
djmux-1.0.1/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# djmux
|
|
2
|
+
|
|
3
|
+
**One config, many DataJoint packages on one server.** `djmux` lets several DataJoint
|
|
4
|
+
table-set packages run side-by-side on the same MySQL server — each under its own schema
|
|
5
|
+
**prefix** — from a single shared config file. It patches nothing else about DataJoint.
|
|
6
|
+
|
|
7
|
+
## Why
|
|
8
|
+
|
|
9
|
+
DataJoint natively supports a *single* schema prefix. As soon as you have more than one table-set
|
|
10
|
+
package on a server — a shared lab pipeline, a couple of per-user downstream packages, a `v1` and a
|
|
11
|
+
`v2` of the same schema — they either collide or need each package to hardcode a prefix. `djmux`
|
|
12
|
+
solves this with **one YAML file** that provides:
|
|
13
|
+
|
|
14
|
+
- the shared MySQL connection (standard `dj.config` keys), and
|
|
15
|
+
- a **map of schema prefixes keyed by package**.
|
|
16
|
+
|
|
17
|
+
Each package's schemas are then named `<prefix>__<name>`, so many packages activate together with
|
|
18
|
+
**no package hardcoding a prefix**, and versioning (`v1 → v2`) is a one-line config edit. Everything
|
|
19
|
+
else works exactly like stock DataJoint — `djmux` only patches `dj.config`.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
pip install djmux
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Use
|
|
28
|
+
|
|
29
|
+
A single config file (`~/.djmux.yaml`, or point `$DJMUX_CONFIG` at it):
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
32
|
+
datajoint: # standard DataJoint connection
|
|
33
|
+
host: db.lab
|
|
34
|
+
port: 3306
|
|
35
|
+
user: alice
|
|
36
|
+
password: ...
|
|
37
|
+
use_tls: true
|
|
38
|
+
prefixes: # one prefix per table-set package (v1 -> v2 = edit here)
|
|
39
|
+
mypipeline: mypipeline_v1 # shared pipeline package -> schemas mypipeline_v1__<name>
|
|
40
|
+
mine: alice_replay # your downstream package -> schemas alice_replay__<name>
|
|
41
|
+
stores: # optional filepath@ external store(s)
|
|
42
|
+
tree: { location: /data/store }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Then several packages activate together, each under its own prefix:
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
import djmux, mypipeline, my_replay
|
|
49
|
+
djmux.load("~/.djmux.yaml") # sets the shared connection + prefix map (once)
|
|
50
|
+
mypipeline.activate() # -> mypipeline_v1__*
|
|
51
|
+
my_replay.activate() # -> alice_replay__*
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
A package makes itself djmux-aware by decorating tables with a **deferred** schema and delegating
|
|
55
|
+
activation:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import datajoint as dj, djmux
|
|
59
|
+
schema = dj.Schema() # deferred (unnamed)
|
|
60
|
+
|
|
61
|
+
@schema
|
|
62
|
+
class Session(dj.Manual): ...
|
|
63
|
+
|
|
64
|
+
def activate(**kw):
|
|
65
|
+
djmux.activate(schema, key="mypipeline", name="core", linking_module=__name__, **kw)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## API
|
|
69
|
+
|
|
70
|
+
| function | purpose |
|
|
71
|
+
|---|---|
|
|
72
|
+
| `djmux.load(path=None)` | read the YAML, patch `dj.config` (connection + `custom.prefixes` + `stores`); enables `filepath@` |
|
|
73
|
+
| `djmux.activate(schema, key, name, ...)` | activate a deferred `dj.Schema()` as `<prefix>__<name>` (prefix from config `key`) |
|
|
74
|
+
| `djmux.get_datajoint_schema(file, module, key)` | eager per-file modular schema, `<prefix>__<filestem>` (orm-patterns style) |
|
|
75
|
+
| `djmux.schema_name(key, name)` / `resolve_prefix(key)` | naming helpers |
|
|
76
|
+
|
|
77
|
+
Prefix resolution order: explicit `override=` arg → `$DJMUX_PREFIX_<KEY>` env → config `prefixes[key]`.
|
|
78
|
+
Credentials may live in `~/.datajoint_config.json` instead and be omitted from the djmux config.
|
|
79
|
+
|
|
80
|
+
## Development
|
|
81
|
+
|
|
82
|
+
```sh
|
|
83
|
+
git clone https://github.com/larsrollik/djmux.git
|
|
84
|
+
cd djmux
|
|
85
|
+
uv sync --extra dev
|
|
86
|
+
uv run pre-commit install --hook-type pre-commit --hook-type commit-msg
|
|
87
|
+
uv run pytest
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Release
|
|
91
|
+
|
|
92
|
+
Bump `VERSION`, merge to `main`; the tag triggers a GitHub release + **OIDC trusted-publish** to PyPI
|
|
93
|
+
(no tokens). See `.github/workflows/release.yml`.
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
BSD-3-Clause — see [LICENSE](LICENSE).
|
djmux-1.0.1/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.1
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "djmux"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Shared DataJoint connection and multi-prefix schema activation"
|
|
9
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Lars B. Rollik", email = "code@rollik.me" },
|
|
13
|
+
]
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
dependencies = [
|
|
16
|
+
"datajoint>=0.14",
|
|
17
|
+
"pyyaml>=6.0",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/larsrollik/djmux"
|
|
22
|
+
Documentation = "https://larsrollik.github.io/djmux/"
|
|
23
|
+
"Issue Tracker" = "https://github.com/larsrollik/djmux/issues"
|
|
24
|
+
|
|
25
|
+
# ---------------------------------------------------------------------------
|
|
26
|
+
# Build
|
|
27
|
+
# ---------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
[tool.hatch.version]
|
|
30
|
+
source = "vcs"
|
|
31
|
+
fallback-version = "1.0.0"
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.hooks.vcs]
|
|
34
|
+
version-file = "src/djmux/_version.py"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.build.targets.wheel]
|
|
37
|
+
packages = ["src/djmux"]
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.sdist]
|
|
40
|
+
include = [
|
|
41
|
+
"/src/djmux",
|
|
42
|
+
"/tests",
|
|
43
|
+
"/README.md",
|
|
44
|
+
"/LICENSE",
|
|
45
|
+
"/pyproject.toml",
|
|
46
|
+
"/CITATION.cff",
|
|
47
|
+
"/VERSION",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
# ---------------------------------------------------------------------------
|
|
51
|
+
# Dependencies
|
|
52
|
+
# ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
[project.optional-dependencies]
|
|
55
|
+
dev = [
|
|
56
|
+
"commitizen",
|
|
57
|
+
"pytest>=8",
|
|
58
|
+
"pytest-cov",
|
|
59
|
+
"pre-commit",
|
|
60
|
+
"mypy",
|
|
61
|
+
]
|
|
62
|
+
docs = [
|
|
63
|
+
"mkdocs-material",
|
|
64
|
+
# Uncomment to enable auto-generated API reference from docstrings:
|
|
65
|
+
# "mkdocstrings[python]",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
# ---------------------------------------------------------------------------
|
|
69
|
+
# Commitizen
|
|
70
|
+
# ---------------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
[tool.commitizen]
|
|
73
|
+
name = "cz_conventional_commits"
|
|
74
|
+
version_provider = "commitizen"
|
|
75
|
+
version = "1.0.1"
|
|
76
|
+
version_files = ["VERSION", "CITATION.cff:^version:"]
|
|
77
|
+
tag_format = "v$version"
|
|
78
|
+
update_changelog_on_bump = false
|
|
79
|
+
|
|
80
|
+
# ---------------------------------------------------------------------------
|
|
81
|
+
# Pytest
|
|
82
|
+
# ---------------------------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
[tool.pytest.ini_options]
|
|
85
|
+
testpaths = ["tests"]
|
|
86
|
+
addopts = "--cov=src/djmux --cov-report=term-missing --maxfail=5"
|
|
87
|
+
|
|
88
|
+
# ---------------------------------------------------------------------------
|
|
89
|
+
# Ruff
|
|
90
|
+
# ---------------------------------------------------------------------------
|
|
91
|
+
|
|
92
|
+
[tool.ruff]
|
|
93
|
+
line-length = 100
|
|
94
|
+
indent-width = 4
|
|
95
|
+
src = ["src"]
|
|
96
|
+
|
|
97
|
+
[tool.ruff.lint]
|
|
98
|
+
select = [
|
|
99
|
+
"E", "W", # pycodestyle
|
|
100
|
+
"F", # pyflakes
|
|
101
|
+
"I", # isort
|
|
102
|
+
"UP", # pyupgrade
|
|
103
|
+
"B", # flake8-bugbear
|
|
104
|
+
"SIM", # flake8-simplify
|
|
105
|
+
"PTH", # flake8-pathlib
|
|
106
|
+
"TCH", # flake8-type-checking
|
|
107
|
+
"PYI", # flake8-pyi
|
|
108
|
+
"YTT", # flake8-2020
|
|
109
|
+
"N", # pep8-naming
|
|
110
|
+
]
|
|
111
|
+
ignore = []
|
|
112
|
+
fixable = ["ALL"]
|
|
113
|
+
|
|
114
|
+
[tool.ruff.format]
|
|
115
|
+
quote-style = "double"
|
|
116
|
+
indent-style = "space"
|
|
117
|
+
docstring-code-format = true
|
|
118
|
+
|
|
119
|
+
[tool.ruff.lint.pydocstyle]
|
|
120
|
+
convention = "numpy"
|
|
121
|
+
|
|
122
|
+
# ---------------------------------------------------------------------------
|
|
123
|
+
# Mypy
|
|
124
|
+
# ---------------------------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
[tool.mypy]
|
|
127
|
+
python_version = "3.10"
|
|
128
|
+
warn_return_any = true
|
|
129
|
+
warn_unused_ignores = true
|
|
130
|
+
ignore_missing_imports = true
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""djmux — shared DataJoint connection + multi-prefix schema activation.
|
|
2
|
+
|
|
3
|
+
ONE config file feeds (a) the shared MySQL connection and (b) a MAP of schema
|
|
4
|
+
**prefixes keyed by package**, so several table-set packages activate side-by-side
|
|
5
|
+
on the SAME server, each under its own prefix, with no package hardcoding a prefix.
|
|
6
|
+
Versioning (v1 -> v2) is a config edit.
|
|
7
|
+
|
|
8
|
+
Typical use (several packages, same MySQL, own prefixes, all live)::
|
|
9
|
+
|
|
10
|
+
import djmux, mypipeline, other_pkg
|
|
11
|
+
|
|
12
|
+
djmux.load("~/.djmux.yaml")
|
|
13
|
+
mypipeline.activate() # -> mypipeline_v1__*
|
|
14
|
+
other_pkg.activate() # -> other_pkg_v1__*
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
20
|
+
|
|
21
|
+
from .activation import activate, deferred, get_datajoint_schema
|
|
22
|
+
from .config import CONFIG, load
|
|
23
|
+
from .prefixes import resolve_prefix, schema_name
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
__version__ = version("djmux")
|
|
27
|
+
except PackageNotFoundError: # pragma: no cover
|
|
28
|
+
__version__ = "unknown"
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"load",
|
|
32
|
+
"CONFIG",
|
|
33
|
+
"resolve_prefix",
|
|
34
|
+
"schema_name",
|
|
35
|
+
"deferred",
|
|
36
|
+
"get_datajoint_schema",
|
|
37
|
+
"activate",
|
|
38
|
+
"__version__",
|
|
39
|
+
]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# file generated by vcs-versioning
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = [
|
|
6
|
+
"__version__",
|
|
7
|
+
"__version_tuple__",
|
|
8
|
+
"version",
|
|
9
|
+
"version_tuple",
|
|
10
|
+
"__commit_id__",
|
|
11
|
+
"commit_id",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
version: str
|
|
15
|
+
__version__: str
|
|
16
|
+
__version_tuple__: tuple[int | str, ...]
|
|
17
|
+
version_tuple: tuple[int | str, ...]
|
|
18
|
+
commit_id: str | None
|
|
19
|
+
__commit_id__: str | None
|
|
20
|
+
|
|
21
|
+
__version__ = version = '1.0.1'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 0, 1)
|
|
23
|
+
|
|
24
|
+
__commit_id__ = commit_id = None
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Schema activation helpers — deferred (Elements-style) and eager (modular) variants.
|
|
2
|
+
|
|
3
|
+
Both name schemas ``'<prefix>__<name>'`` with the prefix resolved from the config
|
|
4
|
+
map by ``key``. Generalises lbr_phd_db's ``get_datajoint_schema(...)`` factory to a
|
|
5
|
+
per-package prefix map.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
import datajoint as dj
|
|
13
|
+
|
|
14
|
+
from .prefixes import schema_name
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def deferred() -> dj.Schema:
|
|
18
|
+
"""A DEFERRED (unnamed) schema — decorate tables with it, activate later
|
|
19
|
+
via :func:`activate`."""
|
|
20
|
+
return dj.Schema()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_datajoint_schema(
|
|
24
|
+
file: str,
|
|
25
|
+
linking_module,
|
|
26
|
+
key: str,
|
|
27
|
+
override: str | None = None,
|
|
28
|
+
*,
|
|
29
|
+
create_schema: bool = True,
|
|
30
|
+
create_tables: bool = True,
|
|
31
|
+
) -> dj.Schema:
|
|
32
|
+
"""orm-patterns style, per-file modular schema: name = ``<prefix>__<filestem>``,
|
|
33
|
+
prefix resolved from the config map by ``key`` (or ``override``). EAGER — requires
|
|
34
|
+
:func:`config.load` (or dj creds) beforehand. Use per table module::
|
|
35
|
+
|
|
36
|
+
schema = djmux.get_datajoint_schema(
|
|
37
|
+
__file__, __name__, key="mypipeline"
|
|
38
|
+
) # -> <prefix>__ephys
|
|
39
|
+
|
|
40
|
+
(Prefer :func:`activate` for deferred/import-anytime, Elements style.)
|
|
41
|
+
"""
|
|
42
|
+
return dj.Schema(
|
|
43
|
+
schema_name(key, Path(file).stem, override),
|
|
44
|
+
create_schema=create_schema,
|
|
45
|
+
create_tables=create_tables,
|
|
46
|
+
add_objects=getattr(linking_module, "__dict__", None)
|
|
47
|
+
if not isinstance(linking_module, str)
|
|
48
|
+
else __import__("sys").modules.get(linking_module).__dict__,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def activate(
|
|
53
|
+
schema: dj.Schema,
|
|
54
|
+
key: str,
|
|
55
|
+
name: str,
|
|
56
|
+
linking_module=None,
|
|
57
|
+
override: str | None = None,
|
|
58
|
+
*,
|
|
59
|
+
create_schema: bool = True,
|
|
60
|
+
create_tables: bool = True,
|
|
61
|
+
) -> dj.Schema:
|
|
62
|
+
"""Activate a deferred ``dj.Schema()`` under ``'<prefix>__<name>'``; ``key`` selects the
|
|
63
|
+
per-package prefix from the config map (or ``override``). Call from a package's ``activate()``.
|
|
64
|
+
"""
|
|
65
|
+
schema.activate(
|
|
66
|
+
schema_name(key, name, override),
|
|
67
|
+
create_schema=create_schema,
|
|
68
|
+
create_tables=create_tables,
|
|
69
|
+
add_objects=getattr(linking_module, "__dict__", None),
|
|
70
|
+
)
|
|
71
|
+
return schema
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""Shared config load — patch the standard ``dj.config`` from one YAML file.
|
|
2
|
+
|
|
3
|
+
``load()`` reads a single YAML file and sets the *standard* DataJoint connection
|
|
4
|
+
keys plus a **map of schema prefixes keyed by package** (``custom.prefixes``), so
|
|
5
|
+
several table-set packages can activate side-by-side on the SAME server, each under
|
|
6
|
+
its own prefix, with no package hardcoding one. Everything else about DataJoint
|
|
7
|
+
works unchanged — this only patches ``dj.config``.
|
|
8
|
+
|
|
9
|
+
Config path resolution: explicit arg > ``$DJMUX_CONFIG`` > ``~/.djmux.yaml``.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
import datajoint as dj
|
|
18
|
+
|
|
19
|
+
#: The parsed config. Mutated in place by :func:`load` so re-exports stay live.
|
|
20
|
+
CONFIG: dict = {}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def load(path: str | os.PathLike | None = None) -> dict:
|
|
24
|
+
"""Load the shared config; set the MySQL connection + prefix map + filepath@ stores.
|
|
25
|
+
|
|
26
|
+
Connection keys already present in ``~/.datajoint_config.json`` / ``DJ_*`` env are
|
|
27
|
+
left to DataJoint if omitted here — this only sets what the config provides.
|
|
28
|
+
"""
|
|
29
|
+
import yaml
|
|
30
|
+
|
|
31
|
+
# the mypipeline schema (and others) use filepath@ stores; DataJoint gates this
|
|
32
|
+
# experimental type behind an env var. Enable by default for every client (opt-out via env).
|
|
33
|
+
os.environ.setdefault("DJ_SUPPORT_FILEPATH_MANAGEMENT", "TRUE")
|
|
34
|
+
|
|
35
|
+
p = Path(path or os.environ.get("DJMUX_CONFIG", "~/.djmux.yaml")).expanduser()
|
|
36
|
+
CONFIG.clear()
|
|
37
|
+
CONFIG.update(yaml.safe_load(p.read_text()) or {})
|
|
38
|
+
|
|
39
|
+
d = CONFIG.get("datajoint", {}) or {}
|
|
40
|
+
if d.get("host"):
|
|
41
|
+
dj.config["database.host"] = d["host"]
|
|
42
|
+
if d.get("port"):
|
|
43
|
+
dj.config["database.port"] = int(d["port"])
|
|
44
|
+
if d.get("user"):
|
|
45
|
+
dj.config["database.user"] = d["user"]
|
|
46
|
+
if d.get("password") is not None:
|
|
47
|
+
dj.config["database.password"] = d["password"]
|
|
48
|
+
dj.config["database.use_tls"] = d.get("use_tls", True)
|
|
49
|
+
dj.config["safemode"] = d.get("safemode", False)
|
|
50
|
+
dj.config.setdefault("custom", {})["prefixes"] = CONFIG.get("prefixes", {}) or {}
|
|
51
|
+
|
|
52
|
+
stores = CONFIG.get("stores") or {}
|
|
53
|
+
if stores:
|
|
54
|
+
dj.config["stores"] = {
|
|
55
|
+
**(dj.config.get("stores") or {}),
|
|
56
|
+
**{
|
|
57
|
+
name: {
|
|
58
|
+
"protocol": s.get("protocol", "file"),
|
|
59
|
+
"location": s["location"],
|
|
60
|
+
"stage": s.get("stage", s["location"]),
|
|
61
|
+
}
|
|
62
|
+
for name, s in stores.items()
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
return CONFIG
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""Per-package prefix resolution and ``'<prefix>__<name>'`` schema naming.
|
|
2
|
+
|
|
3
|
+
The prefix for a package is resolved: explicit ``override`` > ``$DJMUX_PREFIX_<KEY>``
|
|
4
|
+
> the config ``prefixes[key]`` map. This is the one thing DataJoint does not do
|
|
5
|
+
natively (it has a single ``database.prefix``); everything else is stock DataJoint.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
import datajoint as dj
|
|
13
|
+
|
|
14
|
+
from . import config
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def resolve_prefix(key: str, override: str | None = None) -> str:
|
|
18
|
+
"""Prefix for a package: explicit ``override`` > ``$DJMUX_PREFIX_<KEY>`` > config
|
|
19
|
+
``prefixes[key]``."""
|
|
20
|
+
if override:
|
|
21
|
+
return override
|
|
22
|
+
env = os.environ.get(f"DJMUX_PREFIX_{key.upper()}")
|
|
23
|
+
if env:
|
|
24
|
+
return env
|
|
25
|
+
prefixes = (
|
|
26
|
+
(dj.config.get("custom") or {}).get("prefixes") or config.CONFIG.get("prefixes") or {}
|
|
27
|
+
)
|
|
28
|
+
if key in prefixes:
|
|
29
|
+
return str(prefixes[key])
|
|
30
|
+
raise KeyError(
|
|
31
|
+
f"no prefix for package '{key}': set prefixes.{key} in the djmux config, pass override=, "
|
|
32
|
+
f"or export DJMUX_PREFIX_{key.upper()}"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def schema_name(key: str, name: str, override: str | None = None) -> str:
|
|
37
|
+
"""``'<prefix>__<name>'`` (double-underscore join; lbr_phd_db convention)."""
|
|
38
|
+
return "__".join([resolve_prefix(key, override), name])
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from __future__ import annotations
|