Skip to content

Commit

Permalink
Merge pull request #100 from Erotemic/dev/0.15.7
Browse files Browse the repository at this point in the history
Start branch for 0.15.7
  • Loading branch information
Erotemic authored Sep 2, 2021
2 parents e8a3cfa + 02e99a1 commit 1af724f
Show file tree
Hide file tree
Showing 17 changed files with 525 additions and 151 deletions.
16 changes: 8 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ __doc__: &__doc__
This is only needed if you want to automatically sign published
wheels with a gpg key.
* GITHUB_PUSH_TOKEN -
* PERSONAL_GITHUB_PUSH_TOKEN -
This is only needed if you want to automatically git-tag release branches.
To make a API token go to:
Expand All @@ -80,7 +80,7 @@ __doc__: &__doc__
Do whatever you need to locally access the values of these variables
echo $TWINE_USERNAME
echo $GITHUB_PUSH_TOKEN
echo $PERSONAL_GITHUB_PUSH_TOKEN
echo $CIRCLE_CI_SECRET
echo $TWINE_PASSWORD
Expand Down Expand Up @@ -122,7 +122,7 @@ __doc__: &__doc__
export TWINE_USERNAME=<pypi-username>
export TWINE_PASSWORD=<pypi-password>
export CIRCLE_CI_SECRET="<a-very-long-secret-string>"
export GITHUB_PUSH_TOKEN='git-push-token:<token-password>'
export PERSONAL_GITHUB_PUSH_TOKEN='git-push-token:<token-password>'
```
You should also make a secret_unloader.sh that points to a script that
Expand Down Expand Up @@ -180,10 +180,10 @@ __doc__: &__doc__
```
TEST GITHUB_PUSH_TOKEN
TEST PERSONAL_GITHUB_PUSH_TOKEN
-------------------
The following script tests if your GITHUB_PUSH_TOKEN environment variable is correctly setup.
The following script tests if your PERSONAL_GITHUB_PUSH_TOKEN environment variable is correctly setup.
```bash
docker run -it ubuntu
Expand All @@ -196,7 +196,7 @@ __doc__: &__doc__
URL_HOST=$(git remote get-url origin | sed -e 's|https\?://.*@||g' | sed -e 's|https\?://||g')
echo "URL_HOST = $URL_HOST"
git tag "test-tag4"
git push --tags "https://${GITHUB_PUSH_TOKEN}@${URL_HOST}"
git push --tags "https://${PERSONAL_GITHUB_PUSH_TOKEN}@${URL_HOST}"
# Cleanup after you verify the tags shows up on the remote
git push --delete origin test-tag4
Expand Down Expand Up @@ -445,7 +445,7 @@ jobs:
# Have the server git-tag the release and push the tags
VERSION=$($PYTHON_EXE -c "import setup; print(setup.VERSION)")
# do sed twice to handle the case of https clone with and without a read token
URL_HOST=$(git remote get-url origin | sed -e 's|https\?://.*@||g' | sed -e 's|https\?://||g')
URL_HOST=$(git remote get-url origin | sed -e 's|https\?://.*@||g' | sed -e 's|https\?://||g' | sed -e 's|git@||g' | sed -e 's|:|/|g')
echo "URL_HOST = $URL_HOST"
# A git config user name and email is required. Set if needed.
if [[ "$(git config user.email)" == "" ]]; then
Expand All @@ -456,7 +456,7 @@ jobs:
echo "Tag already exists"
else
git tag $VERSION -m "tarball tag $VERSION"
git push --tags "https://${GITHUB_PUSH_TOKEN}@${URL_HOST}"
git push --tags "https://${PERSONAL_GITHUB_PUSH_TOKEN}@${URL_HOST}"
fi
Expand Down
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,29 @@ We are currently working on porting this changelog to the specifications in
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## Version 0.15.6 - Unreleased
## Version 0.15.7 - Unreleased

### Changed
* Removed the distracting and very long internal traceback that occurred in
pytest when a module errors while it is being imported before the doctest is
run.
* Pytest now defaults to `--xdoctest-verbose=2` by default (note this does
nothing unless `-s` is also given so pytest does not supress output)


### Fixed
* Bug in REQUIRES state did not respect `python_implementation` arguments
* Ported sphinx fixes from ubelt

## Version 0.15.6 - Released 2021-08-08


### Changed
* Directive syntax errors are now handled as doctest runtime errors and return
better debugging information.

* README and docs were improved


## Version 0.15.5 - Released 2021-06-27

Expand Down
5 changes: 1 addition & 4 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ sphinx
sphinx-autobuild
sphinx_rtd_theme
sphinxcontrib-napoleon

sphinx-autoapi

six
Pygments

ubelt

sphinx-reredirects
myst_parser
102 changes: 100 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ def visit_Assign(self, node):
sphobjinv suggest -t 90 -u https://readthedocs.org/projects/pytest/reference/objects.inv
"signal.convolve2d"
python -m sphinx.ext.intersphinx https://pygments-doc.readthedocs.io/en/latest/objects.inv
"""
Expand All @@ -294,8 +293,107 @@ def visit_Assign(self, node):
# 'pygments': ('https://pygments-doc.readthedocs.io/en/latest/', None),
# 'colorama': ('https://pypi.org/project/colorama/', None),
'python': ('https://docs.python.org/3', None),
# 'ubelt': ('https://readthedocs.org/projects/ubelt/', None),
'ubelt': ('https://ubelt.readthedocs.io/en/latest/', None),
# 'numpy': ('http://docs.scipy.org/doc/numpy/', None),
# 'cv2' : ('http://docs.opencv.org/2.4/', None),
# 'h5py' : ('http://docs.h5py.org/en/latest/', None)
}
__dev_note__ = """
python -m sphinx.ext.intersphinx https://docs.python.org/3/objects.inv
python -m sphinx.ext.intersphinx https://ubelt.readthedocs.io/en/latest/objects.inv
python -m sphinx.ext.intersphinx https://networkx.org/documentation/stable/objects.inv
"""


# -- Extension configuration -------------------------------------------------


from sphinx.domains.python import PythonDomain # NOQA


class PatchedPythonDomain(PythonDomain):
"""
References:
https://github.com/sphinx-doc/sphinx/issues/3866
"""
def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
# TODO: can use this to resolve references nicely
if target.startswith('xdoc.'):
target = 'xdoctest.' + target[3]
return_value = super(PatchedPythonDomain, self).resolve_xref(
env, fromdocname, builder, typ, target, node, contnode)
return return_value


def setup(app):
# app.add_domain(PatchedPythonDomain, override=True)

if 1:
# https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
from sphinx.application import Sphinx
from typing import Any, List

what = None
# Custom process to transform docstring lines
# Remove "Ignore" blocks
def process(app: Sphinx, what_: str, name: str, obj: Any, options: Any, lines: List[str]
) -> None:
if what and what_ not in what:
return
orig_lines = lines[:]

# text = '\n'.join(lines)
# if 'Example' in text and 'CommandLine' in text:
# import xdev
# xdev.embed()

ignore_tags = tuple(['Ignore'])

mode = None
# buffer = None
new_lines = []
for i, line in enumerate(orig_lines):

# See if the line triggers a mode change
if line.startswith(ignore_tags):
mode = 'ignore'
elif line.startswith('CommandLine'):
mode = 'cmdline'
elif line and not line.startswith(' '):
# if the line startswith anything but a space, we are no
# longer in the previous nested scope
mode = None

if mode is None:
new_lines.append(line)
elif mode == 'ignore':
# print('IGNORE line = {!r}'.format(line))
pass
elif mode == 'cmdline':
if line.startswith('CommandLine'):
new_lines.append('.. rubric:: CommandLine')
new_lines.append('')
new_lines.append('.. code-block:: bash')
new_lines.append('')
# new_lines.append(' # CommandLine')
else:
# new_lines.append(line.strip())
new_lines.append(line)
else:
raise KeyError(mode)

lines[:] = new_lines
# make sure there is a blank line at the end
if lines and lines[-1]:
lines.append('')

app.connect('autodoc-process-docstring', process)
else:
# https://stackoverflow.com/questions/26534184/can-sphinx-ignore-certain-tags-in-python-docstrings
# Register a sphinx.ext.autodoc.between listener to ignore everything
# between lines that contain the word IGNORE
# from sphinx.ext.autodoc import between
# app.connect('autodoc-process-docstring', between('^ *Ignore:$', exclude=True))
pass

return app
139 changes: 139 additions & 0 deletions testing/test_pytest_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
from xdoctest.utils import util_misc
import sys
from xdoctest import utils


def cmd(command):
# simplified version of ub.cmd no fancy tee behavior
import subprocess
proc = subprocess.Popen(
command, shell=True, universal_newlines=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
out, err = proc.communicate()
ret = proc.wait()
info = {
'proc': proc,
'out': out,
'test_doctest_in_notebook.ipynberr': err,
'ret': ret,
}
return info


def test_simple_pytest_cli():
module_text = utils.codeblock(
'''
def module_func1():
"""
This module has a doctest
Example:
>>> print('hello world')
"""
''')
temp_module = util_misc.TempModule(module_text)
modpath = temp_module.modpath

info = cmd(sys.executable + ' -m pytest --xdoctest ' + modpath)
print(info['out'])
assert info['ret'] == 0


def test_simple_pytest_import_error_cli():
"""
This test case triggers an excessively long callback in xdoctest <
dev/0.15.7
xdoctest ~/code/xdoctest/testing/test_pytest_cli.py test_simple_pytest_import_error_cli
import sys, ubelt
sys.path.append(ubelt.expandpath('~/code/xdoctest/testing'))
from test_pytest_cli import * # NOQA
"""
module_text = utils.codeblock(
'''
# There are lines before the bad line
import os
import sys
import does_not_exist
def module_func1():
"""
This module has a doctest
Example:
>>> print('hello world')
"""
''')
temp_module = util_misc.TempModule(module_text, modname='imperr_test_mod')
command = sys.executable + ' -m pytest -v -s --xdoctest-verbose=3 --xdoctest ' + temp_module.dpath
print(command)
info = cmd(command)
print(info['out'])

# info = cmd('pytest --xdoctest ' + temp_module.modpath)
# print(info['out'])

assert info['ret'] == 1


def test_simple_pytest_syntax_error_cli():
"""
"""
module_text = utils.codeblock(
'''
&&does_not_exist
def module_func1():
"""
This module has a doctest
Example:
>>> print('hello world')
"""
''')
temp_module = util_misc.TempModule(module_text)
info = cmd(sys.executable + ' -m pytest --xdoctest ' + temp_module.dpath)
print(info['out'])

info = cmd(sys.executable + ' -m pytest --xdoctest ' + temp_module.modpath)
print(info['out'])


def test_simple_pytest_import_error_no_xdoctest():
"""
"""
module_text = utils.codeblock(
'''
import does_not_exist
def test_this():
print('hello world')
''')
temp_module = util_misc.TempModule(module_text)
info = cmd(sys.executable + ' -m pytest ' + temp_module.modpath)
print(info['out'])

info = cmd('pytest ' + temp_module.dpath)
print(info['out'])
# assert info['ret'] == 0


def test_simple_pytest_syntax_error_no_xdoctest():
"""
"""
module_text = utils.codeblock(
'''
&&does_not_exist
def test_this():
print('hello world')
''')
temp_module = util_misc.TempModule(module_text)
info = cmd(sys.executable + ' -m pytest ' + temp_module.modpath)
print(info['out'])

info = cmd(sys.executable + ' -m pytest ' + temp_module.dpath)
print(info['out'])
# assert info['ret'] == 0
Loading

0 comments on commit 1af724f

Please sign in to comment.