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

Support JSONPath #237

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
73 changes: 39 additions & 34 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'notfound.extension',
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
"notfound.extension",
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"sphinx.ext.viewcode",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix of source filenames.
source_suffix = '.rst'
source_suffix = ".rst"

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'Parsel'
copyright = '2015, Scrapy Project'
project = "Parsel"
copyright = "2015, Scrapy Project"

# The version info for the project you're documenting, acts as replacement
# for |version| and |release|, also used in various other places throughout
Expand All @@ -51,28 +51,28 @@

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
exclude_patterns = ["_build"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

suppress_warnings = ['epub.unknown_project_files']
suppress_warnings = ["epub.unknown_project_files"]


# -- Options for HTML output -------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

# Add any paths that contain custom static files (such as style sheets)
# here, relative to this directory. They are copied after the builtin
# static files, so a file named "default.css" will overwrite the builtin
# "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Output file base name for HTML help builder.
htmlhelp_basename = 'parseldoc'
htmlhelp_basename = "parseldoc"


# -- Options for LaTeX output ------------------------------------------
Expand All @@ -83,9 +83,13 @@
# (source start file, target name, title, author, documentclass
# [howto/manual]).
latex_documents = [
('index', 'parsel.tex',
'Parsel Documentation',
'Scrapy Project', 'manual'),
(
"index",
"parsel.tex",
"Parsel Documentation",
"Scrapy Project",
"manual",
),
]


Expand All @@ -94,9 +98,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'parsel',
'Parsel Documentation',
['Scrapy Project'], 1)
("index", "parsel", "Parsel Documentation", ["Scrapy Project"], 1)
]


Expand All @@ -106,30 +108,33 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'parsel',
'Parsel Documentation',
'Scrapy Project',
'parsel',
'One line description of project.',
'Miscellaneous'),
(
"index",
"parsel",
"Parsel Documentation",
"Scrapy Project",
"parsel",
"One line description of project.",
"Miscellaneous",
),
]


# -- Options for the InterSphinx extension ------------------------------------

intersphinx_mapping = {
'cssselect': ('https://cssselect.readthedocs.io/en/latest', None),
'python': ('https://docs.python.org/3', None),
'requests': ('https://requests.kennethreitz.org/en/latest', None),
"cssselect": ("https://cssselect.readthedocs.io/en/latest", None),
"python": ("https://docs.python.org/3", None),
"requests": ("https://requests.kennethreitz.org/en/latest", None),
}


# --- Nitpicking options ------------------------------------------------------

# nitpicky = True # https://github.com/scrapy/cssselect/pull/110
nitpick_ignore = [
('py:class', 'cssselect.xpath.GenericTranslator'),
('py:class', 'cssselect.xpath.HTMLTranslator'),
('py:class', 'cssselect.xpath.XPathExpr'),
('py:class', 'lxml.etree.XMLParser'),
("py:class", "cssselect.xpath.GenericTranslator"),
("py:class", "cssselect.xpath.HTMLTranslator"),
("py:class", "cssselect.xpath.XPathExpr"),
("py:class", "lxml.etree.XMLParser"),
]
13 changes: 8 additions & 5 deletions docs/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@
from doctest import ELLIPSIS, NORMALIZE_WHITESPACE

from sybil import Sybil

try:
from sybil.parsers.codeblock import PythonCodeBlockParser
except ImportError:
from sybil.parsers.codeblock import CodeBlockParser as PythonCodeBlockParser
from sybil.parsers.codeblock import (
CodeBlockParser as PythonCodeBlockParser,
)
from sybil.parsers.doctest import DocTestParser
from sybil.parsers.skip import skip

from parsel import Selector


def load_selector(filename, **kwargs):
input_path = os.path.join(os.path.dirname(__file__), '_static', filename)
input_path = os.path.join(os.path.dirname(__file__), "_static", filename)
with open(input_path, encoding="utf-8") as input_file:
return Selector(text=input_file.read(), **kwargs)


def setup(namespace):
namespace['load_selector'] = load_selector
namespace["load_selector"] = load_selector


pytest_collect_file = Sybil(
parsers=[
DocTestParser(optionflags=ELLIPSIS | NORMALIZE_WHITESPACE),
PythonCodeBlockParser(future_imports=['print_function']),
PythonCodeBlockParser(future_imports=["print_function"]),
skip,
],
pattern='*.rst',
pattern="*.rst",
setup=setup,
).pytest()
8 changes: 6 additions & 2 deletions parsel/csstranslator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class XPathExpr(OriginalXPathExpr):

@classmethod
def from_xpath(cls, xpath, textnode=False, attribute=None):
x = cls(path=xpath.path, element=xpath.element, condition=xpath.condition)
x = cls(
path=xpath.path, element=xpath.element, condition=xpath.condition
)
x.textnode = textnode
x.attribute = attribute
return x
Expand Down Expand Up @@ -81,7 +83,9 @@ def xpath_attr_functional_pseudo_element(self, xpath, function):
raise ExpressionError(
f"Expected a single string or ident for ::attr(), got {function.arguments!r}"
)
return XPathExpr.from_xpath(xpath, attribute=function.arguments[0].value)
return XPathExpr.from_xpath(
xpath, attribute=function.arguments[0].value
)

def xpath_text_simple_pseudo_element(self, xpath):
"""Support selecting text nodes using ::text pseudo-element"""
Expand Down
Loading