Skip to content

Commit

Permalink
move whoop_pydantic_v2 dir out a level
Browse files Browse the repository at this point in the history
  • Loading branch information
JTunis committed Jul 21, 2024
1 parent c53adc7 commit 3267fd6
Show file tree
Hide file tree
Showing 198 changed files with 1,766 additions and 1,765 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ repos:
- id: usage_docs
name: Usage docs links
entry: pdm run ./tests/check_usage_docs.py
files: '^pydantic/'
files: '^whoop_pydantic_v2/'
types: [python]
language: system
- id: typecheck
name: Typecheck
entry: pdm run pyright pydantic
entry: pdm run pyright whoop_pydantic_v2
types: [python]
language: node
pass_filenames: false
Expand Down
11 changes: 6 additions & 5 deletions docs/concepts/dataclasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class File:


class Foo(BaseModel):
# Required so that pydantic revalidates the model attributes
# Required so that whoop_pydantic_v2 revalidates the model attributes
model_config = ConfigDict(revalidate_instances='always')

file: File
Expand Down Expand Up @@ -309,7 +309,7 @@ In this case you can simply add `arbitrary_types_allowed` in the config!
import dataclasses

from pydantic import BaseModel, ConfigDict
from whoop_pydantic_v2.pydantic.errors import PydanticSchemaGenerationError
from whoop_pydantic_v2.whoop_pydantic_v2.errors import PydanticSchemaGenerationError


class ArbitraryType:
Expand All @@ -335,12 +335,13 @@ try:
dc: DC
other: str

# invalid as it is now a pydantic dataclass

# invalid as it is now a whoop_pydantic_v2 dataclass
Model(dc=my_dc, other='other')
except PydanticSchemaGenerationError as e:
print(e.message)
"""
Unable to generate pydantic-core schema for <class '__main__.ArbitraryType'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
Unable to generate whoop_pydantic_v2-core schema for <class '__main__.ArbitraryType'>. Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
If you got this error by calling handler(<some type>) within `__get_pydantic_core_schema__` then you likely need to call `handler.generate_schema(<some type>)` since we do not call `__get_pydantic_core_schema__` on `<some type>` otherwise to avoid infinite recursion.
"""
Expand All @@ -355,7 +356,7 @@ class Model(BaseModel):

m = Model(dc=my_dc, other='other')
print(repr(m))
#> Model(dc=DC(a=ArbitraryType(value=3), b='qwe'), other='other')
# > Model(dc=DC(a=ArbitraryType(value=3), b='qwe'), other='other')
```

### Checking if a dataclass is a pydantic dataclass
Expand Down
24 changes: 12 additions & 12 deletions docs/concepts/serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,13 @@ class OuterModel(BaseModel):
user: User


user = UserLogin(name='pydantic', password='hunter2')
user = UserLogin(name='whoop_pydantic_v2', password='hunter2')

m = OuterModel(user=user)
print(m)
#> user=UserLogin(name='pydantic', password='hunter2')
#> user=UserLogin(name='whoop_pydantic_v2', password='hunter2')
print(m.model_dump()) # note: the password field is not included
#> {'user': {'name': 'pydantic'}}
#> {'user': {'name': 'whoop_pydantic_v2'}}
```
!!! warning "Migration Warning"
This behavior is different from how things worked in Pydantic V1, where we would always include
Expand Down Expand Up @@ -470,13 +470,13 @@ class OuterModel(BaseModel):
as_user: User


user = UserLogin(name='pydantic', password='password')
user = UserLogin(name='whoop_pydantic_v2', password='password')

print(OuterModel(as_any=user, as_user=user).model_dump())
"""
{
'as_any': {'name': 'pydantic', 'password': 'password'},
'as_user': {'name': 'pydantic'},
'as_any': {'name': 'whoop_pydantic_v2', 'password': 'password'},
'as_user': {'name': 'whoop_pydantic_v2'},
}
"""
```
Expand Down Expand Up @@ -524,19 +524,19 @@ class OuterModel(BaseModel):
user2: User


user = UserLogin(name='pydantic', password='password')
user = UserLogin(name='whoop_pydantic_v2', password='password')

outer_model = OuterModel(user1=user, user2=user)
print(outer_model.model_dump(serialize_as_any=True)) # (1)!
"""
{
'user1': {'name': 'pydantic', 'password': 'password'},
'user2': {'name': 'pydantic', 'password': 'password'},
'user1': {'name': 'whoop_pydantic_v2', 'password': 'password'},
'user2': {'name': 'whoop_pydantic_v2', 'password': 'password'},
}
"""

print(outer_model.model_dump(serialize_as_any=False)) # (2)!
#> {'user1': {'name': 'pydantic'}, 'user2': {'name': 'pydantic'}}
#> {'user1': {'name': 'whoop_pydantic_v2'}, 'user2': {'name': 'whoop_pydantic_v2'}}
```

