mirror of
https://github.com/rendercv/rendercv.git
synced 2026-05-24 16:48:55 -04:00
data: finalize refactoring
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
The `rendercv.data_models` package contains the necessary classes and functions for
|
||||
The `rendercv.data` package contains the necessary classes and functions for
|
||||
|
||||
- Parsing and validating a YAML input file
|
||||
- Computing some properties based on a YAML input file (like converting ISO dates to
|
||||
@@ -11,6 +11,12 @@ The validators and data format of RenderCV are written using
|
||||
[Pydantic](https://github.com/pydantic/pydantic).
|
||||
"""
|
||||
|
||||
from .generator import (
|
||||
create_a_sample_data_model,
|
||||
create_a_sample_yaml_input_file,
|
||||
generate_json_schema,
|
||||
generate_json_schema_file,
|
||||
)
|
||||
from .models import (
|
||||
BulletEntry,
|
||||
CurriculumVitae,
|
||||
@@ -23,18 +29,11 @@ from .models import (
|
||||
PublicationEntry,
|
||||
RenderCVDataModel,
|
||||
SocialNetwork,
|
||||
available_social_networks,
|
||||
available_theme_options,
|
||||
format_date,
|
||||
available_social_networks,
|
||||
)
|
||||
from .reader import (
|
||||
create_a_sample_data_model,
|
||||
create_a_sample_yaml_input_file,
|
||||
generate_json_schema,
|
||||
generate_json_schema_file,
|
||||
read_input_file,
|
||||
set_or_update_a_value,
|
||||
)
|
||||
from .reader import read_input_file
|
||||
|
||||
__all__ = [
|
||||
"OneLineEntry",
|
||||
@@ -53,7 +52,6 @@ __all__ = [
|
||||
"create_a_sample_yaml_input_file",
|
||||
"generate_json_schema_file",
|
||||
"generate_json_schema",
|
||||
"set_or_update_a_value",
|
||||
"read_input_file",
|
||||
"format_date",
|
||||
"Entry",
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
The `rendercv.data.generators` module contains all the functions for generating the JSON
|
||||
Schema of the input data format and a sample YAML input file.
|
||||
"""
|
||||
|
||||
import io
|
||||
import json
|
||||
import pathlib
|
||||
@@ -6,7 +11,7 @@ from typing import Any, Optional
|
||||
import pydantic
|
||||
import ruamel.yaml
|
||||
|
||||
from . import models
|
||||
from . import models, reader
|
||||
|
||||
|
||||
def dictionary_to_yaml(dictionary: dict[str, Any]):
|
||||
@@ -47,7 +52,7 @@ def create_a_sample_data_model(
|
||||
|
||||
# read the sample_content.yaml file
|
||||
sample_content = pathlib.Path(__file__).parent / "sample_content.yaml"
|
||||
sample_content_dictionary = read_a_yaml_file(sample_content)
|
||||
sample_content_dictionary = reader.read_a_yaml_file(sample_content)
|
||||
cv = models.CurriculumVitae(**sample_content_dictionary)
|
||||
|
||||
# Update the name:
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
"""
|
||||
The `rendercv.data.models` package contains all the Pydantic data models, validators,
|
||||
and computed fields that are used in RenderCV. The package is divided into several
|
||||
modules, each containing a different group of data models.
|
||||
|
||||
- `base.py`: Contains `RenderCVBaseModel`, which is the parent class of all the data
|
||||
models in RenderCV.
|
||||
- `computers.py`: Contains all the functions that are used to compute some values of
|
||||
the fields in the data models. For example, converting ISO dates to human-readable
|
||||
dates.
|
||||
- `entry_types.py`: Contains all the data models that are used to represent the entries
|
||||
in the CV.
|
||||
- `curriculum_vitae.py`: Contains the `CurriculumVitae` data model, which is the main
|
||||
data model that contains all the content of the CV.
|
||||
- `design.py`: Contains the data model that is used to represent the design options of
|
||||
the CV.
|
||||
- `locale_catalog.py`: Contains the data model that is used to represent the locale
|
||||
catalog of the CV.
|
||||
- `rendercv_data_model.py`: Contains the `RenderCVDataModel` data model, which is the
|
||||
main data model that defines the whole input file structure.
|
||||
"""
|
||||
|
||||
from .computers import format_date
|
||||
from .curriculum_vitae import CurriculumVitae, SocialNetwork, available_social_networks
|
||||
from .design import available_theme_options
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
The `rendercv.data.models.base` module contains the `RenderCVBaseModel` class, which is
|
||||
the parent class of all the data models in RenderCV.
|
||||
"""
|
||||
|
||||
import pydantic
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
"""
|
||||
The `rendercv.data_models.computed_fields` module contains functions that compute
|
||||
some properties based on the input data. For example, it includes functions that
|
||||
calculate the time span between two dates, the date string, the URL of a social network,
|
||||
etc.
|
||||
The `rendercv.data.models.computers` module contains functions that compute some
|
||||
properties based on the input data. For example, it includes functions that calculate
|
||||
the time span between two dates, the date string, the URL of a social network, etc.
|
||||
"""
|
||||
|
||||
import re
|
||||
from datetime import date as Date
|
||||
from typing import Optional
|
||||
|
||||
from .curriculum_vitae import CurriculumVitae
|
||||
from .locale_catalog import locale_catalog
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ def compute_social_network_url(network: str, username: str):
|
||||
return url
|
||||
|
||||
|
||||
def compute_connections(cv) -> list[dict[str, str]]:
|
||||
def compute_connections(cv: "CurriculumVitae") -> list[dict[str, str]]:
|
||||
"""Bring together all the connections in the CV, such as social networks, phone
|
||||
number, email, etc and return them as a list of dictionaries. Each dictionary
|
||||
contains the following keys: "latex_icon", "url", "clean_url", and "placeholder."
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
The `rendercv.data.models.curriculum_vitae` module contains the data model of the `cv`
|
||||
field of the input file.
|
||||
"""
|
||||
|
||||
import functools
|
||||
import re
|
||||
from typing import Annotated, Any, Literal, Optional, Type, get_args
|
||||
@@ -5,8 +10,7 @@ from typing import Annotated, Any, Literal, Optional, Type, get_args
|
||||
import pydantic
|
||||
import pydantic_extra_types.phone_numbers as pydantic_phone_numbers
|
||||
|
||||
from . import computers as computers
|
||||
from . import entry_types
|
||||
from . import computers, entry_types
|
||||
from .base import RenderCVBaseModel
|
||||
|
||||
# ======================================================================================
|
||||
@@ -411,7 +415,7 @@ class CurriculumVitae(RenderCVBaseModel):
|
||||
|
||||
if self.sections_input is not None:
|
||||
for title, entries in self.sections_input.items():
|
||||
title = util.dictionary_key_to_proper_section_title(title)
|
||||
title = computers.dictionary_key_to_proper_section_title(title)
|
||||
|
||||
# The first entry can be used because all the entries in the section are
|
||||
# already validated with the `validate_a_section` function:
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
The `rendercv.data.models.design` module contains the data model of the `design` field
|
||||
of the input file.
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import importlib.util
|
||||
import pathlib
|
||||
@@ -5,10 +10,10 @@ from typing import Annotated, Any, Type
|
||||
|
||||
import pydantic
|
||||
|
||||
from ...themes.classic import ClassicThemeOptions
|
||||
from ...themes.engineeringresumes import EngineeringresumesThemeOptions
|
||||
from ...themes.moderncv import ModerncvThemeOptions
|
||||
from ...themes.sb2nov import Sb2novThemeOptions
|
||||
from ...renderer.themes.classic import ClassicThemeOptions
|
||||
from ...renderer.themes.engineeringresumes import EngineeringresumesThemeOptions
|
||||
from ...renderer.themes.moderncv import ModerncvThemeOptions
|
||||
from ...renderer.themes.sb2nov import Sb2novThemeOptions
|
||||
from . import entry_types
|
||||
from .base import RenderCVBaseModel
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
`rendercv.models.data.entry_types` module contains the data models of all the available
|
||||
entry types in RenderCV.
|
||||
"""
|
||||
|
||||
import functools
|
||||
import re
|
||||
from datetime import date as Date
|
||||
@@ -160,6 +165,7 @@ EndDate = Annotated[
|
||||
# Create the entry models: =============================================================
|
||||
# ======================================================================================
|
||||
|
||||
|
||||
class OneLineEntry(RenderCVBaseModel):
|
||||
"""This class is the data model of `OneLineEntry`."""
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
`rendercv.models.locale_catalog` module contains the data model of the `locale_catalog`
|
||||
field of the input file.
|
||||
"""
|
||||
|
||||
from typing import Annotated, Optional
|
||||
|
||||
import annotated_types as at
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
"""
|
||||
The `rendercv.data_models.models` module contains all the Pydantic data models used in
|
||||
RenderCV. These data models define the data format and the usage of computed fields and
|
||||
the validators.
|
||||
The `rendercv.data.models.rendercv_data_model` module contains the `RenderCVDataModel`
|
||||
data model, which is the main data model that defines the whole input file structure.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
import pydantic
|
||||
|
||||
from ...themes.classic import ClassicThemeOptions
|
||||
from ...renderer.themes.classic import ClassicThemeOptions
|
||||
|
||||
# Disable Pydantic warnings:
|
||||
# warnings.filterwarnings("ignore")
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
"""
|
||||
The `rendercv.data_models.generators` module contains the functions that are used to
|
||||
generate a sample YAML input file and the JSON schema of RenderCV based on the data
|
||||
models defined in `rendercv.data_models.models`.
|
||||
The `rendercv.data.reader` module contains the functions that are used to read the input
|
||||
file (YAML or JSON) and return them as an instance of `RenderCVDataModel`, which is a
|
||||
Pydantic data model of RenderCV's data format.
|
||||
"""
|
||||
|
||||
import io
|
||||
import json
|
||||
import pathlib
|
||||
from typing import Any, Optional
|
||||
from typing import Any
|
||||
|
||||
import pydantic
|
||||
import ruamel.yaml
|
||||
|
||||
from . import models
|
||||
|
||||
Reference in New Issue
Block a user