Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG Copy Binder logo to avoid Window drive rel path error #745

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

Merged
merged 25 commits into from
Sep 9, 2020

Conversation

lucyleeow
Copy link
Contributor

Fixes #744

Copy Binder logo from package _static folder to target_dir/images.

@larsoner happy to explore another solution.

Test: would changing appveyor setup such that _static is in a different drive be a good test? I am not so familiar with appveyor but if I add a cd D: here:

test_script:
- python setup.py develop

would that work?

@lucyleeow lucyleeow added the bug label Sep 5, 2020
@larsoner
Copy link
Contributor

larsoner commented Sep 6, 2020

I suspect you shouldn't need to manually copy any static file, just link to it properly. The question is how to do that. Usually / hopefully you can do it by doing a relpath between the example file and the src_dir or so (?), or maybe get the static path from Sphinx. I can dig into it Tuesday if we can wait that long

@lucyleeow
Copy link
Contributor Author

lucyleeow commented Sep 6, 2020

The problem is that relative paths between 2 different drives on Windows doesn't exist. It may be possible with symbolic links but we might not want to mess with that.

(I think I tried using a static path but it didn't work - though I didn't look into this too closely)

No hurry, take a look on Tuesday.

@codecov
Copy link

codecov bot commented Sep 6, 2020

Codecov Report

Merging #745 into master will increase coverage by 0.00%.
The diff coverage is 97.29%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #745   +/-   ##
=======================================
  Coverage   97.50%   97.51%           
=======================================
  Files          32       32           
  Lines        3727     3741   +14     
=======================================
+ Hits         3634     3648   +14     
  Misses         93       93           
Impacted Files Coverage Δ
sphinx_gallery/tests/test_gen_rst.py 99.71% <ø> (ø)
sphinx_gallery/tests/test_notebook.py 100.00% <ø> (ø)
sphinx_gallery/tests/test_full.py 99.57% <92.30%> (-0.21%) ⬇️
sphinx_gallery/binder.py 96.11% <100.00%> (+0.97%) ⬆️
sphinx_gallery/gen_gallery.py 94.90% <100.00%> (+0.01%) ⬆️
sphinx_gallery/tests/test_binder.py 98.85% <100.00%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 839c02b...3518ece. Read the comment docs.

@larsoner
Copy link
Contributor

larsoner commented Sep 8, 2020

@lucyleeow pushed a commit. The critical point is that, regardless of what html_static_paths users enter, they always end up in _static/. So we just need to link directly to OUT_DIR/_static/image.svg. See if it makes sense and if so, feel free to merge and cut a 0.8.1

@lucyleeow
Copy link
Contributor Author

I think I've just missed something important. So all files in the package _static dir (i.e. <where you installed SG>/sphinx-gallery/sphinx_gallery/_static) are always copied over to the built html (e.g., <where your package is>/doc/_build/html/_static/)?

Can you show me where this is done in the code?

@larsoner
Copy link
Contributor

larsoner commented Sep 8, 2020

Can you show me where this is done in the code?

It's done by sphinx itself somewhere (feel free to dig through their code to figure this out). If you look at tinybuild I modified it to use html_static_paths = ['_static_nonstandard'], but when you make html, the static files from that dir and from glr_path_static (because we add it to the static paths) get copied to OUT_DIR/_static. AFAIK this is a hard-coded output path

@lucyleeow
Copy link
Contributor Author

Thanks, I had no idea Sphinx did this but it makes sense.

@larsoner
Copy link
Contributor

larsoner commented Sep 8, 2020

Feel free to fix the path error in CIs, or I can push a fix in a couple of hours. Have meetings now

@larsoner
Copy link
Contributor

larsoner commented Sep 8, 2020

Actually I think that all of those build warnings are bogus, they say files don't exist but it renders fine:

https://1811-25860190-gh.circle-artifacts.com/0/rtd_html/auto_examples/plot_0_sin.html#sphx-glr-auto-examples-plot-0-sin-py

I'm not sure how to avoid this warning. Maybe worth asking on the Sphinx listserv or GitHub. But we do need to make these warnings go away somehow because this will cause -nW builds fail. :(

@larsoner
Copy link
Contributor

larsoner commented Sep 8, 2020

This might also be relevant

#120

And maybe

https://stackoverflow.com/questions/52138336/sphinx-reference-to-an-image-from-different-locations#answer-52141199

@lucyleeow
Copy link
Contributor Author

I'll do this tomorrow

@larsoner
Copy link
Contributor

larsoner commented Sep 8, 2020

Actually I wonder if the correct fix is to give the path to the sphx_glr_static() without any relpath business. Sphinx in theory should recognize that this is a path to a static file and substitute OUT_DIR/static. I'll give it a shot...

@larsoner
Copy link
Contributor

larsoner commented Sep 9, 2020

Okay @lucyleeow I ended up giving up on the static idea and ended up with something that I think is pretty close to what you had. Can you take a look and merge if you're happy?

os.path.dirname(fpath), 'images', 'binder_badge_logo.svg')
os.makedirs(os.path.dirname(physical_path), exist_ok=True)
if not os.path.isfile(physical_path):
shutil.copyfile(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for the test test_gen_binder_rst we shouldn't copy the file over

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, isfile is better than os.path.exists that I used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try some tmpdir gymnastics...

@lucyleeow
Copy link
Contributor Author

Sorry can you clarify what glr_path_static returns? Is it the packaged _static, where the package files are or the path to the the _static folder where the built html files are?

@@ -115,9 +116,10 @@ def apptmp():
assert url == expected


def test_gen_binder_rst():
def test_gen_binder_rst(tmpdir):
"""Check binder rst generated correctly."""
gallery_conf_base = {'gallery_dirs': None, 'src_dir': 'blahblah'}
Copy link
Contributor Author

@lucyleeow lucyleeow Sep 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set 'gallery_dirs': None to avoid copying files over when testing (with my poor implementation), but we can change this back to what it was before

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a commit to be more like how it should in actually building

@larsoner
Copy link
Contributor

larsoner commented Sep 9, 2020

glr_path_static is the path to sphinx-gallery's sphinx_gallery/_static folder. The contents will be copied to OUT_DIR/_static on build. The problem is that we can't actually use it (see code comments)

@lucyleeow
Copy link
Contributor Author

Okay thanks. But in Windows, if the path has to be relative to the build root, and the build root is in a different drive to glr_path_static, I thought there was not relative path between different drives?
Sorry maybe I missed something?

@larsoner
Copy link
Contributor

larsoner commented Sep 9, 2020

Sorry maybe I missed something?

relpath is no longer used

@@ -445,7 +444,8 @@ def test_rebuild(tmpdir_factory, sphinx_app):
new_app.build(False, [])
status = new_app._status.getvalue()
lines = [line for line in status.split('\n') if '0 removed' in line]
assert re.match('.*[0|1] added, [1-9] changed, 0 removed$.*',
# XXX on AppVeyor this can be 13
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What can be 13?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number of changed files in the regex below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. DI]id this change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did in previous runs because I added binder to the tinybuild conf. Not sure if it's still there or not but I'm okay living with it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I forgot binder changed. Can we change to:
assert re.match('.*[0|1] added, [1-9][0-3]? changed, 0 removed$.*',

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, feel free to push. You could even make the [1-9][0-3]? only if on windows and use [1-9] otherwise

@lucyleeow lucyleeow merged commit 7bac6f5 into sphinx-gallery:master Sep 9, 2020
@lucyleeow lucyleeow deleted the IS/744 branch September 9, 2020 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG Windows relative path error with _static Binder logo
2 participants