forked from python-poetry/poetry-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude.py
49 lines (33 loc) · 1.04 KB
/
include.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pathlib import Path
class Include:
"""
Represents an "include" entry.
It can be a glob string, a single file or a directory.
This class will then detect the type of this include:
- a package
- a module
- a file
- a directory
"""
def __init__(self, base: Path, include: str, formats: list[str]) -> None:
self._base = base
self._include = str(include)
self._formats = formats
self._elements: list[Path] = sorted(self._base.glob(str(self._include)))
@property
def base(self) -> Path:
return self._base
@property
def elements(self) -> list[Path]:
return self._elements
@property
def formats(self) -> list[str]:
return self._formats
def is_empty(self) -> bool:
return len(self._elements) == 0
def refresh(self) -> Include:
self._elements = sorted(self._base.glob(self._include))
return self