Skip to content

Commit

Permalink
Merge branch 'master' of github.com:alexmojaki/stack_data into new-pu…
Browse files Browse the repository at this point in the history
…re-eval
  • Loading branch information
alexmojaki committed Apr 2, 2021
2 parents 51fe91e + ddf7ad8 commit c6898de
Show file tree
Hide file tree
Showing 20 changed files with 654 additions and 77 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
dist
build
stack_data/version.py
stack_data.egg-info
.eggs
.pytest_cache
.tox
pip-wheel-metadata
venv
*.egg-info
*.pyc
*.pyo
__pycache__
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ python:
- 3.6
- 3.7
- 3.8-dev
- 3.9-dev

env:
global:
- STACK_DATA_SLOW_TESTS=1
- COVERALLS_PARALLEL=true

before_install:
- pip install --upgrade coveralls setuptools>=44 setuptools_scm>=3.4.3 pep517

install:
- pip install coveralls
- pip install .[tests]
- pip install '.[tests]'

script:
- coverage run --include='stack_data/*' -m pytest
- coverage run --branch --include='stack_data/*' -m pytest --junitxml=./rspec.xml
- coverage report -m

after_success:
Expand Down
30 changes: 30 additions & 0 deletions make_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
set -eux

# Ensure that there are no uncommitted changes
# which would mess up using the git tag as a version
[ -z "$(git status --porcelain)" ]

if [ -z "${1+x}" ]
then
set +x
echo Provide a version argument
echo "${0} <major>.<minor>.<patch>"
exit 1
else
if [[ ${1} =~ ^([0-9]+)(\.[0-9]+)?(\.[0-9]+)?$ ]]; then
:
else
echo "Not a valid release tag."
exit 1
fi
fi

tox -p auto

export TAG="v${1}"
git tag "${TAG}"
git push origin master "${TAG}"
rm -rf ./build ./dist
python3 -m pep517.build -b .
twine upload ./dist/*.whl
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
requires = ["setuptools>=44", "wheel", "setuptools_scm[toml]>=3.4.3"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "stack_data/version.py"
write_to_template = "__version__ = '{version}'\n"
29 changes: 29 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[metadata]
name = stack_data
author = Alex Hall
author_email = [email protected]
license = MIT
description = Extract data from python stack frames and tracebacks for informative displays
url = http://github.com/alexmojaki/stack_data
long_description = file: README.md
long_description_content_type = text/markdown
classifiers =
Intended Audience :: Developers
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
License :: OSI Approved :: MIT License
Operating System :: OS Independent
Topic :: Software Development :: Debuggers

[options]
packages = stack_data
install_requires = executing; asttokens; pure_eval
setup_requires = setuptools>=44; wheel; setuptools_scm[toml]>=3.4.3
include_package_data = True
tests_require = pytest; typeguard; pygments

[options.extras_require]
tests = pytest; typeguard; pygments; pep517; littleutils
62 changes: 2 additions & 60 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,4 @@
import os
import re
from io import open

from setuptools import setup

package = 'stack_data'
dirname = os.path.dirname(__file__)


def file_to_string(*path):
with open(os.path.join(dirname, *path), encoding='utf8') as f:
return f.read()


# __version__ is defined inside the package, but we can't import
# it because it imports dependencies which may not be installed yet,
# so we extract it manually
contents = file_to_string(package, '__init__.py')
__version__ = re.search(r"__version__ = '([.\d]+)'", contents).group(1)

install_requires = [
'executing',
'asttokens',
'pure_eval',
]


tests_require = [
'pytest',
'typeguard',
'pygments',
]

setup(
name=package,
version=__version__,
description="Extract data from python stack frames and tracebacks for informative displays",
# long_description=file_to_string('README.md'),
# long_description_content_type='text/markdown',
url='http://github.com/alexmojaki/' + package,
author='Alex Hall',
author_email='[email protected]',
license='MIT',
include_package_data=True,
packages=[package],
install_requires=install_requires,
tests_require=tests_require,
extras_require={
'tests': tests_require,
},
classifiers=[
'Intended Audience :: Developers',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Topic :: Software Development :: Debuggers',
],
)
if __name__ == "__main__":
setup()
10 changes: 8 additions & 2 deletions stack_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
__version__ = '0.0.6'
from .core import Source, FrameInfo, markers_from_ranges, Options, LINE_GAP, Line, Variable, RangeInLine, \
RepeatedFrames, MarkerInLine, style_with_executing_node
from .formatting import Formatter

from .core import Source, FrameInfo, markers_from_ranges, Options, LINE_GAP, Line, Variable, RangeInLine, RepeatedFrames, MarkerInLine, style_with_executing_node
try:
from .version import __version__
except ImportError:
# version.py is auto-generated with the git tag when building
__version__ = "???"
19 changes: 10 additions & 9 deletions stack_data/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import sys
from collections import defaultdict, Counter
from textwrap import dedent
from tokenize import TokenInfo
from types import FrameType, CodeType, TracebackType
from typing import (
Iterator, List, Tuple, Optional, NamedTuple,
Any, Iterable, Callable, Union
)
Any, Iterable, Callable, Union,
Sequence)
from typing import Mapping

import executing
Expand All @@ -19,7 +18,7 @@
from stack_data.utils import (
truncate, unique_in_order, line_range,
frame_and_lineno, iter_stack, collapse_repeated, group_by_key_func,
cached_property, is_frame, _pygmented_with_ranges)
cached_property, is_frame, _pygmented_with_ranges, assert_)

RangeInLine = NamedTuple('RangeInLine',
[('start', int),
Expand Down Expand Up @@ -50,7 +49,7 @@
class Variable(
NamedTuple('_Variable',
[('name', str),
('nodes', List[ast.AST]),
('nodes', Sequence[ast.AST]),
('value', Any)])
):
"""
Expand Down Expand Up @@ -87,7 +86,7 @@ def pieces(self) -> List[range]:
return list(self._clean_pieces())

@cached_property
def tokens_by_lineno(self) -> Mapping[int, List[TokenInfo]]:
def tokens_by_lineno(self) -> Mapping[int, List[Token]]:
if not self.tree:
raise AttributeError("This file doesn't contain valid Python, so .tokens_by_lineno doesn't exist")
return group_by_key_func(
Expand Down Expand Up @@ -333,8 +332,7 @@ def render(
common to all lines in this frame will be excluded.
"""
if pygmented:
assert not markers, "Cannot use pygmented with markers"
assert self.frame_info.options.pygments_formatter, "Must set a pygments formatter in Options"
assert_(not markers, ValueError("Cannot use pygmented with markers"))
start_line, lines = self.frame_info._pygmented_scope_lines
result = lines[self.lineno - start_line]
if strip_leading_indent:
Expand Down Expand Up @@ -721,7 +719,8 @@ def _pygmented_scope_lines(self) -> Optional[Tuple[int, List[str]]]:

formatter = self.options.pygments_formatter
scope = self.scope
assert scope and formatter
assert_(formatter, ValueError("Must set a pygments formatter in Options"))
assert_(scope)

if isinstance(formatter, HtmlFormatter):
formatter.nowrap = True
Expand Down Expand Up @@ -787,6 +786,8 @@ def variables(self) -> List[Variable]:
nodes, values = zip(*group)
value = values[0]
text = get_text(nodes[0])
if not text:
continue
result.append(Variable(text, nodes, value))

return result
Expand Down
Loading

0 comments on commit c6898de

Please sign in to comment.