Giter VIP home page Giter VIP logo

Comments (13)

mikepqr avatar mikepqr commented on August 14, 2024 1

See #11 and especially #8 for why I switched away from WeasyPrint.

I don't have access to Windows, but this "Error" is actually a harmless warning (i.e. the resume.pdf file is successfully built) on Windows in Github Actions: https://github.com/mikepqr/resume.md/runs/2901233186?check_suite_focus=true.

I believe it can be eliminated by upgrading to a more recent version of Python (e.g. 3.8, 3.9 or 3.10).

Given it is harmless then I'd be glad to take a PR that hides it on 3.7, but I don't want to revert to WeasyPrint just to get rid of it.

But like I said, I don't have access to Windows to test anything, so please let me know if any of the above is wrong (e.g. it's not harmless, it's not fixed by upgrading Python to 3.8+).

from resume.md.

mikepqr avatar mikepqr commented on August 14, 2024 1

According to https://bugs.python.org/issue26660, the snippet at https://docs.python.org/3/library/shutil.html?highlight=shutil#rmtree-example might help. I'd probably need to add that here

shutil.rmtree(tmpdir.name)
. I'll get around to this eventually, but I'Il gladly take a PR (especially from someone who can reproduce the error locally).

from resume.md.

mikepqr avatar mikepqr commented on August 14, 2024 1

OK, sounds promising! Also sounds like it might break macOS and Linux, so I will be sure to run rests on the PR 😄

from resume.md.

amandal1810 avatar amandal1810 commented on August 14, 2024

Can confirm that i am seeing a similar error

from resume.md.

amandal1810 avatar amandal1810 commented on August 14, 2024

I tried using weasyprint instead of headless chrome and pdf generation works fine. Is there any reason why we cannot use weasyprint?
I also tried pdfkit but it has been updated in a while.

from resume.md.

amandal1810 avatar amandal1810 commented on August 14, 2024

Thanks for all the details @mikepqr . I'll try to make this change.
Please note that i am on Python 3.9.6 and i am still seeing the error :)

from resume.md.

amandal1810 avatar amandal1810 commented on August 14, 2024

Also, there are problems with WeasyPrint. :)
As already mentioned in an issue here, the most annoying thing about WeasyPrint is probably the installation process. Its quite convoluted. And then the output is also not satisfactory. I was trying to achieve a LaTeX look - the html looks fine but the pdf looks all weird.
So i agree, its probably best to stick with headless chrome.

from resume.md.

amandal1810 avatar amandal1810 commented on August 14, 2024

Do note that, for me, it does not write the resume.pdf file.
This is the output i see:

PS C:\work\code\resume.md> python resume.py
Wrote resume.html
Found Chrome or Chromium at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
Traceback (most recent call last):
  File "C:\work\code\resume.md\resume.py", line 210, in <module>
    write_pdf(html, prefix=prefix, chrome=args.chrome_path)
  File "C:\work\code\resume.md\resume.py", line 139, in write_pdf
    subprocess.run(
  File "C:\Python39\lib\subprocess.py", line 507, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "C:\Python39\lib\subprocess.py", line 1126, in communicate
    self.wait()
  File "C:\Python39\lib\subprocess.py", line 1189, in wait
    return self._wait(timeout=timeout)
  File "C:\Python39\lib\subprocess.py", line 1470, in _wait
    result = _winapi.WaitForSingleObject(self._handle,
KeyboardInterrupt

from resume.md.

amandal1810 avatar amandal1810 commented on August 14, 2024

OK. So i added the --repl flag while calling chrome.exe in subprocess.run() and now we can see the real reason for the failure:
Note that although it says Wrote resume.pdf, the file was not created.

C:\work\code\resume.md [main ≡ +4 ~4 -1 !]> python resume.py
Wrote resume.html
Found Chrome or Chromium at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
>>>
Wrote resume.pdf
Could not delete C:\Users\abmandal\AppData\Local\Temp\resume.md_iv3sprky
[WinError 5] Access is denied: 'C:\\Users\\abmandal\\AppData\\Local\\Temp\\resume.md_iv3sprky\\CrashpadMetrics-active.pma'
Exception ignored in: <finalize object at 0x1e6aa6d0700; dead>
Traceback (most recent call last):
  File "C:\Python39\lib\weakref.py", line 580, in __call__
    return info.func(*info.args, **(info.kwargs or {}))
  File "C:\Python39\lib\tempfile.py", line 816, in _cleanup
    cls._rmtree(name)
  File "C:\Python39\lib\tempfile.py", line 812, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "C:\Python39\lib\shutil.py", line 740, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Python39\lib\shutil.py", line 618, in _rmtree_unsafe
    onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Python39\lib\tempfile.py", line 804, in onerror
    cls._rmtree(path)
  File "C:\Python39\lib\tempfile.py", line 812, in _rmtree
    _shutil.rmtree(name, onerror=onerror)
  File "C:\Python39\lib\shutil.py", line 740, in rmtree
    return _rmtree_unsafe(path, onerror)
  File "C:\Python39\lib\shutil.py", line 599, in _rmtree_unsafe
    onerror(os.scandir, path, sys.exc_info())
  File "C:\Python39\lib\shutil.py", line 596, in _rmtree_unsafe
    with os.scandir(path) as scandir_it:
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\Users\\abmandal\\AppData\\Local\\Temp\\resume.md_iv3sprky\\CrashpadMetrics-active.pma'

from resume.md.

mikepqr avatar mikepqr commented on August 14, 2024

No idea, I'm afraid. The error should be harmless to our goals (I think it's Chrome's own telemetry/logging tempfile/cleanup failing) but it raises which causes resume.py to receive the exception. You could try catching NotADirectoryError just before here

except subprocess.CalledProcessError as exc:
.

from resume.md.

amandal1810 avatar amandal1810 commented on August 14, 2024

OK. So i re-approached the problem from a different angle, and it works 😀

  • I have gotten rid of the temporary directory thingy altogether.
  • I have created a separate function for writing pdf for win32
  • i cannot pass the entire html in base64 encoded format via the command line. I get a command too long error. So i must first create the html file and then create the pdf file from the html file.
  • As a result, the args are not respected. IMHO, this is okay for now because the tool actually works now for win32 users 🤣
  • So in philosophy, I am simply trying to run the below PowerShell command from Python:
    & 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' --headless --disable-gpu --run-all-compositor-stages-before-draw --print-to-pdf-no-header --virtual-time-budget=5000 --no-margins --print-to-pdf=C:\work\code\resume.md\resume.pdf C:\work\code\resume.md\resume.html

I will raise a PR tomorrow as its quite late here 😄

from resume.md.

amandal1810 avatar amandal1810 commented on August 14, 2024

OK, sounds promising! Also sounds like it might break macOS and Linux, so I will be sure to run rests on the PR 😄

I think it will not break for macOS and Linux because there are two separate functions now - one for win32 and another for macOS/Linux. But yes, you must test it, especially because I have not.

from resume.md.

akaihola avatar akaihola commented on August 14, 2024

For anyone else having this issue, you can find a recipe for a work-around in:

from resume.md.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.