Skip to content
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

Merged
merged 32 commits into from
Dec 25, 2024

Conversation

kael-k
Copy link
Contributor

@kael-k kael-k commented Nov 1, 2024

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:

  • add "photo" field in CV model
    • Absolute paths
    • Relative paths
  • adding photo in moderncv template as suggested in another thread Answer an FAQ: Can I add a profile picture? #74 (comment)
  • adding photo in sb2nov template
    • check that the latex code I copypasted and adapted 2 month ago from SO doesn't go bananas with margin changes
  • adding photo in the markdown template
  • adding photo in the classic template
  • adding photo in the engineeringresumes template
  • fix tests

@kael-k kael-k marked this pull request as draft November 1, 2024 18:26
rendercv/renderer/templater.py Outdated Show resolved Hide resolved
Comment on lines 421 to 441
@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()

Copy link
Contributor Author

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.

Copy link
Collaborator

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

https://github.com/sinaatalay/rendercv/blob/9cbff56057ac552dc15ec0e1160c2a740921096a/rendercv/cli/commands.py#L196

then, the problem will be resolved and the path will always be relative to the input file path's directory.

Copy link
Contributor Author

@kael-k kael-k Nov 1, 2024

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).

Copy link
Contributor Author

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).

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@sinaatalay
Copy link
Collaborator

Thank you very much! I will review it when it's done.

kael-k pushed a commit to kael-k/rendercv that referenced this pull request Nov 2, 2024
@kael-k
Copy link
Contributor Author

kael-k commented Nov 5, 2024

tl;DR: \usepackage{graphicx} and design.font: "Source Sans 3" in the resume's yaml file do not work together with tinytex, I don't know why.

I implemented the propic for all templates, however, I am facing a strange error with the classic template:
the changes I've made are the same for classic, engineeringresume and sb2nov:

  1. added \usepackage{graphicx} % for includegraphics to include profile picture line in Preamble.j2.tex to be able to use \includegraphics command
  2. changed Header.j2.tex to add the profile picture if available

While engineeringresume and sb2nov work correctly, classic does not render correctly and gives me this error in the log file:

[...]
LaTeX Font Info:    ... okay on input line 172.

*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
*geometry* verbose mode - [ preamble ] result:
* driver: pdftex
* paper: letterpaper
* layout: <same size as paper>
* layoutoffset:(h,v)=(0.0pt,0.0pt)
* modes: 
* h-part:(L,W,R)=(56.9055pt, 500.484pt, 56.9055pt)
* v-part:(T,H,B)=(56.9055pt, 681.15898pt, 56.9055pt)
* \paperwidth=614.295pt
* \paperheight=794.96999pt
* \textwidth=500.484pt
* \textheight=681.15898pt
* \oddsidemargin=-15.36449pt
* \evensidemargin=-15.36449pt
* \topmargin=-52.36449pt
* \headheight=12.0pt
* \headsep=25.0pt
* \topskip=0.0pt
* \footskip=28.45274pt
* \marginparwidth=65.0pt
* \marginparsep=11.0pt
* \columnsep=4.26773pt
* \skip\footins=9.0pt plus 4.0pt minus 2.0pt
* \hoffset=0.0pt
* \voffset=0.0pt
* \mag=1000
* \@twocolumnfalse
* \@twosidefalse
* \@mparswitchfalse
* \@reversemarginfalse
* (1in=72.27pt=25.4mm, 1cm=28.453pt)


