-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert requirementslib to pydantic (#368)
* Convert requirementslib to pydantic * Should never import setuptools, causes bad side effects. * Fix import * Remove tests of removed functions. * Fix import * Fix import * Fix import * Fix to use isinstance * Fix import * Fix import * Remove test that tests removed method * Remove tests of removed methods. * fix test * Remove tests of removed methods. * Remove tests of removed methods. * Fix python markers. * Revert "Remove tests of removed methods." This reverts commit 73fb203. * fix tests * Update test case to avoid antiquated package. * Check pt tests * Fix edge case of VCS requirements and expected resulting dictionary. * Fix more tests * more test fixes * down to 6 failing tests * down to 5 failing tests * Fix tests, down to 4 failing * Fix tests, down to 3 failing * Do not force parse of ireq when it may not be parsable. * latest changes that work for both pipenv and requirementslib. * latest changes that work for both pipenv and requirementslib. * remove test that is problematic in github acttions. * remove test that is problematic in github acttions. * Apply fix to failing test. * PR feedback * Remove unused type imports --------- Co-authored-by: Oz Tiram <oz.tiram@gmail.com>
- Loading branch information
Showing
24 changed files
with
1,674 additions
and
3,765 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Any, Dict | ||
|
||
from pydantic import BaseModel, Extra | ||
|
||
|
||
class ReqLibBaseModel(BaseModel): | ||
def __setattr__(self, name, value): # noqa: C901 (ignore complexity) | ||
private_attributes = { | ||
field_name | ||
for field_name in self.__annotations__ | ||
if field_name.startswith("_") | ||
} | ||
|
||
if name in private_attributes or name in self.__fields__: | ||
return object.__setattr__(self, name, value) | ||
|
||
if self.__config__.extra is not Extra.allow and name not in self.__fields__: | ||
raise ValueError(f'"{self.__class__.__name__}" object has no field "{name}"') | ||
|
||
object.__setattr__(self, name, value) | ||
|
||
def dict(self, *args, **kwargs) -> Dict[str, Any]: | ||
"""The requirementslib classes make use of a lot of private attributes | ||
which do not get serialized out to the dict by default in pydantic.""" | ||
model_dict = super().dict(*args, **kwargs) | ||
private_attrs = {k: v for k, v in self.__dict__.items() if k.startswith("_")} | ||
model_dict.update(private_attrs) | ||
return model_dict |
Oops, something went wrong.