Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Automated Bug Reporting #92

Merged
merged 33 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c0c5c3f
ENH: Helper function to find current log files
Mar 23, 2018
bc9d60b
TST: Add test to find log files from test session
Mar 23, 2018
9ee76d1
TST: Add a test for generating bug report
Mar 23, 2018
9ff2c53
DEV: Github issue Jinja2 template
Mar 23, 2018
ad2aa12
MAINT: Keep internal variable for report directory
Mar 24, 2018
b98dedc
BLD: Explicit dependencies on requests, simplejson and jinja2
Mar 24, 2018
335d145
ENH: JSON report saving and GitHub posting
Mar 24, 2018
257afd0
TST: Test GitHub posting with fake session
Mar 24, 2018
6513714
FIX: Rejoin textwrap from editor
Mar 24, 2018
8810353
STY: Various PEP8 violations
Mar 24, 2018
f487ed2
BLD: Include jinja2 template in package
Mar 26, 2018
29ffd9c
MAINT: Try / except block for no IPython history
Mar 26, 2018
d3d555f
ENH: Create report_bug magics
Mar 26, 2018
47fd7ce
MAINT: Register report_bug magics in IPython shell
Mar 26, 2018
9e7f59d
ENH: post-issues command line function
Mar 26, 2018
b83111a
DOC: Full API documentation and module explanation
Mar 27, 2018
6175dbf
DOC: Add get_session_logfiles to API
Mar 27, 2018
bd8da30
DOC: Break up utils into sections, include bug reporting
Mar 27, 2018
01ecf5f
DOC: Full API of bug.py available in autosummary
Mar 27, 2018
b926680
MAINT: Switch to official Bug-Reports repository
Mar 27, 2018
0adc78c
REV: Remove CRON job post-issues script
Mar 27, 2018
7c9ff14
DOC: Various typos and formatting issues
Mar 27, 2018
5b38028
REV: Remove bug report information for Useful Utilities
Mar 27, 2018
6d805e0
DOC: Reorganize placement of various docstrings
Mar 27, 2018
5f72c03
DOC: Remove references to CRON job
Mar 27, 2018
6113df5
FIX: Forgotten description in exception logging
Mar 27, 2018
1309b0d
MAINT: Clarify various comments
Mar 27, 2018
666bc8a
MAINT: Check EDITOR environment variable instead of assuming vim
Mar 27, 2018
4f59dab
MAINT: Place try/except block in lower level get_session_logfiles
Mar 27, 2018
f5c0113
STY: One blank line instead of two between imports and logger init
Mar 27, 2018
ac0715e
TST: Add explicit test for dev_pkgs and CONDA env variables
Mar 28, 2018
83d0ace
FIX: Return empty list even if PYTHONPATH is not found
Mar 28, 2018
56d7601
TST: Add mock test for get_text_from_editor
Mar 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include versioneer.py
include hutch_python/_version.py
include hutch_python/templates/*
include hutch_python/logging.yml
include hutch_python/cookiecutter/*
include hutch_python/cookiecutter/*/*
Expand Down
56 changes: 56 additions & 0 deletions bin/post-issues
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python
import os
import getpass
import logging
import argparse

from hutch_python.constants import BUG_REPORT_PATH
from hutch_python.bug import post_to_github

logger = logging.getLogger(__name__)


description = """\
Post all of the stored issue to https://github.com/pcdshub/Bug-Reports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo, issue should be issues


This requires a valid GitHub account that is authorized to post issues in
the pcdshub organization. By default this script will be run automatically at a
frequent interval, but if that is failing or you feel the need to immediately
push an issue upstream this script can be utilized.


"""


def main():
"""Post all issues in BUG_REPORT_PATH"""
# Create argument parser
fclass = argparse.RawDescriptionHelpFormatter
parser = argparse.ArgumentParser(epilog=description,
formatter_class=fclass)
parser.add_argument('-u', '--user', dest='username',
default=None,
help="Username for GitHub account")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is an optional argument, which is odd because we don't prompt the user for it if omitted. I expect the script breaks if this isn't passed.

