Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[POC] image based search (GSOC)#28009

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
NirobNabil wants to merge4 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromNirobNabil:test_run
Draft
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
tidy up image_search ext
  • Loading branch information
@NirobNabil
NirobNabil committedApr 5, 2024
commit7952565ad97da7cb1dd1ce1a8ed1284d69199490
1 change: 1 addition & 0 deletions.gitignore
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -71,6 +71,7 @@ doc/gallery
doc/modules
doc/plot_types
doc/pyplots/tex_demo.png
doc/image_search
doc/tutorials
doc/users/explain
lib/dateutil
Expand Down
94 changes: 12 additions & 82 deletionsdoc/sphinxext/image_search.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,13 +9,6 @@
import pathlib
from xml.sax.saxutils import quoteattr, escape
from itertools import chain

import sphinx_gallery.gen_gallery as gen_gallery


from sphinx.util import logging as sphinx_logging


from collections import defaultdict
import json
import logging
Expand All@@ -24,6 +17,9 @@
from docutils.utils import get_source_line
from docutils import nodes

from sphinx.util import logging as sphinx_logging

from sphinx_gallery import gen_gallery
from sphinx_gallery.py_source_parser import split_code_and_text_blocks
from sphinx_gallery.gen_rst import extract_intro_and_title
from sphinx_gallery.backreferences import _thumbnail_div, THUMBNAIL_PARENT_DIV, THUMBNAIL_PARENT_DIV_CLOSE
Expand All@@ -32,74 +28,21 @@
logger = sphinx_logging.getLogger(__name__)


class ImageSearch():
def __init__(self, gallery_dir):
self.gallery_dir = gallery_dir
self.items = []

def add_item(self, src_path, taget_path, image_dir):
self.items.append((src_path, taget_path, image_dir))
logger.info("Image path")
logger.info(image_dir)
# self.items.extend(item_dirs)

def generate_files(self, src_dir):
# src_dir = gallery_conf["src_dir"]

include_path = os.path.join(self.gallery_dir, "%s.recommendationsssssss" % self.gallery_dir.split('/')[-1])
logger.info("Include Path")
logger.info(include_path)

logger.info("self items")
logger.info(self.items)

with open(include_path, "w", encoding="utf-8") as ex_file:
heading = "More related examples"
ex_file.write("\n\n" + heading + "\n")
ex_file.write("^" * len(heading) + "\n")
ex_file.write(THUMBNAIL_PARENT_DIV)
for src_path, taget_path, image_dir in self.items:
rec_path, rec_name = taget_path.rsplit("/", maxsplit=1)

_, script = split_code_and_text_blocks(taget_path)
intro, title = extract_intro_and_title(taget_path, script[0][1])

logger.info("rec_path")
logger.info(rec_path)
logger.info("rec_path")
logger.info(rec_name)
logger.info("src_dir")
logger.info(src_dir)

ex_file.write(
_thumbnail_div(
rec_path,
src_dir,
rec_name,
intro,
title,
is_backref=True,
)
)
ex_file.write(THUMBNAIL_PARENT_DIV_CLOSE)
# def fit(self):



def generate_search_page(app):
"""
fetches all generated example images and adds links to them
in image_search/index.recommendations file
"""

gallery_conf = app.config.sphinx_gallery_conf

workdirs = gen_gallery._prepare_sphx_glr_dirs(gallery_conf,
app.builder.srcdir)

# Check for duplicate filenames to make sure linking works as expected
examples_dirs = [ex_dir for ex_dir, _ in workdirs]

# imageSearch = ImageSearch()

src_dir = app.builder.srcdir
heading = "Searchresults"
heading = "ImageSearchpage"

image_search_path = os.path.join(src_dir, "image_search")

Expand All@@ -126,7 +69,6 @@ def generate_search_page(app):
examples_dir_abs_path, gallery_conf,
check_for_index=True)

all_py_examples = []
directory_explore = [gallery_dir_abs_path] + subsecs
# logger.info("directory_explore")
# logger.info(directory_explore)
Expand All@@ -153,12 +95,7 @@ def generate_search_page(app):
example_image_path = os.path.join(os.path.join(src_dir, "images"), f"sphx_glr_{example_name}_001.png")

if os.path.isfile(example_image_path):
# imageSearch.add_item(example_image_path)
# logger.info("OK")

# logger.info(example_image_path)
# logger.info(example)
# logger.info(app.builder.srcdir)

_, script = split_code_and_text_blocks(example)
intro, title = extract_intro_and_title(example, script[0][1])

Expand All@@ -176,21 +113,14 @@ def generate_search_page(app):
# add the thumbnail
rst_content += thumbnail_rst

all_py_examples.append(fullpath)

f.write(rst_content)
f.write(THUMBNAIL_PARENT_DIV_CLOSE)
# f.close()

all_py_examples = list(chain.from_iterable(all_py_examples))

logger.info("all py examples")
logger.info(all_py_examples)
logger.info(examples_dir_abs_path)
logger.info(gallery_dir_abs_path)




def setup(app):
app.connect("builder-inited", generate_search_page)

# need to decide on the priority
app.connect("builder-inited", generate_search_page, priority=100)

[8]ページ先頭

©2009-2025 Movatter.jp