Skip to content
Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ douki check src/
douki sync src/
```

By default, Douki respects `.gitignore` during file discovery. You can
disable that per run with `--no-respect-gitignore`, or set
`[tool.douki] respect-gitignore = false` in `pyproject.toml`.

## What's Next?

- [Installation](installation.md) — install via pip, conda, or from source
Expand Down
12 changes: 10 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,18 +356,26 @@ def add(x, y):

## Configuration

You can configure Douki using a `pyproject.toml` file in your project root. Currently, Douki supports excluding files or directories using glob patterns.
You can configure Douki using a `pyproject.toml` file in your project root.
Douki supports excluding files or directories using glob patterns, and it
respects `.gitignore` during file discovery by default.

```toml
[tool.douki]
# Respect `.gitignore` by default. Set to false to opt out globally.
respect-gitignore = true

# Exclude specific files or entire directories
exclude = [
"tests/smoke/*",
"legacy_module.py"
]
```

When running `douki sync` or `douki check`, any file matching these patterns will be ignored.
When running `douki sync`, `douki check`, or `douki migrate`, any file
matching these patterns will be ignored. You can override the `.gitignore`
setting for a single run with `--respect-gitignore` or
`--no-respect-gitignore`.

---

Expand Down
40 changes: 30 additions & 10 deletions src/douki/_base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

from abc import ABC, abstractmethod
from pathlib import Path
from typing import List
from typing import List, Tuple

from douki._base.discovery import (
DiscoveryConfig,
collect_source_files,
load_douki_discovery_config,
)


class BaseConfig(ABC):
Expand All @@ -17,30 +23,44 @@ class BaseConfig(ABC):
source files are discovered.
"""

@property
@abstractmethod
def load_exclude_patterns(self, cwd: Path) -> List[str]:
def file_extensions(self) -> Tuple[str, ...]:
"""
title: File extensions handled by the language backend.
returns:
type: Tuple[str, Ellipsis]
"""
title: Load exclude patterns from a config file.
... # pragma: no cover

def load_discovery_config(self, cwd: Path) -> DiscoveryConfig:
"""
title: Load shared discovery settings from project configuration.
parameters:
cwd:
type: Path
returns:
type: List[str]
type: DiscoveryConfig
"""
... # pragma: no cover
return load_douki_discovery_config(cwd)

@abstractmethod
def collect_files(
self, paths: List[Path], excludes: List[str]
self,
paths: List[Path],
discovery: DiscoveryConfig,
) -> List[Path]:
"""
title: Expand paths into source files, filtering excluded ones.
parameters:
paths:
type: List[Path]
excludes:
type: List[str]
discovery:
type: DiscoveryConfig
returns:
type: List[Path]
"""
... # pragma: no cover
return collect_source_files(
paths,
file_extensions=self.file_extensions,
discovery=discovery,
)
Loading
Loading