parser.add_argument('-p', '--pw', dest='password',
default=None,
help='Password for GitHub account. This will be '
'queried for if not entered at call time.')
args = parser.parse_args()
# Ask for the password once so if it isn't asked to repetitively
pw = args.password or getpass.getpass()
# Run post_to_github on every stored issue
for issue in os.listdir(BUG_REPORT_PATH):
if issue.endswith('.json'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is anything else in this folder? It seems odd to me to check for the file extension when that isn't sufficient to guarantee that we have a well-formed bug report. I guess it's a good first cut though if someone mangles the BUG_REPORT_PATH

try:
logger.info('Posting %s ...', issue)
post_to_github(os.path.join(BUG_REPORT_PATH, issue),
user=args.username, pw=pw)
except Exception:
logger.exception("Error posting %s", issue)


if __name__ == '__main__':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test that runs this script? Look for my tests that shell out and call hutch-python. Alternatively, move main into bug.py and test it there.

# Configure logger
logging.basicConfig(level=logging.INFO)
# Post issues
main()
3 changes: 3 additions & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ requirements:
- lightpath >=0.3.0
- cookiecutter >=1.6.0
- matplotlib
- simplejson
- requests
- jinja2

test:
imports:
Expand Down
14 changes: 14 additions & 0 deletions docs/source/bug.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
bug.py
======
Functionality associatted with bug reports
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

associated. This should just be an automodule with a shortened docstring from bug.py.


.. autosummary::
:toctree: generated
:nosignatures:

hutch_python.bug.get_current_environment
hutch_python.bug.get_last_n_commands
hutch_python.bug.get_text_from_editor
hutch_python.bug.report_bug
hutch_python.bug.post_to_github

1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
:caption: Internal API Reference
:hidden:

bug
cache
cli
ipython_log
Expand Down
1 change: 1 addition & 0 deletions docs/source/log_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ log_setup.py
:nosignatures:

setup_logging
get_session_logfiles
get_console_handler
get_console_level
set_console_level
Expand Down
25 changes: 22 additions & 3 deletions docs/source/user_utils.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
Useful Utilities
================

The ``hutch_python.utils`` and ``hutch_python.namespace`` modules have
functions that may be broadly useful.

Reporting Issues
----------------
.. automodule:: hutch_python.bug

.. autofunction:: report_bug

Issue Lifecyle
^^^^^^^^^^^^^^
We can not expect that every operator on the beamline has a valid Github
account. To get around this, when you call `report_bug` we dump a JSON
description of the issue into a standard NFS directory. Then by a regular CRON
job we will post this issue to https://github.com/pcdshub/Bug-Reports. This
leads to a slight delay but also allows to have issues posted by persons
without valid GitHub accounts. Once issues are received on GitHub the
appropriate action will be made by the PCDS staff. This may mean a deeper look
at the linked log files and/or creating a distilled issue or action item in a
different repository.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the bug reporting stuff belongs on this page, it's not a user utility that you'd include in a beamline file. It deserves it's own page before this one on the index.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize this was only for beamline.py utilities. Might suggest a rename if this was your intention.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, the page should be renamed. Even if it would fit on the page, bug reporting still deserves it's own page because of how important it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Bug Reporting page has been created 👍


Safe Loading
------------
`hutch_python.utils.safe_load` can be used as a shortcut for wrapping code
that may or may not succeed to prevent a bad submodule from interrupting the
``hutch-python`` load sequence. This means that if the ``Attenuator`` class is
Expand All @@ -23,6 +40,8 @@ For example, this will complete successfully but show a warning:
The reason for the failure with the full traceback will be saved to the log
file and will be visible in the terminal if you are in `debug mode <debug>`.

User Namespaces
---------------
`hutch_python.namespace.class_namespace` can be used to create your own object
groupings by type. This will find all objects loaded by hutch python plus all
objects in your global environment, and accumulate them if they match a given
Expand Down
Loading