-
-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support for profile photo #193
Conversation
@pydantic.field_validator("photo") | ||
@classmethod | ||
def photo_path(cls, value: str | Path, info: pydantic.ValidationInfo) -> Path: | ||
"""Cast `photo` to Path and make the path absolute""" | ||
path = Path(value) | ||
return path.absolute() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this snippet I compute the absolute path of the image. This resolve the problem that relatives path references should change in the j2 template compilation context.
However there is still a problem: relative path is always relative to the cwd, this is the expected behaviour when the parameter is passed by args (ex: --cv.photo=propic.jpg) but I don't think is the correct one if the path is specified in the yaml, because the path should be relative to the yaml and not to the cwd. I think this problem cannot be solved in this PR, as the code merge together YAML and args data before passing it to the pydantic model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line below
https://github.com/sinaatalay/rendercv/blob/9cbff56057ac552dc15ec0e1160c2a740921096a/rendercv/cli/commands.py#L212
changes the current working directory to the parent of the input file. If we move that line above the line below
then, the problem will be resolved and the path will always be relative to the input file path's directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using os.chdir to change the relative point solve the problem of the relative reference from the YAML but then you have that from the CLI --cv.photo would be relative to the YAML file and not to the cwd (which I think it might be misleading).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only quick solution I see is to explicit the arg "--cv.photo" and, if passed, compute the absolute path from the cwd (idk how typer works, I generally use click, tomorrow I'll take a look to the docs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point, but I think it's still fine because we clearly define what that option does, which is overriding the YAML file. So users should expect that --cv.photo PATH
is equivalent to writing
cv:
photo: PATH
which will be equivalent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, during next days I'll proceed as you suggested. Thank you for the feedback.
Thank you very much! I will review it when it's done. |
tl;DR: I implemented the propic for all templates, however, I am facing a strange error with the
While
I tested it both on a macbook air m3 and on a x64 arch linux machine with the same result.
After smashing my head against the PC for 2 hours this is what I got:
@sinaatalay do you have any guesses as to why this happens? |
I've found a workaround that I implemented in a5a43bd, I have no idea why it works, but it works |
…g to pydantic models this is required because the "os.chdir" solution (rendercv#193 (comment)) solved the path resolution for the image but bugged the path construction for paths in rendercv_settings (which should be relative to cwd and not to the path of the input file)
…g to pydantic models this is required because the "os.chdir" solution (rendercv#193 (comment)) solved the path resolution for the image but bugged the path construction for paths in rendercv_settings (which should be relative to cwd and not to the path of the input file)
bbe0ed2
to
b0d03f0
Compare
Hello @kael-k, can I push some commits before merging this? |
Sure |
…g to pydantic models this is required because the "os.chdir" solution (rendercv#193 (comment)) solved the path resolution for the image but bugged the path construction for paths in rendercv_settings (which should be relative to cwd and not to the path of the input file)
13742de
to
c27d8a5
Compare
I was trying to add graphics (company logo/favicon) and ran into the same problems. What change was this? I can't find it, but I'm glad I wasn't the only one with the issue. |
@mekantor iirc the problem was that the import EDIT: idk why but the commit hash is not available after the rebase I made some days ago, however you can find it by searching the commit with message |
60f424c
to
c27d8a5
Compare
* relative paths are always relative to cwd
…g to pydantic models this is required because the "os.chdir" solution (rendercv#193 (comment)) solved the path resolution for the image but bugged the path construction for paths in rendercv_settings (which should be relative to cwd and not to the path of the input file)
…d_copy_theme_files tests
c27d8a5
to
14095af
Compare
remove RenderCVContextModel resolve typing and INPUT_FILE_PATH issue update Preambles update templates rebase tests fix issues update headers
Thank you for your contribution. |
This PR
Aim to fix #28 by adding the support for the profile picture in a systematic way.
The pull request proposes the following changes:
moderncv
template as suggested in another thread Answer an FAQ: Can I add a profile picture? #74 (comment)sb2nov
templatemarkdown
templateclassic
templateengineeringresumes
template