@@ -341,47 +341,6 @@ def create_mirror_package(source_dir: str, package_mapping: dict[str, str]) -> N
341
341
342
342
343
343
class AssistantCLI :
344
- @staticmethod
345
- def requirements_prune_pkgs (packages : Sequence [str ], req_files : Sequence [str ] = REQUIREMENT_FILES_ALL ) -> None :
346
- """Remove some packages from given requirement files."""
347
- if isinstance (req_files , str ):
348
- req_files = [req_files ]
349
- for req in req_files :
350
- AssistantCLI ._prune_packages (req , packages )
351
-
352
- @staticmethod
353
- def _prune_packages (req_file : str , packages : Sequence [str ]) -> None :
354
- """Remove some packages from given requirement files."""
355
- path = Path (req_file )
356
- assert path .exists ()
357
- text = path .read_text ()
358
- lines = text .splitlines ()
359
- final = []
360
- for line in lines :
361
- ln_ = line .strip ()
362
- if not ln_ or ln_ .startswith ("#" ):
363
- final .append (line )
364
- continue
365
- req = list (_parse_requirements ([ln_ ]))[0 ]
366
- if req .name not in packages :
367
- final .append (line )
368
- print (final )
369
- path .write_text ("\n " .join (final ) + "\n " )
370
-
371
- @staticmethod
372
- def _replace_min (fname : str ) -> None :
373
- with open (fname , encoding = "utf-8" ) as fopen :
374
- req = fopen .read ().replace (">=" , "==" )
375
- with open (fname , "w" , encoding = "utf-8" ) as fwrite :
376
- fwrite .write (req )
377
-
378
- @staticmethod
379
- def replace_oldest_ver (requirement_fnames : Sequence [str ] = REQUIREMENT_FILES_ALL ) -> None :
380
- """Replace the min package version by fixed one."""
381
- for fname in requirement_fnames :
382
- print (fname )
383
- AssistantCLI ._replace_min (fname )
384
-
385
344
@staticmethod
386
345
def copy_replace_imports (
387
346
source_dir : str ,
@@ -500,6 +459,25 @@ def generate_docker_tags(
500
459
tags = [f"{ docker_project } :{ tag } " for tag in tags ]
501
460
print ("," .join (tags ))
502
461
462
+ @staticmethod
463
+ def prune_pytest_as_errors (
464
+ pyproject_toml : str = "pyproject.toml" , errors : tuple = ("FutureWarning" , "DeprecationWarning" )
465
+ ) -> None :
466
+ """Prune pytest warnings as errors from the pyproject.toml file."""
467
+ import tomlkit
468
+
469
+ with open (pyproject_toml , encoding = "utf-8" ) as fopen :
470
+ content = fopen .read ()
471
+ pyproject = tomlkit .parse (content )
472
+ filterwarnings = pyproject .get ("tool" , {}).get ("pytest" , {}).get ("ini_options" , {}).get ("filterwarnings" , [])
473
+ if not filterwarnings :
474
+ return
475
+ filterwarnings = [wrn for wrn in filterwarnings if not any (f"error::{ err } " in wrn for err in errors )]
476
+ pyproject ["tool" ]["pytest" ]["ini_options" ]["filterwarnings" ] = filterwarnings
477
+
478
+ with open (pyproject_toml , "w" , encoding = "utf-8" ) as fopen :
479
+ fopen .write (tomlkit .dumps (pyproject ))
480
+
503
481
504
482
if __name__ == "__main__" :
505
483
import jsonargparse
0 commit comments