1. With `serialize_as_any` set to `True`, the result matches that of V1.
Expand Down Expand Up @@ -566,7 +566,7 @@ class OuterModel(BaseModel):

user = UserLogin(
name='samuel',
password='pydantic-pw',
password='whoop_pydantic_v2-pw',
friends=[UserLogin(name='sebastian', password='fastapi-pw', friends=[])],
)

Expand All @@ -578,7 +578,7 @@ print(OuterModel(user=user).model_dump(serialize_as_any=True)) # (1)!
'friends': [
{'name': 'sebastian', 'friends': [], 'password': 'fastapi-pw'}
],
'password': 'pydantic-pw',
'password': 'whoop_pydantic_v2-pw',
}
}
"""
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ from pydantic import (
ItemType = TypeVar('ItemType')


# This is not a pydantic model, it's an arbitrary generic class
# This is not a whoop_pydantic_v2 model, it's an arbitrary generic class
@dataclass
class Owner(Generic[ItemType]):
name: str
Expand Down
6 changes: 3 additions & 3 deletions docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ Fork the repository on GitHub and clone your fork locally.

```bash
# Clone your fork and cd into the repo directory
git clone [email protected]:<your username>/pydantic.git
cd pydantic
git clone [email protected]:<your username>/whoop_pydantic_v2.git
cd whoop_pydantic_v2

# Install PDM and pre-commit
# We use pipx here, for other options see:
Expand All @@ -74,7 +74,7 @@ cd pydantic
pipx install pdm
pipx install pre-commit

# Install pydantic, dependencies, test dependencies and doc dependencies
# Install whoop_pydantic_v2, dependencies, test dependencies and doc dependencies
make install
```

Expand Down
2 changes: 1 addition & 1 deletion docs/errors/usage_errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,7 @@ class Foo:


"""
pydantic.errors.PydanticUserError: Dataclass field bar has init=False and init_var=True, but these are mutually exclusive.
whoop_pydantic_v2.errors.PydanticUserError: Dataclass field bar has init=False and init_var=True, but these are mutually exclusive.
"""
```

Expand Down
2 changes: 1 addition & 1 deletion docs/extra/tweaks.css
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ aside.blog img {
--md-default-bg-color: hsla(230, 15%, 21%, 1);
}

/* Add customization for pydantic people page */
/* Add customization for whoop_pydantic_v2 people page */

.user-list {
display: flex;
Expand Down
10 changes: 5 additions & 5 deletions docs/install.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Installation is as simple as:

```bash
pip install pydantic
pip install whoop_pydantic_v2
```

Pydantic has a few dependencies:
Expand All @@ -16,7 +16,7 @@ Pydantic is also available on [conda](https://www.anaconda.com) under the [conda
channel:

```bash
conda install pydantic -c conda-forge
conda install whoop_pydantic_v2 -c conda-forge
```

## Optional dependencies
Expand All @@ -28,7 +28,7 @@ Pydantic has the following optional dependencies:
To install optional dependencies along with Pydantic:

```bash
pip install pydantic[email]
pip install whoop_pydantic_v2[email]
```

Of course, you can also install requirements manually with `pip install email-validator`.
Expand All @@ -38,7 +38,7 @@ Of course, you can also install requirements manually with `pip install email-va
And if you prefer to install Pydantic directly from the repository:

```bash
pip install git+https://github.com/pydantic/pydantic@main#egg=pydantic
pip install git+https://github.com/pydantic/pydantic@main#egg=whoop_pydantic_v2
# or with extras
pip install git+https://github.com/pydantic/pydantic@main#egg=pydantic[email]
pip install git+https://github.com/pydantic/pydantic@main#egg=whoop_pydantic_v2[email]
```
4 changes: 2 additions & 2 deletions docs/integrations/aws_lambda.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pip install \
--implementation cp \ # (3)!
--python-version 3.10 \ # (4)!
--only-binary=:all: \ # (5)!
--upgrade pydantic # (6)!
--upgrade whoop_pydantic_v2 # (6)!
```

1. Use the platform corresponding to your Lambda runtime.
Expand All @@ -55,7 +55,7 @@ error is a common issue that indicates you have installed `pydantic` incorrectly

```py test="skip" lint="skip"
from importlib.metadata import files
print([file for file in files('pydantic-core') if file.name.startswith('_pydantic_core')])
print([file for file in files('whoop_pydantic_v2-core') if file.name.startswith('_pydantic_core')])
"""
[PackagePath('pydantic_core/_pydantic_core.pyi'), PackagePath('pydantic_core/_pydantic_core.cpython-312-x86_64-linux-gnu.so')]
"""
Expand Down
2 changes: 1 addition & 1 deletion docs/integrations/linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ If using Flake8 in your project, a [plugin](https://pypi.org/project/flake8-pyda
and can be installed using the following:

```bash
pip install flake8-pydantic
pip install flake8-whoop_pydantic_v2
```

The lint errors provided by this plugin are namespaced under the `PYDXXX` code. To ignore some unwanted
Expand Down
4 changes: 2 additions & 2 deletions docs/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Pydantic V2 is now the current production release of Pydantic.
You can install Pydantic V2 from PyPI:

```bash
pip install -U pydantic
pip install -U whoop_pydantic_v2
```

If you encounter any issues, please [create an issue in GitHub](https://github.com/pydantic/pydantic/issues) using
Expand All @@ -30,7 +30,7 @@ migrate your code more quickly.
You can install the tool from PyPI:

```bash
pip install bump-pydantic
pip install bump-whoop_pydantic_v2
```

The usage is simple. If your project structure is:
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/griffe_doclinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def replace_links(m: re.Match, *, api_link: str) -> str:

def update_docstring(obj: GriffeObject) -> str:
return re.sub(
r'usage[\- ]docs: ?https://docs\.pydantic\.dev/.+?/(\S+)',
r'usage[\- ]docs: ?https://docs\.whoop_pydantic_v2\.dev/.+?/(\S+)',
partial(replace_links, api_link=obj.path),
obj.docstring.value,
flags=re.I,
Expand Down
14 changes: 7 additions & 7 deletions docs/plugins/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ def add_changelog() -> None:


def add_mkdocs_run_deps() -> None:
# set the pydantic, pydantic-core, pydantic-extra-types versions to configure for running examples in the browser
# set the whoop_pydantic_v2, whoop_pydantic_v2-core, whoop_pydantic_v2-extra-types versions to configure for running examples in the browser
pyproject_toml = (PROJECT_ROOT / 'pyproject.toml').read_text()
pydantic_core_version = re.search(r'pydantic-core==(.+?)["\']', pyproject_toml).group(1)
pydantic_core_version = re.search(r'whoop_pydantic_v2-core==(.+?)["\']', pyproject_toml).group(1)

version_py = (PROJECT_ROOT / 'pydantic' / 'version.py').read_text()
version_py = (PROJECT_ROOT / 'whoop_pydantic_v2' / 'version.py').read_text()
pydantic_version = re.search(r'^VERSION ?= (["\'])(.+)\1', version_py, flags=re.M).group(2)

pdm_lock = (PROJECT_ROOT / 'pdm.lock').read_text()
pydantic_extra_types_version = re.search(r'name = "pydantic-extra-types"\nversion = "(.+?)"', pdm_lock).group(1)
pydantic_extra_types_version = re.search(r'name = "whoop_pydantic_v2-extra-types"\nversion = "(.+?)"', pdm_lock).group(1)

mkdocs_run_deps = json.dumps(
[
f'pydantic=={pydantic_version}',
f'pydantic-core=={pydantic_core_version}',
f'pydantic-extra-types=={pydantic_extra_types_version}',
f'whoop_pydantic_v2=={pydantic_version}',
f'whoop_pydantic_v2-core=={pydantic_core_version}',
f'whoop_pydantic_v2-extra-types=={pydantic_extra_types_version}',
]
)
logger.info('Setting mkdocs_run_deps=%s', mkdocs_run_deps)
Expand Down
18 changes: 9 additions & 9 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ theme:
logo: 'logo-white.svg'
favicon: 'favicon.png'

repo_name: pydantic/pydantic
repo_name: whoop_pydantic_v2/whoop_pydantic_v2
repo_url: https://github.com/pydantic/pydantic
edit_uri: edit/main/docs/
extra:
Expand Down Expand Up @@ -187,7 +187,7 @@ markdown_extensions:
alternate_style: true

watch:
- pydantic
- whoop_pydantic_v2

plugins:
- mike:
Expand Down Expand Up @@ -235,18 +235,18 @@ plugins:
'usage/linting.md': 'integrations/linting.md'
'usage/types.md': 'concepts/types.md'
'usage/types/secrets.md': 'examples/secrets.md'
'usage/types/string_types.md': 'api/types.md#pydantic.types.StringConstraints'
'usage/types/file_types.md': 'api/types.md#pydantic.types.FilePath'
'usage/types/string_types.md': 'api/types.md#whoop_pydantic_v2.types.StringConstraints'
'usage/types/file_types.md': 'api/types.md#whoop_pydantic_v2.types.FilePath'
'api/main.md': 'api/base_model.md'
'api/color.md': 'api/pydantic_extra_types_color.md'
'api/alias_generators.md': 'api/config.md#pydantic.config.ConfigDict.alias_generator'
'api/alias_generators.md': 'api/config.md#whoop_pydantic_v2.config.ConfigDict.alias_generator'
'api/pydantic_core_init.md': 'api/pydantic_core.md'
'usage/types/booleans.md': 'api/standard_library_types.md#booleans'
'usage/types/callables.md': 'api/standard_library_types.md#callable'
'usage/types/custom.md': 'concepts/types.md#custom-types'
'usage/types/datetime.md': 'api/standard_library_types.md#datetime-types'
'usage/types/enum.md': 'api/standard_library_types.md#enum'
'usage/types/json.md': 'api/types.md#pydantic.types.Json'
'usage/types/json.md': 'api/types.md#whoop_pydantic_v2.types.Json'
'usage/types/list_types.md': 'api/standard_library_types.md#list'
'usage/types/standard_types.md': 'api/standard_library_types.md'
'usage/types/strict_types.md': 'concepts/types.md#strict-types'
Expand All @@ -266,7 +266,7 @@ plugins:
'usage/types/extra_types/routing_numbers.md': 'api/pydantic_extra_types_routing_numbers.md'
'version-compatibility.md': 'version-policy.md'
'api/pydantic_extra_types_routing_number.md': 'api/pydantic_extra_types_routing_numbers.md'
'usage/computed_fields.md': 'api/fields.md#pydantic.fields.computed_field'
'usage/computed_fields.md': 'api/fields.md#whoop_pydantic_v2.fields.computed_field'
'usage/conversion_table.md': 'concepts/conversion_table.md'
'usage/dataclasses.md': 'concepts/dataclasses.md'
'usage/fields.md': 'concepts/fields.md'
Expand All @@ -279,9 +279,9 @@ plugins:
'usage/type_adapter.md': 'concepts/type_adapter.md'
'usage/validation_decorator.md': 'concepts/validation_decorator.md'
'usage/validators.md': 'concepts/validators.md'
'usage/types/bytesize.md': 'api/types.md#pydantic.types.ByteSize'
'usage/types/bytesize.md': 'api/types.md#whoop_pydantic_v2.types.ByteSize'
'usage/types/dicts_mapping.md': 'api/standard_library_types.md#mapping-types'
'usage/types/encoded.md': 'api/types.md#pydantic.types.EncodedBytes'
'usage/types/encoded.md': 'api/types.md#whoop_pydantic_v2.types.EncodedBytes'
'usage/types/enums.md': 'api/standard_library_types.md#enum'
'usage/types/number_types.md': 'api/standard_library_types.md#number-types'
'usage/types/sequence_iterable.md': 'api/standard_library_types.md#other-iterables'
Expand Down
2 changes: 1 addition & 1 deletion release/make_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main():
if args.preview:
new_version = args.preview
else:
version_file = root_dir / 'pydantic' / 'version.py'
version_file = root_dir / 'whoop_pydantic_v2' / 'version.py'
new_version = re.search(r"VERSION = '(.*)'", version_file.read_text()).group(1)

history_path = root_dir / 'HISTORY.md'
Expand Down
Loading

0 comments on commit 3267fd6

Please sign in to comment.