5
5
from __future__ import annotations
6
6
7
7
import logging
8
+ from dataclasses import dataclass , field
8
9
from pathlib import Path
9
10
from typing import Literal
10
11
18
19
class DirtyPrimerDirectoryException (Exception ):
19
20
"""We can't pull if there's local changes."""
20
21
21
- def __init__ (self , path : Path | str ):
22
+ def __init__ (self , path : Path | str ) -> None :
22
23
super ().__init__ (
23
24
rf"""
24
25
@@ -31,6 +32,7 @@ def __init__(self, path: Path | str):
31
32
)
32
33
33
34
35
+ @dataclass (frozen = True )
34
36
class PackageToLint :
35
37
"""Represents data about a package to be tested during primer tests."""
36
38
@@ -43,48 +45,34 @@ class PackageToLint:
43
45
directories : list [str ]
44
46
"""Directories within the repository to run pylint over."""
45
47
46
- commit : str | None
48
+ commit : str | None = None
47
49
"""Commit hash to pin the repository on."""
48
50
49
- pylint_additional_args : list [str ]
51
+ pylint_additional_args : list [str ] = field ( default_factory = list )
50
52
"""Arguments to give to pylint."""
51
53
52
- pylintrc_relpath : str | None
54
+ pylintrc_relpath : str | None = None
53
55
"""Path relative to project's main directory to the pylintrc if it exists."""
54
56
55
- minimum_python : str | None
57
+ minimum_python : str | None = None
56
58
"""Minimum python version supported by the package."""
57
59
58
- def __init__ (
59
- self ,
60
- url : str ,
61
- branch : str ,
62
- directories : list [str ],
63
- commit : str | None = None ,
64
- pylint_additional_args : list [str ] | None = None ,
65
- pylintrc_relpath : str | None = None ,
66
- minimum_python : str | None = None ,
67
- ) -> None :
68
- self .url = url
69
- self .branch = branch
70
- self .directories = directories
71
- self .commit = commit
72
- self .pylint_additional_args = pylint_additional_args or []
73
- self .pylintrc_relpath = pylintrc_relpath
74
- self .minimum_python = minimum_python
75
-
76
60
@property
77
61
def pylintrc (self ) -> Path | Literal ["" ]:
78
62
if self .pylintrc_relpath is None :
79
63
# Fall back to "" to ensure pylint's own pylintrc is not discovered
80
64
return ""
81
65
return self .clone_directory / self .pylintrc_relpath
82
66
67
+ @property
68
+ def clone_name (self ) -> str :
69
+ """Extract repository name from URL."""
70
+ return "/" .join (self .url .split ("/" )[- 2 :]).replace (".git" , "" )
71
+
83
72
@property
84
73
def clone_directory (self ) -> Path :
85
74
"""Directory to clone repository into."""
86
- clone_name = "/" .join (self .url .split ("/" )[- 2 :]).replace (".git" , "" )
87
- return PRIMER_DIRECTORY_PATH / clone_name
75
+ return PRIMER_DIRECTORY_PATH / self .clone_name
88
76
89
77
@property
90
78
def paths_to_lint (self ) -> list [str ]:
0 commit comments