Skip to content

Commit 379122c

Browse files
committed
docs: update venv-strategy with current implementation details
- Add projects/ directory to the structure diagram - Add dbx project add command behaviour section (project-specific lookup order) - Fix "uvx" → "pipx" in the technical implementation section - Update get_venv_info code example to reflect actual signature (fallback_paths, PATH-based activated venv check, auto-detect logic)
1 parent 23fe035 commit 379122c

1 file changed

Lines changed: 38 additions & 33 deletions

File tree

docs/design/venv-strategy.rst

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ This supports a structure like:
3636
3737
~/Developer/mongodb/
3838
├── .venv/ # Base venv (shared across all groups)
39+
├── projects/
40+
│ ├── .venv/ # Shared venv for all Django projects
41+
│ ├── myproject/
42+
│ └── another_project/
3943
├── pymongo/
4044
│ ├── .venv/ # Group-level venv (optional)
4145
│ ├── mongo-python-driver/
@@ -95,6 +99,18 @@ Run tests using the most specific venv found:
9599
# Uses repo, group, or base venv — whichever is most specific
96100
dbx test mongo-python-driver
97101
102+
dbx project add
103+
~~~~~~~~~~~~~~~
104+
105+
Django project creation uses a project-specific lookup order:
106+
107+
1. ``projects/.venv`` — shared venv for all projects (group level)
108+
2. ``base_dir/django/.venv`` — django group venv, if it exists
109+
3. ``base_dir/.venv`` — base venv
110+
4. Activated venv
111+
112+
If no venv is found and ``--install`` is active (the default), one is created automatically at ``projects/.venv`` and Django is bootstrapped into it. See :doc:`wagtail-support` for how this interacts with Wagtail projects.
113+
98114
Venv Detection
99115
--------------
100116

@@ -121,7 +137,7 @@ Technical Implementation
121137
Running Commands in Venvs
122138
~~~~~~~~~~~~~~~~~~~~~~~~~~
123139

124-
When ``dbx`` (running in uvx's isolated environment) needs to execute commands in a venv, it cannot use ``source`` or activation scripts in subprocesses. Instead, it must directly invoke the venv's Python executable:
140+
When ``dbx`` (installed via pipx into an isolated environment) needs to execute commands in a venv, it cannot use ``source`` or activation scripts in subprocesses. Instead, it must directly invoke the venv's Python executable:
125141

126142
.. code-block:: python
127143
@@ -140,46 +156,35 @@ This is because:
140156
Venv Detection Example
141157
~~~~~~~~~~~~~~~~~~~~~~
142158

159+
The actual ``get_venv_info`` signature includes an optional ``fallback_paths`` list for intermediate group lookups (used by ``dbx project`` commands to check the ``django`` group before falling back to base):
160+
143161
.. code-block:: python
144162
145-
def get_venv_info(repo_path, group_path=None, base_path=None):
163+
def get_venv_info(repo_path, group_path=None, base_path=None, fallback_paths=None):
146164
"""
147165
Get information about which venv will be used.
148166
149167
Checks in priority order (most specific to least specific):
150-
1. Repository-level venv
151-
2. Group-level venv
152-
3. Base directory venv
153-
4. Activated venv (sys.executable or shell PATH)
154-
5. Auto-detected venv (if exactly one exists)
168+
1. repo_path/.venv
169+
2. group_path/.venv
170+
3. Each path in fallback_paths (e.g. django group)
171+
4. base_path/.venv
172+
5. sys.executable — if already inside a venv
173+
6. PATH python — if a different venv is activated in the shell
174+
7. Auto-detected — if exactly one venv exists under base_path
175+
8. Error — system Python, installation refused
155176
156177
Returns:
157-
tuple: (python_path, venv_type) where venv_type is "base", "repo", "group", or "venv"
178+
tuple: (python_path, venv_type)
179+
venv_type is one of: "repo", "group", "base", "venv"
158180
159181
Raises:
160-
typer.Exit: If no virtual environment is found (system Python detected)
182+
typer.Exit: If no virtual environment is found
161183
"""
162-
# Check repository-level venv (most specific)
163-
if repo_path:
164-
repo_venv_python = repo_path / ".venv" / "bin" / "python"
165-
if repo_venv_python.exists():
166-
return str(repo_venv_python), "repo"
167-
168-
# Check group-level venv
169-
if group_path:
170-
group_venv_python = group_path / ".venv" / "bin" / "python"
171-
if group_venv_python.exists():
172-
return str(group_venv_python), "group"
173-
174-
# Check base directory venv
175-
if base_path:
176-
base_venv_python = base_path / ".venv" / "bin" / "python"
177-
if base_venv_python.exists():
178-
return str(base_venv_python), "base"
179-
180-
# Check activated venv
181-
if _is_venv(sys.executable):
182-
return sys.executable, "venv"
183-
184-
# System Python detected - error out
185-
raise typer.Exit(1)
184+
# 1. Repo-level venv
185+
# 2. Group-level venv
186+
# 3. Fallback group venvs (e.g. django group for projects)
187+
# 4. Base directory venv
188+
# 5-6. Activated venv (sys.executable or shell PATH)
189+
# 7. Auto-detect: if exactly one .venv exists, use it unambiguously
190+
# 8. Error with suggestions (dbx env init / source .venv/bin/activate)

0 commit comments

Comments
 (0)