FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

move to github actions by samuelcolvin · Pull Request #53 · samuelcolvin/python-devtools · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cfg  (1) .py  (10) .txt  (4) .yml  (2) No extension  (1) All 5 file types selected
Only manifest files
Deleted files Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
99 changes: 99 additions & 0 deletions .github/workflows/ci.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: CI

on:
push:
branches:
- master
tags:
- '**'
pull_request: {}

jobs:
test:
name: test py${{ matrix.python-version }} on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos]
python-version: ['3.6', '3.7', '3.8']

env:
PYTHON: ${{ matrix.python-version }}
OS: ${{ matrix.os }}
EXTRAS: yes

runs-on: ${{ matrix.os }}-latest

steps:
- uses: actions/checkout@v2

- name: set up python
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: install dependencies
run: |
make install
pip freeze

- name: lint
run: |
make lint
make check-dist

- name: test with extras
run: make test

- uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
env_vars: EXTRAS,PYTHON,OS

- name: uninstall extras
run: pip uninstall -y multidict numpy

- name: test without extras
run: |
make test
coverage xml

- uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
env_vars: DEPS,PYTHON,OS
env:
EXTRAS: no

deploy:
name: Deploy
needs: test
if: "success() && startsWith(github.ref, 'refs/tags/')"
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: set up python
uses: actions/setup-python@v1
with:
python-version: '3.8'

- name: install
run: |
make install
pip install -U wheel

- name: build
run: python setup.py sdist bdist_wheel

