EveryVoiceTTS / EveryVoice

The EveryVoice TTS Toolkit - Text To Speech for your language
https://docs.everyvoice.ca
Other
19 stars 2 forks source link

DirectoryPathMustExist and friends are not compatible with Pydantic 2.8.0 #498

Open joanise opened 3 months ago

joanise commented 3 months ago

In a fresh environment, where the default pydantic is now 2.8.0, we get 11 unit testing errors from test_configs.py and test_utils.py. If I force <2.8.0, the errors disappear. The result atm is that CI is broken.

Quick hack

I'm going to set pydantic[email]>=2.4.2,<2.8 in requirements.txt, so CI can pass again for now.

Steps to reproduce

./make-everyvoice-env -n EV-new
conda activate EV-new
pip install 'pydantic[email]==2.8.0'  # only required once I lock to <2.8
python -m unittest everyvoice.tests.test_utils everyvoice.tests.test_configs
# see 11 failures
pip install 'pydantic[email]<2.8.0'
rmdir test_using_a_directory_with_context/ logs_and_checkpoints/
python -m unittest everyvoice.tests.test_utils everyvoice.tests.test_configs
# see all tests pass

Desired fix

Make the code compatible with 2.8.0.

Full error log with 2.8.0

======================================================================
FAIL: test_using_a_directory_with_context (everyvoice.tests.test_utils.DirectoryPathMustExistTest)
Verifies that directory_path_must_exist(), when using a context,
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 232, in test_using_a_directory_with_context
    self.assertTrue((root_dir / directory).exists())
AssertionError: False is not true

======================================================================
FAIL: test_using_a_directory_with_context (everyvoice.tests.test_utils.PathIsADirectoryTest)
Verifies that PathIsADirectory detects that the argument is a directory
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 99, in test_using_a_directory_with_context
    PathIsADirectory(path=directory)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 72, in __init__
    __pydantic_self__.__pydantic_validator__.validate_python(
pydantic_core._pydantic_core.ValidationError: 1 validation error for PathIsADirectory
path
  Value error, hierarchy is not a directory [type=value_error, input_value=PosixPath('hierarchy'), input_type=PosixPath]
    For further information visit https://errors.pydantic.dev/2.8/v/value_error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 101, in test_using_a_directory_with_context
    self.fail("Failed to detect that the argument is a directory")
AssertionError: Failed to detect that the argument is a directory

======================================================================
FAIL: test_using_a_file_with_context (everyvoice.tests.test_utils.PathIsADirectoryTest)
Verifies that PathIsADirectory detects that the argument is a file when
----------------------------------------------------------------------
pydantic_core._pydantic_core.ValidationError: 1 validation error for PathIsADirectory
path
  Value error, test_utils.py is not a directory [type=value_error, input_value='test_utils.py', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/value_error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 109, in test_using_a_file_with_context
    with self.assertRaisesRegex(
AssertionError: "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py is not a directory" does not match "1 validation error for PathIsADirectory
path
  Value error, test_utils.py is not a directory [type=value_error, input_value='test_utils.py', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/value_error"

======================================================================
FAIL: test_with_context (everyvoice.tests.test_utils.RelativePathToAbsoluteTest)
When provided with a context, the path should be absolute.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 196, in test_with_context
    self.assertTrue(dir.path.is_absolute())
AssertionError: False is not true

======================================================================
FAIL: test_config_save_dirs (everyvoice.tests.test_configs.ConfigTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 101, in test_config_save_dirs
    self.assertTrue((tempdir / preprocessing_config.save_dir).exists())
AssertionError: False is not true

======================================================================
FAIL: test_absolute_path (everyvoice.tests.test_configs.LoadConfigTest)
Load a config that has absolute paths.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 538, in test_absolute_path
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : logs_and_checkpoints

======================================================================
FAIL: test_aligner_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a AlignerConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 385, in test_aligner_config
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../logs_and_checkpoints

======================================================================
FAIL: test_everyvoice_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a EveryVoiceConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 479, in test_everyvoice_config
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../logs_and_checkpoints

======================================================================
FAIL: test_feature_prediction_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a FeaturePredictionConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 427, in test_feature_prediction_config
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../logs_and_checkpoints

======================================================================
FAIL: test_preprocessing_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a PreprocessingConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 403, in test_preprocessing_config
    self.validate_config_path(config.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../preprocessed

======================================================================
FAIL: test_vocoder_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a VocoderConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 448, in test_vocoder_config
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../logs_and_checkpoints

----------------------------------------------------------------------
Ran 48 tests in 1.245s

FAILED (failures=11)
joanise commented 3 months ago

@SamuelLarkin not urgent, since #499 provides a work-around for now, but when you have time can you look at this?

joanise commented 3 weeks ago

@roedoejet I would bump this to milestone 1.0: we don't need to fix this until we want/need to upgrade to a newer Pydantic.

roedoejet commented 3 weeks ago

@roedoejet I would bump this to milestone 1.0: we don't need to fix this until we want/need to upgrade to a newer Pydantic.

good idea!