コード例 #1
0
def test_validate_config():
    config = AttrDict({
        "source_link_target": "Sphinx",
        "github_username": "******",
        "github_repository": "sphinx-toolbox",
        "rst_prolog": '',
    })

    validate_config(None, config)  # type: ignore

    assert config == {
        "source_link_target":
        "sphinx",
        "github_username":
        "******",
        "github_repository":
        "sphinx-toolbox",
        "github_url":
        RequestsURL("https://github.com/domdfcoding/sphinx-toolbox"),
        "github_source_url":
        RequestsURL(
            "https://github.com/domdfcoding/sphinx-toolbox/blob/master"),
        "github_issues_url":
        RequestsURL("https://github.com/domdfcoding/sphinx-toolbox/issues"),
        "github_pull_url":
        RequestsURL("https://github.com/domdfcoding/sphinx-toolbox/pull"),
        "rst_prolog":
        "\n\n.. |nbsp| unicode:: 0xA0\n   :trim:",
    }

    config = AttrDict({
        "source_link_target": "Sphinx",
        "github_username": None,
        "github_repository": "sphinx-toolbox",
    })

    with pytest.raises(MissingOptionError,
                       match="The 'github_username' option is required."):
        validate_config(None, config)  # type: ignore

    config = AttrDict({
        "source_link_target": "Sphinx",
        "github_username": "******",
        "github_repository": None,
    })

    with pytest.raises(MissingOptionError,
                       match="The 'github_repository' option is required."):
        validate_config(None, config)  # type: ignore

    config = AttrDict({
        "source_link_target": "bananas",
        "github_username": "******",
        "github_repository": "sphinx-toolbox",
    })

    with pytest.raises(InvalidOptionError,
                       match="Invalid value for 'source_link_target'."):
        validate_config(None, config)  # type: ignore
コード例 #2
0
ファイル: __init__.py プロジェクト: domdfcoding/searchdocs
def resolve_url(url: Union[str, RequestsURL]) -> RequestsURL:
	"""
	Resolve any redirects in the given URL.

	:param url:
	"""

	return RequestsURL(RequestsURL(url).head(allow_redirects=True).url)
コード例 #3
0
    def __init__(self, github_issues_url):
        config = AttrDict({"github_pull_url": RequestsURL(github_issues_url)})
        app = AttrDict({"config": config})
        env = AttrDict({"app": app})
        settings = AttrDict({"env": env})
        reporter = Reporter('', 0, 100)

        self.document = AttrDict({"settings": settings, "reporter": reporter})
コード例 #4
0
def get_sphinx_doc_url(pypi_name: str) -> str:
    """
	Returns the URL to the given project's Sphinx documentation.

	Not all projects include this URL in their distributions
	and therefore it may not be possible to determine it from PyPI.

	Responses are cached to prevent overloading the PyPI server.
	The cache can be cleared as follows:

	.. prompt:: bash

		python3 -m seed_intersphinx_mapping

	.. latex:vspace:: -10px

	:param pypi_name: The name of the project on PyPI

	:returns: The URL of the project's Sphinx documentation.

	:raises:

		* :exc:`ValueError` if the url could not be determined.
		* :exc:`packaging.requirements.InvalidRequirement` if the project could not be found on PyPI.

	.. versionchanged:: 0.4.0

		Now raises :exc:`~packaging.requirements.InvalidRequirement` rather than
		:exc:`apeye.slumber_url.exceptions.HttpNotFoundError` if the project could not be found on PyPI.
	"""

    for key, value in _get_project_links(pypi_name).items():

        # Follow redirects to get actual URL
        r = RequestsURL(value).head(allow_redirects=True, timeout=10)
        if r.status_code != 200:  # pragma: no cover
            raise ValueError(
                f"Documentation URL not found: HTTP Status {r.status_code}.")

        docs_url = r.url

        if docs_url.endswith('/'):
            objects_inv_url = f"{docs_url}objects.inv"
        else:  # pragma: no cover
            objects_inv_url = f"{docs_url}/objects.inv"

        r = requests.head(objects_inv_url)
        if r.status_code != 200:
            raise ValueError(
                f"objects.inv not found at url {objects_inv_url}: HTTP Status {r.status_code}."
            )

        return docs_url

    raise ValueError("Documentation URL not found in data from PyPI.")
コード例 #5
0
ファイル: test_wordle.py プロジェクト: domdfcoding/wordle
def test_python_source_file(
    tmp_pathplus,
    image_regression: ImageRegressionFixture,
    counter_regression: CounterRegressionFixture,
):
    w = Wordle(random_state=5678)

    outfile = tmp_pathplus / "python_wordcloud.png"

    source_url = RequestsURL(
        "https://raw.githubusercontent.com/domdfcoding/wordle")
    source_url = source_url / "76797ba8b641b38fe1bed0801f0af248b793b59e/wordle/__init__.py"
    (tmp_pathplus / "source.py").write_bytes(source_url.get().content)

    w.generate_from_file(tmp_pathplus / "source.py",
                         outfile=tmp_pathplus / "python_wordcloud.svg")
    export_wordcloud(w, outfile=outfile)

    image_regression.check(outfile.read_bytes())
    counter_regression.check(frequency_from_file(tmp_pathplus / "source.py"))
コード例 #6
0
def close_empty_pull_requests():
	owner = github_app.payload["repository"]["owner"]["login"]
	repo_name = github_app.payload["repository"]["name"]
	num = github_app.payload["pull_request"]["number"]
	pr: PullRequest = github_app.installation_client.pull_request(owner, repo_name, num)

	if not RequestsURL(pr.diff_url).get().text:
		issue = pr.issue()

		issue.close()
		issue.create_comment(empty_pr_close_message)
