55from __future__ import annotations
66
77import logging
8+ from dataclasses import dataclass , field
89from pathlib import Path
910from typing import Literal
1011
1819class DirtyPrimerDirectoryException (Exception ):
1920 """We can't pull if there's local changes."""
2021
21- def __init__ (self , path : Path | str ):
22+ def __init__ (self , path : Path | str ) -> None :
2223 super ().__init__ (
2324 rf"""
2425
@@ -31,6 +32,7 @@ def __init__(self, path: Path | str):
3132 )
3233
3334
35+ @dataclass (frozen = True )
3436class PackageToLint :
3537 """Represents data about a package to be tested during primer tests."""
3638
@@ -43,48 +45,34 @@ class PackageToLint:
4345 directories : list [str ]
4446 """Directories within the repository to run pylint over."""
4547
46- commit : str | None
48+ commit : str | None = None
4749 """Commit hash to pin the repository on."""
4850
49- pylint_additional_args : list [str ]
51+ pylint_additional_args : list [str ] = field ( default_factory = list )
5052 """Arguments to give to pylint."""
5153
52- pylintrc_relpath : str | None
54+ pylintrc_relpath : str | None = None
5355 """Path relative to project's main directory to the pylintrc if it exists."""
5456
55- minimum_python : str | None
57+ minimum_python : str | None = None
5658 """Minimum python version supported by the package."""
5759
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-
7660 @property
7761 def pylintrc (self ) -> Path | Literal ["" ]:
7862 if self .pylintrc_relpath is None :
7963 # Fall back to "" to ensure pylint's own pylintrc is not discovered
8064 return ""
8165 return self .clone_directory / self .pylintrc_relpath
8266
67+ @property
68+ def clone_name (self ) -> str :
69+ """Extract repository name from URL."""
70+ return "/" .join (self .url .split ("/" )[- 2 :]).replace (".git" , "" )
71+
8372 @property
8473 def clone_directory (self ) -> Path :
8574 """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
8876
8977 @property
9078 def paths_to_lint (self ) -> list [str ]:
0 commit comments