Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ repos:
- id: check-toml
- id: check-added-large-files
args: ['--maxkb=1024']
# The tracked web build output (src/profiles/web/dist/) is a
# bundled artifact regenerated by `npm run build`; its minified
# JS bundle crossed the 1 MB source-size line (issue #192 PR).
exclude: ^src/profiles/web/dist/

# Ruff - Linter et formatter
- repo: https://github.com/astral-sh/ruff-pre-commit
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Ce document définit les standards d'architecture, les principes de conception e
src/profiles/
├── core/ # Logique métier — indépendante de toute UI
│ ├── actions.py # Actions domaine (lancement, ouverture, ActionResult)
│ ├── paths.py # Politique de chemins utilisateur (~/.profiles, CWD non informatifs, #191)
│ ├── config/ # Sous-système configuration
│ │ ├── models.py # AppConfig, MachineConfiguration, ColumnConfiguration
│ │ ├── loader.py # load_config, propose_config_creation
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- **Per-user configuration path policy** (issue #191): launcher-style
launches (Start Menu, pinned taskbar, `.desktop` entries — any process
whose CWD is System32, the home folder, or an install/runtime directory)
no longer propose creating `.profiles` in a system directory. The
proposal targets `~/.profiles/.profiles` (next to `profiles.log`), every
later launch loads that per-user default automatically, terminal/project
launches keep their current behavior, and no code path ever proposes an
existing directory as the configuration file. New
`profiles.core.paths` module is the single source of truth for these
user-level locations.
- **Windows installer polish**: the MSI now creates a desktop shortcut, asks
per-user vs per-machine at install time, and shows a proper finish page
("Launch ProFiles" checkbox plus Documentation / What's new links).
Expand All @@ -20,6 +30,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Branded installer**: the welcome dialog and page banners now use the
ProFiles brand art (indigo-violet gradient) instead of the stock WiX look.

### Fixed

- **Config picker mode follows the entry point** (issue #192): with no
active configuration, the editor's **Load config file…** and the file
list's **Choose configuration** buttons now open the picker in Load
mode; only the first-run auto-prompt still opens Create mode.

### Changed

- **Loopback-only by default**: the web server now binds `127.0.0.1` on launch
Expand Down
2 changes: 1 addition & 1 deletion README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ ProFiles --config "/path/to/.profiles"

## 🛠 Configuration

ProFiles est piloté par un fichier **YAML** `.profiles`, recherché en remontant l'arborescence du système de fichiers.
ProFiles est piloté par un fichier **YAML** `.profiles`, recherché en remontant l'arborescence du système de fichiers. Les lancements par lanceur (menu Démarrer, dock, entrées `.desktop`) ignorent la recherche dans l'arborescence et chargent le défaut par utilisateur `~/.profiles/.profiles` s'il existe ; sans fichier trouvé, la proposition de création cible le dossier du projet — ou `~/.profiles` pour un lancement par lanceur — afin de ne jamais écrire dans un répertoire système.

```yaml
# ProFiles Configuration — Format YAML
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ ProFiles --config "/path/to/.profiles"

## 🛠 Configuration

ProFiles is driven by a `.profiles` **YAML** file, walking up the filesystem tree to locate it.
ProFiles is driven by a `.profiles` **YAML** file, walking up the filesystem tree to locate it. Launcher-style starts (Start Menu, dock, `.desktop` entries) skip the tree search and load the per-user default `~/.profiles/.profiles` when it exists; when nothing is found, the creation proposal targets the project folder — or `~/.profiles` for launcher starts — so nothing is ever written into a system directory.

```yaml
# ProFiles Configuration — YAML Format
Expand Down
6 changes: 3 additions & 3 deletions docs/configuration-profile.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@

## Overview

The `.profiles` file is a **YAML-format** configuration file that customizes ProFiles's behavior. This file is searched for starting from the current working directory (CWD) and descending into subdirectories. The first match found is used.
The `.profiles` file is a **YAML-format** configuration file that customizes ProFiles's behavior. This file is searched for starting from the current working directory (CWD) and descending into subdirectories. The first match found is used. The CWD tree is skipped when the CWD carries no launch information — a Start-Menu/launcher start inherits `System32`, the home folder, or the interpreter/app install directory — and the per-user default `~/.profiles/.profiles` is loaded when it exists instead.

If no `.profiles` file is found:

- In interactive mode (web UI, desktop or browser): ProFiles proposes to create a default configuration file
- In interactive mode (web UI, desktop or browser): ProFiles proposes to create a default configuration file — in the project folder for a terminal launch, in `~/.profiles` for a launcher-style launch
- In headless mode: ProFiles uses default values identical to those presented in this document

## Creating the Configuration File

### Method 1: Automatic Proposal (Interactive Mode)

On first launch in interactive mode (web UI in the PyWebView shell or browser), if no `.profiles` file is found, ProFiles proposes to create a default configuration file in the current working directory.
On first launch in interactive mode (web UI in the PyWebView shell or browser), if no `.profiles` file is found, ProFiles proposes to create a default configuration file in the current working directory. When that directory carries no launch information (a Start-Menu shortcut, a launcher with an empty "Start in" field, a Finder/dock launch), the proposal targets `~/.profiles/.profiles` instead — the same folder as `profiles.log` — so nothing is ever written into a system directory, and every later launch loads that per-user default automatically.

### Method 2: Command Line

Expand Down
6 changes: 3 additions & 3 deletions docs/configuration-profile.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

## Vue d'ensemble

Le fichier `.profiles` est un fichier de configuration au format **YAML** qui personnalise le comportement de ProFiles. Ce fichier est recherché en commençant depuis le répertoire courant (CWD) et en descendant dans les sous-répertoires. Le premier fichier trouvé est utilisé.
Le fichier `.profiles` est un fichier de configuration au format **YAML** qui personnalise le comportement de ProFiles. Ce fichier est recherché en commençant depuis le répertoire courant (CWD) et en descendant dans les sous-répertoires. Le premier fichier trouvé est utilisé. La recherche dans l'arborescence du CWD est ignorée lorsque le CWD ne porte aucune information de lancement — un démarrage via le menu Démarrer/ lanceur hérite de `System32`, du dossier personnel ou du répertoire d'installation de l'interpréteur/application — et le défaut par utilisateur `~/.profiles/.profiles` est chargé s'il existe.

Si aucun fichier `.profiles` n'est trouvé :
- En mode interactif (interface web, bureau ou navigateur) : ProFiles propose de créer un fichier de configuration par défaut
- En mode interactif (interface web, bureau ou navigateur) : ProFiles propose de créer un fichier de configuration par défaut — dans le dossier du projet pour un lancement en terminal, dans `~/.profiles` pour un lancement par lanceur
- En mode headless : ProFiles utilise des valeurs par défaut identiques à celles présentées dans ce document

## Création du fichier de configuration

### Méthode 1 : Proposition automatique (mode interactif)

Au premier lancement en mode interactif (interface web dans la fenêtre PyWebView ou dans le navigateur), si aucun fichier `.profiles` n'est trouvé, ProFiles propose de créer un fichier de configuration par défaut dans le répertoire courant.
Au premier lancement en mode interactif (interface web dans la fenêtre PyWebView ou dans le navigateur), si aucun fichier `.profiles` n'est trouvé, ProFiles propose de créer un fichier de configuration par défaut dans le répertoire courant. Lorsque ce répertoire ne porte aucune information de lancement (raccourci du menu Démarrer, lanceur avec un champ « Démarrer dans » vide, lancement depuis le Finder/dock), la proposition cible `~/.profiles/.profiles` — le même dossier que `profiles.log` — afin de ne jamais écrire dans un répertoire système ; chaque lancement suivant charge automatiquement ce défaut par utilisateur.

### Méthode 2 : Commande ligne de commande

Expand Down
7 changes: 7 additions & 0 deletions docs/installation-guide.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ python -m profiles --init

This creates a `.profiles` file in the current directory with default settings.

You can also skip this step: on the **first launch from the Start Menu** (or
any launcher that runs without a project folder), ProFiles proposes to create
the configuration at `~/.profiles/.profiles` — the same folder as
`profiles.log` — and every later launch loads that per-user default
automatically. Launches from a terminal inside a project keep proposing the
project-local `.profiles`.

### 2. Customize configuration

Edit the `.profiles` file to adapt:
Expand Down
28 changes: 21 additions & 7 deletions src/profiles/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from profiles.core import AppConfig, actions, load_config
from profiles.core.config.io.yaml_io import PRIMARY_CONFIG_NAME
from profiles.core.environment.system import format_user_host
from profiles.core.paths import default_config_path
from profiles.core.processing.scanner import scan_and_process
from profiles.core.telemetry import events
from profiles.core.telemetry.diagnostics import (
Expand Down Expand Up @@ -172,8 +173,8 @@ def _setup_logging(self, level: int | str = logging.INFO) -> logging.Logger:
def _resolve_startup_config(
self,
explicit: Path | None,
) -> tuple[Path | None, bool]:
"""Return (config_path, config_is_missing).
) -> tuple[Path | None, bool, Path]:
"""Return (config_path, config_is_missing, launch_default).

Uses the launch resolution logic to determine which config file
should be used for this launch. On macOS a double-clicked
Expand All @@ -182,11 +183,20 @@ def _resolve_startup_config(
context (issue #188). The context source is remembered for the
busy-port handoff decision.

The third element is the launch-default target from
:func:`profiles.core.paths.default_config_path` — where a
missing configuration would be proposed (``~/.profiles/.profiles``
for launcher-style launches, the project folder for terminal
launches; issue #191). The defaults AppConfig carries it when
nothing was resolved, so the server and UI pre-fill the right
path without any server-specific override.

Args:
explicit: Value of --config flag, if any.

Returns:
Tuple of (resolved config path or None, whether it's missing).
Tuple of (resolved config path or None, whether it's missing,
default proposal target).
"""
documents: tuple[Path, ...] = ()
if not self._headless:
Expand All @@ -198,12 +208,15 @@ def _resolve_startup_config(
self._launch_source = ctx.source
resolved = resolve_config_path(ctx)
is_missing = resolved is not None and not resolved.exists()
return resolved, is_missing
launch_default = default_config_path(ctx.working_directory)
return resolved, is_missing, launch_default

def _load_configuration(self, logger: logging.Logger) -> AppConfig:
"""Load the application configuration.

Uses launch-time resolution to determine which config file to use.
When nothing resolves, the defaults are bound to the launch-default
target (``~/.profiles/.profiles`` for launcher starts, issue #191).
If no config is found and not in server-only mode, offers to create
a starter configuration.

Expand All @@ -217,22 +230,23 @@ def _load_configuration(self, logger: logging.Logger) -> AppConfig:
SystemExit(1) if configuration is invalid.
"""
# Use launch resolution instead of bare self._config_path
resolved, is_missing = self._resolve_startup_config(self._config_path)
resolved, is_missing, launch_default = self._resolve_startup_config(self._config_path)

if is_missing:
events.config_invalid(logger, error=f"Config file not found: {resolved}")
print(f"ERROR: Configuration file not found: {resolved}", file=sys.stderr)
sys.exit(1)

effective_path = resolved if resolved is not None else launch_default
try:
config = load_config(resolved)
config = load_config(effective_path)
events.config_loaded(
logger,
path=str(resolved) if resolved else "auto",
mode="launch resolution" if resolved else "auto",
release=config.release,
)
self._config_path = resolved # Update for later use
self._config_path = effective_path # Update for later use
return config
except (OSError, ValueError) as exc:
events.config_invalid(logger, error=str(exc))
Expand Down
1 change: 1 addition & 0 deletions src/profiles/core/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ owns a single responsibility:

| Sub-package / file | Responsibility (SRP) |
| ------------------------ | ------------------------------------------------------------------------------------ |
| `paths.py` | Per-user path policy: `~/.profiles` data dir, config default, uninformative-directory tests (issue #191) |
| `config/__init__.py` | Single point of egress for the configuration subsystem (high-level API) |
| `config/models.py` | Pure dataclasses (`AppConfig`, `MachineConfiguration`, `ColumnConfiguration`, `HookSpec`, `WorkflowStep`) |
| `config/service.py` | Domain operations over `AppConfig` — find, merge, auto-select directories |
Expand Down
15 changes: 15 additions & 0 deletions src/profiles/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
parse_hook_entries,
run_hooks_for_file,
)
from profiles.core.paths import (
default_config_path,
default_search_directory,
find_user_config,
is_uninformative_directory,
user_config_path,
user_data_dir,
)
from profiles.core.processing import (
ScannedFile,
ScannedFileDynamic,
Expand Down Expand Up @@ -90,6 +98,13 @@
"scan_and_process",
# Template
"STARTER_CONFIG_TEMPLATE",
# Per-user path policy (issue #191)
"default_config_path",
"default_search_directory",
"find_user_config",
"is_uninformative_directory",
"user_config_path",
"user_data_dir",
# System
"SystemInfo",
"collect_system_info",
Expand Down
13 changes: 13 additions & 0 deletions src/profiles/core/config/io/yaml_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@
#: Every accepted configuration file name, primary first.
CONFIG_FILE_NAMES: tuple[str, ...] = (PRIMARY_CONFIG_NAME, *FALLBACK_CONFIG_NAMES)


def is_config_file_name(name: str) -> bool:
"""True when a file *name* matches the accepted config whitelist.

Case-insensitive on purpose: the save-as endpoint accepts
``BACKUP.PROFILES`` (issue #95 wave), so every apply-path gate must
re-accept what it wrote. Shared by the server's config-name check and
the desktop odoc applier's skip guard (issue #193).
"""
return name.lower().endswith(CONFIG_FILE_NAMES)


_yaml = YAML()
_yaml.preserve_quotes = True

Expand Down Expand Up @@ -268,6 +280,7 @@ def find_config_file(
"PRIMARY_CONFIG_NAME",
"content_hash",
"find_config_file",
"is_config_file_name",
"read_yaml",
"write_text_atomic",
"write_value",
Expand Down
Loading
Loading