コード例 #7
0
    def __init__(self, source_link_target, github_source_url):
        config = AttrDict({
            "source_link_target": source_link_target,
            "github_source_url": RequestsURL(github_source_url),
        })
        app = AttrDict({
            "config":
            config,
            "builder":
            AttrDict({
                "get_relative_uri": lambda from_, to: to
            })
        })
        env = AttrDict({"app": app, "docname": ''})
        settings = AttrDict({"env": env})
        reporter = Reporter('', 0, 100)

        self.document = AttrDict({"settings": settings, "reporter": reporter})
コード例 #8
0
def test_make_github_url():
    url = make_github_url("domdfcoding", "sphinx-toolbox")
    assert isinstance(url, RequestsURL)

    assert url == RequestsURL("https://github.com/domdfcoding/sphinx-toolbox")
コード例 #9
0
	"""
	Retrieve the path to a resource inside a package.

	.. versionadded:: $VERSION

	:param package: The name of the package, or a module object representing it.
	:param resource: The name of the resource.
	"""

	if sys.version_info < (3, 7) or sys.version_info >= (3, 11):
		return importlib_resources.as_file(importlib_resources.files(package) / os.fspath(resource))
	else:
		return importlib_resources.path(package, resource)


base_license_url = RequestsURL("https://raw.githubusercontent.com/licenses/license-templates/master/templates/")

license_file_lookup = dict([
		(
				"GNU Lesser General Public License v3 (LGPLv3)",
				(base_license_url / "lgpl.txt", "lgpl3.py"),
				),
		(
				"GNU Lesser General Public License v3 or later (LGPLv3+)",
				(base_license_url / "lgpl.txt", "lgpl3_plus.py")
				),
		("GNU General Public License v3 (GPLv3)", (base_license_url / "gpl3.txt", "gpl3.py")),
		("GNU General Public License v3 or later (GPLv3+)", (base_license_url / "gpl3.txt", "gpl3_plus.py")),
		(
				"GNU General Public License v2 (GPLv2)",
				(RequestsURL("https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt"), "gpl2.py"),
コード例 #10
0
    "NoMatchError",
    "OptionSpec",
    "Param",
    "parse_parameters",
    "Purger",
    "SetupFunc",
    "SphinxExtMetadata",
    "typed_flag_regex",
    "typed_param_regex",
    "unknown_module_warning",
    "untyped_param_regex",
    "add_fallback_css_class",
]

#: Instance of :class:`apeye.requests_url.RequestsURL` that points to the GitHub website.
GITHUB_COM: RequestsURL = RequestsURL("https://github.com")

#: Type hint for the ``option_spec`` variable of Docutils directives.
OptionSpec = Mapping[str, Callable[[str], Any]]

_T = TypeVar("_T")

atexit.register(GITHUB_COM.session.close)


@functools.lru_cache()
def make_github_url(username: str, repository: str) -> RequestsURL:
    """
	Construct a URL to a GitHub repository from a username and repository name.

	:param username: The username of the GitHub account that owns the repository.
コード例 #11
0
# stdlib
import os

# 3rd party
from apeye.requests_url import RequestsURL
from domdf_python_tools.paths import PathPlus
from domdf_python_tools.stringlist import StringList
from shippinglabel.requirements import read_requirements

head_sha = RequestsURL(
    "https://api.github.com/repos/domdfcoding/repo_helper/commits/master").get(
    ).json()["sha"]

requirements, comments, invalid = read_requirements("requirements.txt",
                                                    include_invalid=True)

sorted_requirements = sorted(requirements)

buf = StringList(comments)

for line in invalid:
    if line.startswith("git+https://github.com/domdfcoding/repo_helper@"):
        buf.append(
            f"git+https://github.com/domdfcoding/repo_helper@{head_sha}")
    else:
        buf.append(line)

buf.extend(str(req) for req in sorted_requirements)

PathPlus("requirements.txt").write_lines(buf)
コード例 #12
0
# 3rd party
import pytest
import requests.exceptions
from apeye.requests_url import RequestsURL
from coincidence.regressions import check_file_output

# this package
from repo_helper.cli.commands.init import init_repo

has_internet = True
try:
    RequestsURL("https://raw.githubusercontent.com").head(timeout=10)
except (requests.exceptions.Timeout, requests.exceptions.ConnectionError):
    has_internet = False


@pytest.mark.flaky(reruns=2, reruns_delay=10)
@pytest.mark.skipif(condition=not has_internet,
                    reason="Requires internet connection.")
def test_init_repo(
    temp_empty_repo,
    demo_environment,
    file_regression,
    data_regression,
    fixed_date,
):
    demo_environment.globals["copyright_years"] = "2020-2021"
    demo_environment.globals["author"] = "Joe Bloggs"
    demo_environment.globals["email"] = "*****@*****.**"
    demo_environment.globals["license"] = "MIT License"
    demo_environment.globals["version"] = "1.2.3"
コード例 #13
0
ファイル: __main__.py プロジェクト: domdfcoding/searchdocs
#  OR OTHER DEALINGS IN THE SOFTWARE.
#

# stdlib
import sys

# 3rd party
import click
from apeye.requests_url import RequestsURL
from consolekit import click_command
from consolekit.commands import MarkdownHelpCommand
from consolekit.options import flag_option

__all__ = ["main"]

DOCS_PYTHON_ORG = RequestsURL("https://docs.python.org/3/")


@flag_option("--browser",
             help="Open the documentation in the default web browser.")
@click.argument("search_term", type=click.STRING)
@click_command(cls=MarkdownHelpCommand)
def main(search_term: str, browser: bool = False):
    """
	Search for ``SEARCH_TERM`` in the Python documentation, and print the URL of the best match.
	"""

    # this package
    from searchdocs import find_url

    url = find_url(DOCS_PYTHON_ORG, search_term)