forked from langeland/sirius
-
Notifications
You must be signed in to change notification settings - Fork 19
Migrate from PhantomJS #8
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
Open
notjosh
wants to merge
10
commits into
nordprojects:main
Choose a base branch
from
notjosh:feature/no-more-phantomjs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ccb248a
Bump .gitignore
notjosh aa98fa4
Switched to headless Chromium from PhantomJS
notjosh 9d74a80
Docker knows how to run Chrome instead of Phantom
notjosh a2c123e
Matching fonts to match PhantomJS's DejaVu Sans usage
notjosh 636ded7
Let's get buildpacks working with Chrome/headless on Heroku
notjosh 83c8a7c
Maybe app.json replaces the .buildpacks in modern Heroku, let's find …
notjosh 6c79c1b
Oh, that's how buildpacks are named
notjosh f923357
Turns out chromedriver is on PATH on Heroku already, great!
notjosh aef831a
We should support emojis by default, so let's take the shortest path …
notjosh 59cc9b0
Merge remote-tracking branch 'origin/master' into feature/no-more-pha…
joerick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # Custom | ||
| .vscode/ | ||
| venv/ | ||
| .env | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| { | ||
| "name": "Sirius", | ||
| "description": "Sirius is a Little Printer server, give or take.", | ||
| "website": "https://littleprinter.nordprojects.co/", | ||
| "repository": "https://github.com/nordprojects/sirius", | ||
| "addons": [ | ||
| { | ||
| "plan": "heroku-postgresql", | ||
| "options": { | ||
| "version": "11.5" | ||
| } | ||
| } | ||
| ], | ||
| "image": "heroku/python", | ||
| "buildpacks": [ | ||
| { | ||
| "url": "heroku/google-chrome" | ||
| }, | ||
| { | ||
| "url": "heroku/chromedriver" | ||
| } | ||
| ], | ||
| "env": { | ||
| "FLASK_CONFIG": { | ||
| "description": "Deployment configuration", | ||
| "value": "heroku" | ||
| }, | ||
| "TWITTER_CONSUMER_KEY": { | ||
| "description": "Twitter app consumer key", | ||
| "required": true | ||
| }, | ||
| "TWITTER_CONSUMER_SECRET": { | ||
| "description": "Twitter app consumer secret", | ||
| "required": true | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,15 @@ | |
| from sirius.coding import image_encoding | ||
|
|
||
| class ImageCase(unittest.TestCase): | ||
| def test_empty_document(self): | ||
| data = image_encoding.html_to_png('') | ||
| image = Image.open(data) | ||
| self.assertEquals(image.size[0], 384) | ||
|
|
||
| def test_normal_text(self): | ||
| data = image_encoding.html_to_png( | ||
| '<html><body style="margin: 0px; height: 10px;"></body></html>' | ||
| ) | ||
| ) | ||
| image = Image.open(data) | ||
| self.assertEquals(image.size[0], 384) | ||
| self.assertEquals(image.size[1], 10) | ||
|
|
@@ -20,6 +25,13 @@ def test_normal_height(self): | |
| self.assertEquals(image.size[0], 384) | ||
| self.assertEquals(image.size[1], 100) | ||
|
|
||
| def test_probably_beyond_viewport_height(self): | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying to make sure that headless browsers can actually capture a full screenshot, and don't get limited to resizing to fit a virtual screen size (say, 1024x768) |
||
| data = image_encoding.html_to_png( | ||
| '<html><body style="margin: 0px; height: 10000px;"></body></html>') | ||
| image = Image.open(data) | ||
| self.assertEquals(image.size[0], 384) | ||
| self.assertEquals(image.size[1], 10000) | ||
|
|
||
|
|
||
| class PipeTestCase(unittest.TestCase): | ||
| def test_specific_image_rle(self): | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Don't need to keep this around, but it might be more stable than resizing the viewport? It does break if the height is 0 though, which is kind of undefined right now.
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.
Let's leave it commented there, I can imagine that it could come in handy if the window-resizing method has any issues.
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.
Just one thought I had - could CSS rules on the
htmlelement affect this? I'm guessing thatbody.parentNodeishtml... like margin/padding/border on thehtmlelement?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.
Good question! Part of me wonders if we should apply a global CSS reset here to counter against partial/incomplete HTML layouts (say, just
<p>hello world</p>) getting padding/margin added, but I can only imagine that going poorly when someone wants a specific layout.The whole HTML rendering is probably fairly fragile, and it's definitely undefined right now. I'm sure passing something simple in like
<meta name="viewport" content="width=device-width, initial-scale=2">breaks something we care about here.I was gonna add a bunch of tests that generate PNGs and compare against fixtures, but I'm wondering how fragile that'll be, i.e. different OS fonts will cause test failures. As long as they pass in Docker/on Circle, that's all that really matters I guess? But it'd be good to use it to define a basic spec of "enter this HTML, get this output", and keep it consistent regardless of our implementations here.
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 was wondering if just a HTML -> image height test would do the trick, although that might fall foul of the fragility problems you raise above re. fonts etc.
HTML passed to the print key API is in fact templated, so
<p>Hello, world!</p>would be placed within a HTML document with base styles etc. This is where the Timestamp/from header comes from.Regardless, we're talking about very edge-casey stuff here, so don't let it hold up your progress!
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.
Good point about the template! I'd forgotten about that.
I added #13 as a starting point to catch any of the main regressions here. The image height test is probably enough to 99% of issues, but having the image snapshots gives us a way to inspect/visualise the differences so I think has a fair bit of value.
So let's get #13 in, then get this PR green against those tests. Then let's merge it in and see how it goes.