- run: twine check dist/*

- name: check tag
run: PACKAGE=devtools python <(curl -Ls https://git.io/JvQsH)

- name: upload to pypi
run: twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.pypi_token }}
54 changes: 0 additions & 54 deletions .travis.yml

This file was deleted.

36 changes: 19 additions & 17 deletions Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
.DEFAULT_GOAL := all
isort = isort -rc devtools tests
black = black -S -l 120 --target-version py37 devtools

.PHONY: install-dev
install-dev:
.PHONY: install
install:
pip install -U setuptools pip
pip install -r dev-requirements.txt
pip install -U -r requirements.txt
pip install -e .

.PHONY: install-test
install-test:
pip install -U setuptools pip
pip install -r tests/requirements.txt
pip install -r docs/requirements.txt
pip install -U .

.PHONY: isort
isort:
isort -rc -w 120 devtools
isort -rc -w 120 tests
.PHONY: format
format:
$(isort)
$(black)

.PHONY: lint
lint:
python setup.py check -rms
flake8 devtools/ tests/
pytest devtools -p no:sugar -q
$(isort) --check-only -df
$(black) --check

.PHONY: check-dist
check-dist:
python setup.py check -ms
python setup.py sdist
twine check dist/*

.PHONY: test
test:
Expand All @@ -34,7 +36,7 @@ testcov:
@coverage html

.PHONY: all
all: testcov lint
all: lint testcov

.PHONY: clean
clean:
Expand Down
1 change: 1 addition & 0 deletions devtools/ansi.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class StylePrint:
Annoyingly enums do not allow inheritance, a lazy design mistake, this is an ugly work around
for that mistake.
"""

def __call__(self, input, *styles, reset=True, flush=True, file=None, **print_kwargs):
text = sformat(input, *styles, reset=reset, apply=isatty(file))
print(text, flush=flush, file=file, **print_kwargs)
Expand Down
40 changes: 23 additions & 17 deletions devtools/debug.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def str(self, highlight=False) -> str:
suffix = sformat(
' ({.value.__class__.__name__}){}'.format(self, ''.join(' {}={}'.format(k, v) for k, v in self.extra)),
sformat.dim,
apply=highlight
apply=highlight,
)
try:
s += pformat(self.value, indent=4, highlight=highlight)
Expand All @@ -68,6 +68,7 @@ class DebugOutput:
"""
Represents the output of a debug command.
"""

arg_class = DebugArgument
__slots__ = 'filename', 'lineno', 'frame', 'arguments', 'warning'

Expand All @@ -83,7 +84,7 @@ def str(self, highlight=False) -> str:
prefix = '{}:{} {}'.format(
sformat(self.filename, sformat.magenta),
sformat(self.lineno, sformat.green),
sformat(self.frame, sformat.green, sformat.italic)
sformat(self.frame, sformat.green, sformat.italic),
)
if self.warning:
prefix += sformat(' ({})'.format(self.warning), sformat.dim)
Expand All @@ -104,15 +105,22 @@ def __repr__(self) -> str:
class Debug:
output_class = DebugOutput
complex_nodes = (
ast.Call, ast.Attribute, ast.Subscript,
ast.IfExp, ast.BoolOp, ast.BinOp, ast.Compare,
ast.DictComp, ast.ListComp, ast.SetComp, ast.GeneratorExp
ast.Call,
ast.Attribute,
ast.Subscript,
ast.IfExp,
ast.BoolOp,
ast.BinOp,
ast.Compare,
ast.DictComp,
ast.ListComp,
ast.SetComp,
ast.GeneratorExp,
)

def __init__(self, *,
warnings: Optional[bool] = None,
highlight: Optional[bool] = None,
frame_context_length: int = 50):
def __init__(
self, *, warnings: Optional[bool] = None, highlight: Optional[bool] = None, frame_context_length: int = 50
):
self._show_warnings = self._env_bool(warnings, 'PY_DEVTOOLS_WARNINGS', True)
self._highlight = self._env_bool(highlight, 'PY_DEVTOOLS_HIGHLIGHT', None)
# 50 lines should be enough to make sure we always get the entire function definition
Expand Down Expand Up @@ -217,9 +225,7 @@ def _process_args(self, func_ast, code_lines, args, kwargs) -> Generator[DebugAr
for l_ in range(start_line, end_line + 1):
start_ = start_col if l_ == start_line else 0
end_ = end_col if l_ == end_line else None
name_lines.append(
code_lines[l_][start_:end_].strip(' ')
)
name_lines.append(code_lines[l_][start_:end_].strip(' '))
yield self.output_class.arg_class(arg, name=' '.join(name_lines).strip(' ,'))
else:
yield self.output_class.arg_class(arg)
Expand All @@ -239,7 +245,7 @@ def _parse_code(
try:
new_line = call_frame.code_context[line]
except IndexError: # pragma: no cover
return None, None, line, 'error passing code. line not found'
return None, None, line, 'error parsing code. line not found'
call_lines.append(new_line)
if re.search(func_regex, new_line):
break
Expand All @@ -258,7 +264,7 @@ def _parse_code(
# )
# inspect ignores it when setting index and we have to add it back
for extra in range(2, 6):
extra_lines = call_frame.code_context[tail_index + 1:tail_index + extra]
extra_lines = call_frame.code_context[tail_index + 1 : tail_index + extra]
code = dedent(''.join(call_lines + extra_lines))
try:
func_ast = self._wrap_parse(code, filename)
Expand All @@ -268,12 +274,12 @@ def _parse_code(
break

if not func_ast:
return None, None, lineno, 'error passing code, {0.__class__.__name__}: {0}'.format(e1)
return None, None, lineno, 'error parsing code, {0.__class__.__name__}: {0}'.format(e1)

if not isinstance(func_ast, ast.Call):
return None, None, lineno, 'error passing code, found {} not Call'.format(func_ast.__class__)
return None, None, lineno, 'error parsing code, found {} not Call'.format(func_ast.__class__)

code_lines = [l for l in code.split('\n') if l]
code_lines = [line for line in code.split('\n') if line]
# this removes the trailing bracket from the lines of code meaning it doesn't appear in the
# representation of the last argument
code_lines[-1] = code_lines[-1][:-1]
Expand Down
17 changes: 9 additions & 8 deletions devtools/prettier.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import io
import os
import textwrap
import warnings
from collections import OrderedDict
from collections.abc import Generator
from typing import Any, Union
Expand Down Expand Up @@ -52,13 +51,15 @@ class SkipPretty(Exception):


class PrettyFormat:
def __init__(self,
indent_step=4,
indent_char=' ',
repr_strings=False,
simple_cutoff=10,
width=120,
yield_from_generators=True):
def __init__(
self,
indent_step=4,
indent_char=' ',
repr_strings=False,
simple_cutoff=10,
width=120,
yield_from_generators=True,
):
self._indent_step = indent_step
self._c = indent_char
self._repr_strings = repr_strings
Expand Down
26 changes: 14 additions & 12 deletions devtools/timer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from statistics import mean, stdev
from time import time

__all__ = 'Timer',
__all__ = ('Timer',)


class TimerResult:
Expand Down Expand Up @@ -49,9 +49,7 @@ def __call__(self, name=None, verbose=None):
return self

def start(self, name=None, verbose=None):
self.results.append(
TimerResult(name or self._name, self._verbose if verbose is None else verbose)
)
self.results.append(TimerResult(name or self._name, self._verbose if verbose is None else verbose))
return self

def capture(self, verbose=None):
Expand All @@ -72,14 +70,18 @@ def summary(self, verbose=False):
times.add(r.elapsed())

if times:
print(_SUMMARY_TEMPLATE.format(
count=len(times),
mean=mean(times),
stddev=stdev(times) if len(times) > 1 else 0,
min=min(times),
max=max(times),
dp=self.dp,
), file=self.file, flush=True)
print(
_SUMMARY_TEMPLATE.format(
count=len(times),
mean=mean(times),
stddev=stdev(times) if len(times) > 1 else 0,
min=min(times),
max=max(times),
dp=self.dp,
),
file=self.file,
flush=True,
)
else:
raise RuntimeError('timer not started')
return times
Expand Down
Loading

Back | FazBrowse Home | New Git URL