Skip to content

Commit

Permalink
fixed --bug-report regression (closes #29)
Browse files Browse the repository at this point in the history
  • Loading branch information
marzer committed Aug 9, 2023
1 parent 4363152 commit bf62413
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 69 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.13.5 - 2023-08-09

- fixed `--bug-report` regression (#29) (@wroyca)

## v0.13.4 - 2023-08-06

- fixed excessive `template<>` noise in details views
Expand Down
140 changes: 72 additions & 68 deletions src/poxy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,71 @@ def make_boolean_optional_arg(args, name, default, help='', **kwargs):
args.set_defaults(**{name: default})


def bug_report():
BUG_REPORT_STRIP_ARGS = (
r'--bug-report',
r'--bug-report-internal',
r'-v',
r'--verbose',
r'--color',
r'--no-color',
r'--colour',
r'--no-colour',
)

bug_report_args = [arg for arg in sys.argv[1:] if arg not in BUG_REPORT_STRIP_ARGS]
bug_report_zip = (Path.cwd() / r'poxy_bug_report.zip').resolve()

print(r'Preparing output paths')
delete_directory(paths.BUG_REPORT_DIR)
delete_file(bug_report_zip)
os.makedirs(str(paths.BUG_REPORT_DIR), exist_ok=True)

print(r'Invoking poxy')
result = subprocess.run(
args=[r'poxy', *bug_report_args, r'--bug-report-internal', r'--verbose'],
cwd=str(Path.cwd()),
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding='utf-8',
)

if result.stdout is not None:
print(r'Writing stdout')
with open(paths.BUG_REPORT_DIR / r'stdout.txt', r'w', newline='\n', encoding=r'utf-8') as f:
f.write(result.stdout)

if result.stderr is not None:
print(r'Writing stderr')
with open(paths.BUG_REPORT_DIR / r'stderr.txt', r'w', newline='\n', encoding=r'utf-8') as f:
f.write(result.stderr)

print(r'Writing metadata')
with open(paths.BUG_REPORT_DIR / r'metadata.txt', r'w', newline='\n', encoding=r'utf-8') as f:
f.write(f'version: {VERSION_STRING}\n')
f.write(f'args: {bug_report_args}\n')
f.write(f'returncode: {result.returncode}\n')

# zip file
print(r'Zipping files')
with zipfile.ZipFile(str(bug_report_zip), 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zip:
file_prefix_len = len(str(paths.BUG_REPORT_DIR))
for file in get_all_files(paths.BUG_REPORT_DIR, recursive=True):
if file.suffix is not None and file.suffix.lower() in (r'.pyc',):
continue
relative_file = str(file)[file_prefix_len:].replace('\\', '/').strip('/')
zip.write(file, arcname=rf'poxy_bug_report/{relative_file}')

print(r'Cleaning up')
delete_directory(paths.BUG_REPORT_DIR)

print(
f'Zip generated: {bug_report_zip}\n'
'Please attach this file when you make a report at github.com/marzer/poxy/issues, thanks!'
)


def main(invoker=True):
"""
The entry point when the library is invoked as `poxy`.
Expand All @@ -92,6 +157,7 @@ def main(invoker=True):
# --------------------------------------------------------------
# public user-facing arguments
# --------------------------------------------------------------

args.add_argument(
r'config',
type=Path,
Expand Down Expand Up @@ -139,9 +205,11 @@ def main(invoker=True):
args.add_argument(
r'--bug-report', action=r'store_true', help=r"captures all output in a zip file for easier bug reporting." #
)

# --------------------------------------------------------------
# hidden/developer-only/deprecated/diagnostic arguments
# --------------------------------------------------------------

args.add_argument(r'--where', action=r'store_true', help=argparse.SUPPRESS) #
args.add_argument(r'--nocleanup', action=r'store_true', help=argparse.SUPPRESS) #
args.add_argument(r'--noassets', action=r'store_true', help=argparse.SUPPRESS) #
Expand Down Expand Up @@ -212,72 +280,8 @@ def main(invoker=True):
# bug report invocation
# --------------------------------------------------------------

bug_report_directory = (Path.cwd() / r'poxy_bug_report').resolve()
bug_report_zip = (Path.cwd() / r'poxy_bug_report.zip').resolve()

if args.bug_report:
BUG_REPORT_STRIP_ARGS = (
r'--bug-report',
r'--bug-report-internal',
r'-v',
r'--verbose',
r'--color',
r'--no-color',
r'--colour',
r'--no-colour',
)

bug_report_args = [arg for arg in sys.argv[1:]]
bug_report_args_stripped = [arg for arg in bug_report_args if arg not in BUG_REPORT_STRIP_ARGS]

print(r'Preparing output paths')
delete_directory(bug_report_directory)
delete_file(bug_report_zip)
os.makedirs(str(bug_report_directory), exist_ok=True)

print(r'Invoking poxy')
result = subprocess.run(
args=[r'poxy', *bug_report_args, r'--bug-report-internal', r'--verbose'],
cwd=str(Path.cwd()),
check=False,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
encoding='utf-8',
)

if result.stdout is not None:
print(r'Writing stdout')
with open(bug_report_directory / r'stdout.txt', r'w', newline='\n', encoding=r'utf-8') as f:
f.write(result.stdout)

if result.stderr is not None:
print(r'Writing stderr')
with open(bug_report_directory / r'stderr.txt', r'w', newline='\n', encoding=r'utf-8') as f:
f.write(result.stderr)

print(r'Writing metadata')
with open(bug_report_directory / r'metadata.txt', r'w', newline='\n', encoding=r'utf-8') as f:
f.write(f'version: {VERSION_STRING}\n')
f.write(f'args: {bug_report_args_stripped}\n')
f.write(f'returncode: {result.returncode}\n')

# zip file
print(r'Zipping files')
with zipfile.ZipFile(str(bug_report_zip), 'w', compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zip:
file_prefix_len = len(str(bug_report_directory))
for file in get_all_files(bug_report_directory, recursive=True):
if file.suffix is not None and file.suffix.lower() in (r'.pyc',):
continue
relative_file = str(file)[file_prefix_len:].replace('\\', '/').strip('/')
zip.write(file, arcname=rf'poxy_bug_report/{relative_file}')

print(r'Cleaning up')
delete_directory(bug_report_directory)

print(
f'Zip generated: {bug_report_zip}\n'
'Please attach this file when you make a report at github.com/marzer/poxy/issues, thanks!'
)
bug_report()
return

# --------------------------------------------------------------
Expand All @@ -291,9 +295,8 @@ def main(invoker=True):
output_dir = Path.cwd()
temp_dir = None
if args.bug_report_internal:
output_dir = bug_report_directory / r'output'
temp_dir = bug_report_directory / r'temp'
args.verbose = True
output_dir = paths.BUG_REPORT_DIR
temp_dir = paths.BUG_REPORT_DIR / r'temp'
args.nocleanup = True

with ScopeTimer(r'All tasks', print_start=False, print_end=True) as timer:
Expand All @@ -313,6 +316,7 @@ def main(invoker=True):
theme=args.theme,
copy_assets=not args.noassets,
temp_dir=temp_dir,
bug_report=bool(args.bug_report_internal),
# kwargs:
xml_v2=args.xml_v2,
)
Expand Down
3 changes: 3 additions & 0 deletions src/poxy/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,6 @@

TEMP = Path(tempfile.gettempdir(), r'poxy')
"""A global temp directory shared by all instances of poxy."""

BUG_REPORT_DIR = (TEMP / r'bug_report').resolve()
"""Directory used for assembling bug reports."""
4 changes: 4 additions & 0 deletions src/poxy/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@ def __init__(
theme: str,
copy_assets: bool,
temp_dir: Path = None,
bug_report: bool = False,
**kwargs,
):
self.logger = logger
Expand All @@ -1183,6 +1184,7 @@ def __init__(
self.cleanup = bool(cleanup)
self.copy_assets = bool(copy_assets)
self.verbose_logger = logger if self.__verbose else None
self.bug_report = bool(bug_report)

self.info(rf'Poxy v{VERSION_STRING}')

Expand Down Expand Up @@ -1252,6 +1254,8 @@ def __init__(
self.config_path = Path(self.config_path, r'poxy.toml')
if not self.config_path.exists() or not self.config_path.is_file():
raise Error(rf"Config '{self.config_path}' did not exist or was not a file")
if self.bug_report:
copy_file(self.config_path, paths.BUG_REPORT_DIR)
assert self.config_path.is_absolute()
self.verbose_value(r'Context.config_path', self.config_path)

Expand Down
2 changes: 2 additions & 0 deletions src/poxy/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,7 @@ def run(
theme: str = None,
copy_assets: bool = True,
temp_dir: Path = None,
bug_report: bool = False,
**kwargs,
):
timer = lambda desc: ScopeTimer(desc, print_start=True, print_end=context.verbose_logger)
Expand All @@ -1640,6 +1641,7 @@ def run(
theme=theme,
copy_assets=copy_assets,
temp_dir=temp_dir,
bug_report=bug_report,
**kwargs,
) as context:
preprocess_doxyfile(context)
Expand Down
2 changes: 1 addition & 1 deletion src/poxy/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.4
0.13.5

0 comments on commit bf62413

Please sign in to comment.