From 3d9bd8fad03fca390558ff68aaa112c6e1b4f422 Mon Sep 17 00:00:00 2001 From: Jarry Shaw Date: Thu, 7 Mar 2019 18:24:47 +0800 Subject: [PATCH] New distribution * add PCAPKIT_DEVMODE environ * revised Makefile --- .github/ISSUE_TEMPLATE/bug_report.md | 28 ++++++-------------- Makefile | 38 ++++++++++++++-------------- docker/Dockerfile | 2 +- setup.py | 2 +- src/__init__.py | 16 ++++++++---- src/utilities/exceptions.py | 26 +++++++++++++------ 6 files changed, 58 insertions(+), 54 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b73537336..a847f7ba2 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,29 +7,17 @@ about: Create a report to help us improve **Describe the bug** A clear and concise description of what the bug is. -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error +**System information** +A clear and concise description of your system information. + - OS Version: [e.g. macOS Mojave 10.14.4] + - Python Version: [e.g 3.7, 3.6, 3.5, 3.4] + - Python Implementation: [e.g. CPython, PyPy] + +**Traceback stack** +Run program again with `PCAPKIT_DEVMODE=true` set to provide the traceback stack. **Expected behavior** A clear and concise description of what you expected to happen. -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - Version [e.g. 22] - -**Smartphone (please complete the following information):** - - Device: [e.g. iPhone6] - - OS: [e.g. iOS8.1] - - Browser [e.g. stock browser, safari] - - Version [e.g. 22] - **Additional context** Add any other context about the problem here. diff --git a/Makefile b/Makefile index 7f8d72535..784cefc7e 100644 --- a/Makefile +++ b/Makefile @@ -66,7 +66,7 @@ update-pipenv: update-const: set -ex for file in src/vendor/*/*.py ; do \ - pipenv run python3 $${file} ; \ + pipenv run python3 $${file} ; \ done # update maintenance information @@ -120,16 +120,16 @@ dist-upload: dist-prep: mkdir -p release rm -rf release/src \ - release/pcapkit + release/pcapkit cp -r .gitattributes \ - .gitignore \ - LICENSE \ - MANIFEST.in \ - README.md \ - docker \ - src \ - setup.py \ - setup.cfg release/ + .gitignore \ + LICENSE \ + MANIFEST.in \ + README.md \ + docker \ + src \ + setup.py \ + setup.cfg release/ mv release/src release/pcapkit # add tag @@ -147,9 +147,9 @@ git-upload: git pull git add . if [[ -z "$(message)" ]] ; then \ - git commit -a -S ; \ + git commit -a -S ; \ else \ - git commit -a -S -m "$(message)" ; \ + git commit -a -S -m "$(message)" ; \ fi git push @@ -163,11 +163,11 @@ git-aftermath: # file new release on master release-master: go run github.com/aktau/github-release release \ - --user JarryShaw \ - --repo PyPCAPKit \ - --tag "v$(version)" \ - --name "PyPCAPKit v$(version)" \ - --description "$(message)" + --user JarryShaw \ + --repo PyPCAPKit \ + --tag "v$(version)" \ + --name "PyPCAPKit v$(version)" \ + --description "$(message)" # run pre-distribution process dist-pre: update @@ -175,9 +175,9 @@ dist-pre: update # run post-distribution process dist-post: $(MAKE) message="$(message)" DIR=release \ - clean dist git-tag git-upload + clean dist git-tag git-upload $(MAKE) message="$(message)" \ - git-upload release update-maintainer git-aftermath + git-upload release update-maintainer git-aftermath # run full distribution process dist-all: dist-pre dist-prep dist-post diff --git a/docker/Dockerfile b/docker/Dockerfile index 979b262e6..4ddcef0d7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,6 +1,6 @@ # basic info FROM library/ubuntu -LABEL version 2019.03.02 +LABEL version 2019.03.07 LABEL description "Ubuntu Environment" # prepare environment diff --git a/setup.py b/setup.py index 31e294702..08db0db17 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ from distutils.core import setup # version string -__version__ = '0.14.0' +__version__ = '0.14.1' # README with open('README.md', encoding='utf-8') as file: diff --git a/src/__init__.py b/src/__init__.py index 349dc3a81..ab096c471 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -53,16 +53,22 @@ dump utilities for `pcapkit` implementation """ -# set up sys.excepthook import os +import warnings import tbtrim -from pcapkit.utilities.exceptions import BaseError +from pcapkit.utilities.exceptions import DEVMODE, BaseError -ROOT = os.path.dirname(os.path.relpath(__file__)) -tbtrim.set_trim_rule(lambda filename: ROOT in os.path.realpath(filename), - exception=BaseError, strict=False) +# set up sys.excepthook +if DEVMODE: + warnings.showwarning('development mode enabled', RuntimeWarning, + filename=__file__, lineno=0, + line=f"PCAPKIT_DEVMODE={os.environ['PCAPKIT_DEVMODE']}") +else: + ROOT = os.path.dirname(os.path.relpath(__file__)) + tbtrim.set_trim_rule(lambda filename: ROOT in os.path.realpath(filename), + exception=BaseError, strict=False) # All Reference import pcapkit.__all__ as all # pylint: disable diff --git a/src/utilities/exceptions.py b/src/utilities/exceptions.py index 3aa210bfc..6b4971812 100644 --- a/src/utilities/exceptions.py +++ b/src/utilities/exceptions.py @@ -33,6 +33,15 @@ 'ModuleNotFound', # ModuleNotFoundError ] +# boolean mappings +BOOLEAN_STATES = {'1': True, '0': False, + 'yes': True, 'no': False, + 'true': True, 'false': False, + 'on': True, 'off': False} + +# DEVMODE flag +DEVMODE = BOOLEAN_STATES.get(os.environ.get('PCAPKIT_DEVMODE', '').lower(), False) + def stacklevel(): """Fetch current stack level.""" @@ -62,14 +71,15 @@ class BaseError(Exception): """ def __init__(self, *args, **kwargs): - index = stacklevel() - quiet = kwargs.pop('quiet', False) - if not quiet and index: - fmt_exc = traceback.format_exc(limit=-index) - if len(fmt_exc.splitlines(True)) > 1: - print(fmt_exc, file=sys.stderr) - - sys.tracebacklimit = 0 + if DEVMODE: + index = stacklevel() + quiet = kwargs.pop('quiet', False) + if not quiet and index: + fmt_exc = traceback.format_exc(limit=-index) + if len(fmt_exc.splitlines(True)) > 1: + print(fmt_exc, file=sys.stderr) + else: + sys.tracebacklimit = 0 super().__init__(*args, **kwargs)