mirror of
https://github.com/rendercv/rendercv.git
synced 2026-05-24 16:48:55 -04:00
reader: sort imports
This commit is contained in:
@@ -12,30 +12,29 @@ The validators and data format of RenderCV are written using
|
||||
"""
|
||||
|
||||
from .models import (
|
||||
CurriculumVitae,
|
||||
SocialNetwork,
|
||||
available_theme_options,
|
||||
BulletEntry,
|
||||
CurriculumVitae,
|
||||
EducationEntry,
|
||||
Entry,
|
||||
ExperienceEntry,
|
||||
LocaleCatalog,
|
||||
NormalEntry,
|
||||
OneLineEntry,
|
||||
PublicationEntry,
|
||||
LocaleCatalog,
|
||||
RenderCVDataModel,
|
||||
SocialNetwork,
|
||||
available_theme_options,
|
||||
format_date,
|
||||
)
|
||||
|
||||
from .reader import (
|
||||
create_a_sample_data_model,
|
||||
create_a_sample_yaml_input_file,
|
||||
generate_json_schema_file,
|
||||
generate_json_schema,
|
||||
set_or_update_a_value,
|
||||
generate_json_schema_file,
|
||||
read_input_file,
|
||||
set_or_update_a_value,
|
||||
)
|
||||
|
||||
|
||||
__all__ = [
|
||||
"OneLineEntry",
|
||||
"BulletEntry",
|
||||
@@ -56,4 +55,5 @@ __all__ = [
|
||||
"set_or_update_a_value",
|
||||
"read_input_file",
|
||||
"format_date",
|
||||
"Entry",
|
||||
]
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
from .computers import format_date
|
||||
from .curriculum_vitae import CurriculumVitae, SocialNetwork
|
||||
from .design import available_theme_options
|
||||
from .entry_types import (
|
||||
BulletEntry,
|
||||
EducationEntry,
|
||||
Entry,
|
||||
ExperienceEntry,
|
||||
NormalEntry,
|
||||
OneLineEntry,
|
||||
@@ -10,8 +12,6 @@ from .entry_types import (
|
||||
)
|
||||
from .locale_catalog import LocaleCatalog
|
||||
from .rendercv_data_model import RenderCVDataModel
|
||||
from .computers import format_date
|
||||
|
||||
|
||||
__all__ = [
|
||||
"OneLineEntry",
|
||||
@@ -26,4 +26,5 @@ __all__ = [
|
||||
"RenderCVDataModel",
|
||||
"available_theme_options",
|
||||
"format_date",
|
||||
"Entry"
|
||||
]
|
||||
|
||||
10
rendercv/reader/models/base.py
Normal file
10
rendercv/reader/models/base.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import pydantic
|
||||
|
||||
|
||||
class RenderCVBaseModel(pydantic.BaseModel):
|
||||
"""This class is the parent class of all the data models in RenderCV. It has only
|
||||
one difference from the default `pydantic.BaseModel`: It raises an error if an
|
||||
unknown key is provided in the input file.
|
||||
"""
|
||||
|
||||
model_config = pydantic.ConfigDict(extra="forbid")
|
||||
@@ -5,9 +5,9 @@ calculate the time span between two dates, the date string, the URL of a social
|
||||
etc.
|
||||
"""
|
||||
|
||||
import re
|
||||
from datetime import date as Date
|
||||
from typing import Optional
|
||||
import re
|
||||
|
||||
from .locale_catalog import locale_catalog
|
||||
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
from typing import Annotated, Any, Optional, get_args
|
||||
import functools
|
||||
import re
|
||||
from typing import Annotated, Any, Literal, Optional, Type, get_args
|
||||
|
||||
import pydantic
|
||||
import functools
|
||||
|
||||
from . import entry_types
|
||||
from . import computers as cf
|
||||
|
||||
from typing import Type, Literal
|
||||
import re
|
||||
|
||||
import pydantic_extra_types.phone_numbers as pydantic_phone_numbers
|
||||
|
||||
from . import utilities as util
|
||||
from . import entry_validators
|
||||
from . import computers as computers
|
||||
from . import entry_types
|
||||
from .base import RenderCVBaseModel
|
||||
|
||||
# ======================================================================================
|
||||
# Create validator functions: ==========================================================
|
||||
# ======================================================================================
|
||||
|
||||
|
||||
class SectionBase(entry_types.RenderCVBaseModel):
|
||||
class SectionBase(RenderCVBaseModel):
|
||||
"""This class is the parent class of all the section types. It is being used
|
||||
in RenderCV internally, and it is not meant to be used directly by the users.
|
||||
It is used by `rendercv.data_models.utilities.create_a_section_model` function to
|
||||
@@ -296,7 +291,7 @@ available_social_networks = get_args(SocialNetworkName)
|
||||
# ======================================================================================
|
||||
|
||||
|
||||
class SocialNetwork(entry_types.RenderCVBaseModel):
|
||||
class SocialNetwork(RenderCVBaseModel):
|
||||
"""This class is the data model of a social network."""
|
||||
|
||||
network: SocialNetworkName = pydantic.Field(
|
||||
@@ -339,10 +334,10 @@ class SocialNetwork(entry_types.RenderCVBaseModel):
|
||||
"""Return the URL of the social network and cache `url` as an attribute of the
|
||||
instance.
|
||||
"""
|
||||
return cf.compute_social_network_url(self.network, self.username)
|
||||
return computers.compute_social_network_url(self.network, self.username)
|
||||
|
||||
|
||||
class CurriculumVitae(entry_validators.RenderCVBaseModel):
|
||||
class CurriculumVitae(RenderCVBaseModel):
|
||||
"""This class is the data model of the `cv` field."""
|
||||
|
||||
name: Optional[str] = pydantic.Field(
|
||||
@@ -394,7 +389,7 @@ class CurriculumVitae(entry_validators.RenderCVBaseModel):
|
||||
"""Return all the connections of the person as a list of dictionaries and cache
|
||||
`connections` as an attribute of the instance.
|
||||
"""
|
||||
connections = cf.compute_connections(self)
|
||||
connections = computers.compute_connections(self)
|
||||
|
||||
return connections
|
||||
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import importlib
|
||||
import importlib.util
|
||||
import pathlib
|
||||
from typing import Annotated, Any, Type
|
||||
|
||||
import pydantic
|
||||
@@ -6,14 +9,8 @@ from ...themes.classic import ClassicThemeOptions
|
||||
from ...themes.engineeringresumes import EngineeringresumesThemeOptions
|
||||
from ...themes.moderncv import ModerncvThemeOptions
|
||||
from ...themes.sb2nov import Sb2novThemeOptions
|
||||
|
||||
|
||||
import pathlib
|
||||
import importlib
|
||||
import importlib.util
|
||||
|
||||
from . import entry_types
|
||||
|
||||
from .base import RenderCVBaseModel
|
||||
|
||||
# ======================================================================================
|
||||
# Create validator functions: ==========================================================
|
||||
@@ -127,7 +124,7 @@ def validate_design_options(
|
||||
else:
|
||||
# Then it means there is no __init__.py file in the custom theme folder.
|
||||
# Create a dummy data model and use that instead.
|
||||
class ThemeOptionsAreNotProvided(entry_types.RenderCVBaseModel):
|
||||
class ThemeOptionsAreNotProvided(RenderCVBaseModel):
|
||||
theme: str = theme_name
|
||||
|
||||
theme_data_model = ThemeOptionsAreNotProvided(theme=theme_name)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
from typing import Annotated, Literal, Optional
|
||||
import pydantic
|
||||
import functools
|
||||
import re
|
||||
from datetime import date as Date
|
||||
from .. import utilities as util
|
||||
from . import computers as cf
|
||||
from typing import Annotated, Literal, Optional
|
||||
|
||||
import pydantic
|
||||
|
||||
from . import computers
|
||||
from .base import RenderCVBaseModel
|
||||
|
||||
# ======================================================================================
|
||||
# Create validator functions: ==========================================================
|
||||
@@ -27,7 +28,7 @@ def validate_date_field(date: Optional[int | str]) -> Optional[int | str]:
|
||||
if re.fullmatch(r"\d{4}-\d{2}(-\d{2})?", date):
|
||||
# Then it is in YYYY-MM-DD or YYYY-MMY format
|
||||
# Check if it is a valid date:
|
||||
util.get_date_object(date)
|
||||
computers.get_date_object(date)
|
||||
elif re.fullmatch(r"\d{4}", date):
|
||||
# Then it is in YYYY format, so, convert it to an integer:
|
||||
|
||||
@@ -64,7 +65,7 @@ def validate_start_and_end_date_fields(
|
||||
|
||||
elif date != "present":
|
||||
# Validate the date:
|
||||
util.get_date_object(date)
|
||||
computers.get_date_object(date)
|
||||
|
||||
return date
|
||||
|
||||
@@ -98,14 +99,14 @@ def validate_and_adjust_dates_for_an_entry(
|
||||
start_date = None
|
||||
end_date = None
|
||||
elif start_date_is_provided:
|
||||
start_date = util.get_date_object(start_date)
|
||||
start_date = computers.get_date_object(start_date)
|
||||
if not end_date_is_provided:
|
||||
# If only start_date is provided, assume it is an ongoing event, i.e.,
|
||||
# the end_date is present:
|
||||
end_date = "present"
|
||||
|
||||
if end_date != "present":
|
||||
end_date = util.get_date_object(end_date)
|
||||
end_date = computers.get_date_object(end_date)
|
||||
|
||||
if start_date > end_date:
|
||||
raise ValueError(
|
||||
@@ -159,16 +160,6 @@ EndDate = Annotated[
|
||||
# Create the entry models: =============================================================
|
||||
# ======================================================================================
|
||||
|
||||
|
||||
class RenderCVBaseModel(pydantic.BaseModel):
|
||||
"""This class is the parent class of all the data models in RenderCV. It has only
|
||||
one difference from the default `pydantic.BaseModel`: It raises an error if an
|
||||
unknown key is provided in the input file.
|
||||
"""
|
||||
|
||||
model_config = pydantic.ConfigDict(extra="forbid")
|
||||
|
||||
|
||||
class OneLineEntry(RenderCVBaseModel):
|
||||
"""This class is the data model of `OneLineEntry`."""
|
||||
|
||||
@@ -211,7 +202,9 @@ class EntryWithDate(RenderCVBaseModel):
|
||||
"""Return a date string based on the `date` field and cache `date_string` as
|
||||
an attribute of the instance.
|
||||
"""
|
||||
return cf.compute_date_string(start_date=None, end_date=None, date=self.date)
|
||||
return computers.compute_date_string(
|
||||
start_date=None, end_date=None, date=self.date
|
||||
)
|
||||
|
||||
|
||||
class PublicationEntryBase(RenderCVBaseModel):
|
||||
@@ -272,7 +265,7 @@ class PublicationEntryBase(RenderCVBaseModel):
|
||||
url_is_provided = self.url is not None
|
||||
|
||||
if url_is_provided:
|
||||
return util.make_a_url_clean(self.url)
|
||||
return computers.make_a_url_clean(self.url)
|
||||
else:
|
||||
return ""
|
||||
|
||||
@@ -347,7 +340,7 @@ class EntryBase(EntryWithDate):
|
||||
returns
|
||||
`#!python "Nov 2020 to Apr 2021"`
|
||||
"""
|
||||
return cf.compute_date_string(
|
||||
return computers.compute_date_string(
|
||||
start_date=self.start_date, end_date=self.end_date, date=self.date
|
||||
)
|
||||
|
||||
@@ -364,7 +357,7 @@ class EntryBase(EntryWithDate):
|
||||
returns
|
||||
`#!python "2020 to 2021"`
|
||||
"""
|
||||
return cf.compute_date_string(
|
||||
return computers.compute_date_string(
|
||||
start_date=self.start_date,
|
||||
end_date=self.end_date,
|
||||
date=self.date,
|
||||
@@ -376,7 +369,7 @@ class EntryBase(EntryWithDate):
|
||||
"""Return a time span string based on the `date`, `start_date`, and `end_date`
|
||||
fields and cache `time_span_string` as an attribute of the instance.
|
||||
"""
|
||||
return cf.compute_time_span_string(
|
||||
return computers.compute_time_span_string(
|
||||
start_date=self.start_date, end_date=self.end_date, date=self.date
|
||||
)
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ from typing import Annotated, Optional
|
||||
import annotated_types as at
|
||||
import pydantic
|
||||
|
||||
from . import entry_types
|
||||
from .base import RenderCVBaseModel
|
||||
|
||||
|
||||
class LocaleCatalog(entry_types.RenderCVBaseModel):
|
||||
class LocaleCatalog(RenderCVBaseModel):
|
||||
"""This class is the data model of the locale catalog. The values of each field
|
||||
updates the `locale_catalog` dictionary.
|
||||
"""
|
||||
|
||||
@@ -8,18 +8,17 @@ from typing import Optional
|
||||
|
||||
import pydantic
|
||||
|
||||
from . import entry_types
|
||||
from ...themes.classic import ClassicThemeOptions
|
||||
|
||||
from .design import RenderCVDesign
|
||||
from .curriculum_vitae import CurriculumVitae
|
||||
from .locale_catalog import LocaleCatalog
|
||||
|
||||
# Disable Pydantic warnings:
|
||||
# warnings.filterwarnings("ignore")
|
||||
from .base import RenderCVBaseModel
|
||||
from .curriculum_vitae import CurriculumVitae
|
||||
from .design import RenderCVDesign
|
||||
from .locale_catalog import LocaleCatalog
|
||||
|
||||
|
||||
class RenderCVDataModel(entry_types.RenderCVBaseModel):
|
||||
class RenderCVDataModel(RenderCVBaseModel):
|
||||
"""This class binds both the CV and the design information together."""
|
||||
|
||||
cv: CurriculumVitae = pydantic.Field(
|
||||
|
||||
@@ -4,12 +4,12 @@ generate a sample YAML input file and the JSON schema of RenderCV based on the d
|
||||
models defined in `rendercv.data_models.models`.
|
||||
"""
|
||||
|
||||
import io
|
||||
import json
|
||||
import pathlib
|
||||
from typing import Any, Optional
|
||||
import io
|
||||
import pydantic
|
||||
|
||||
import pydantic
|
||||
import ruamel.yaml
|
||||
|
||||
from . import models
|
||||
|
||||
Reference in New Issue
Block a user