(/Users/kael-k/Documents/rendercv/rendercv/renderer/tinytex-release/TinyTeX/tex
mf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
Package: epstopdf-base 2020-01-24 v2.11 Base part for package epstopdf


! LaTeX Error: File `grfext.sty' not found.

I tested it both on a macbook air m3 and on a x64 arch linux machine with the same result.
It seems that the error is not because of the changes in Header.j2.tex, as if I revert the file and try to render the template with only \usepackage{graphicx} I get the same error, which is kinda strange since it works on the other 2 templates. Furthermore, I ran the following tests:

  • I tried to render the classic template with the --use-local-latex-command option and it rendered the resume with the propic successfully
  • I tried to take my CV repo, write the template override for the classic template with hardcoded path for the image and it rendered the resume with the propic successfully
    • I also tried to rebase my PR on v1.14 (the one I was using in my repo) and then tried to render the resume with the \usepackage{graphicx} only, it didn't work

After smashing my head against the PC for 2 hours this is what I got:

  • the problem is that the condition in rendercv/rendercv/renderer/tinytex-release/TinyTeX/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty:151 seems to be false for classic and true for sb2nov and engineeringresumes, which means that in classic template, tinytex tries to execute L179 \RequirePackage{grfext}\relax, which fails.
  • The test on my resume with the template override seems to work because the condition on epstopdf-base.sty:151 is false. With that information and some random tests I got that the problem/conflict is caused by the "font part" in Preamble.j2.tex: with design.font: Latin Modern Sans Serif in the yaml, the template renders correctly. The problem seems to be with Source Sans 3: by setting it manualy in the YAML with sb2nov and engineeringresumes, you'll get the same error.

@sinaatalay do you have any guesses as to why this happens?

kael-k pushed a commit to kael-k/rendercv that referenced this pull request Nov 7, 2024
@kael-k
Copy link
Contributor Author

kael-k commented Nov 7, 2024

I've found a workaround that I implemented in a5a43bd, I have no idea why it works, but it works

kael-k pushed a commit to kael-k/rendercv that referenced this pull request Nov 7, 2024
…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)
kael-k pushed a commit to kael-k/rendercv that referenced this pull request Nov 7, 2024
kael-k pushed a commit to kael-k/rendercv that referenced this pull request Nov 7, 2024
kael-k pushed a commit to kael-k/rendercv that referenced this pull request Nov 7, 2024
…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)
@kael-k kael-k force-pushed the feat/add-propic-support branch from bbe0ed2 to b0d03f0 Compare November 7, 2024 22:14
@kael-k kael-k marked this pull request as ready for review November 10, 2024 22:32
@kael-k kael-k requested a review from sinaatalay November 10, 2024 22:32
@sinaatalay
Copy link
Collaborator

sinaatalay commented Nov 17, 2024

Hello @kael-k, can I push some commits before merging this?

@kael-k
Copy link
Contributor Author

kael-k commented Nov 18, 2024

Hello @kael-k, can I push some commits before merging this?

Sure

kael-k pushed a commit to kael-k/rendercv that referenced this pull request Nov 30, 2024
kael-k pushed a commit to kael-k/rendercv that referenced this pull request Nov 30, 2024
…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)
@kael-k kael-k force-pushed the feat/add-propic-support branch from 13742de to c27d8a5 Compare November 30, 2024 16:48
@mekantor
Copy link

mekantor commented Dec 5, 2024

I've found a workaround that I implemented in a5a43bd, I have no idea why it works, but it works

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.

@kael-k
Copy link
Contributor Author

kael-k commented Dec 5, 2024

I've found a workaround that I implemented in a5a43bd, I have no idea why it works, but it works

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 graphicx before \usepackage[default, type1]{sourcesanspro} triggers the import of that grfext.sty (because, always iirc, graphicx set some flags that triggers that import in sourcesanspro). The workaround is basically to import graphicx AFTER setting the font.

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 fix,template: found a workaround for sourcesanspro and graphicx (which after the last rebase is 960c9d9)

@sinaatalay sinaatalay self-assigned this Dec 9, 2024
@mekantor mekantor mentioned this pull request Dec 16, 2024
@sinaatalay sinaatalay force-pushed the feat/add-propic-support branch from 60f424c to c27d8a5 Compare December 24, 2024 04:46
kael-k added 18 commits December 23, 2024 23:46
* 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)
@sinaatalay sinaatalay force-pushed the feat/add-propic-support branch from c27d8a5 to 14095af Compare December 24, 2024 04:50
@sinaatalay
Copy link
Collaborator

Thank you for your contribution.

@sinaatalay sinaatalay merged commit 733f4d2 into rendercv:main Dec 25, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to add a profile photo
3 participants