Skip to content

Instantly share code, notes, and snippets.

View GenevieveBuckley's full-sized avatar

Genevieve Buckley GenevieveBuckley

  • Monash University
  • Melbourne
View GitHub Profile
@GenevieveBuckley
GenevieveBuckley / link_with_spaces.rst
Created April 3, 2019 23:55
Link with spaces in restructured text (.rst) files
@GenevieveBuckley
GenevieveBuckley / logfile.py
Last active July 29, 2019 23:32
Log all uncaught exceptions to file with sys.excepthook
import os
import logging
import sys
import time
import traceback
from mypackage import __version__
def _exception_handler(error_type, error_value, error_traceback):
@GenevieveBuckley
GenevieveBuckley / skimage_3d_compatibility.py
Last active April 16, 2019 12:47 — forked from emmanuelle/skimage_3d_compatibility.py
Inspect which functions of scikit-image are compatible with 3-D arrays.
import numpy as np
import inspect
from skimage import exposure, feature, filters, measure, morphology, \
restoration, segmentation, transform, util
def only_one_nondefault(args):
"""
Returns True if the function has only one non-keyword parameter,
False otherwise.
@GenevieveBuckley
GenevieveBuckley / pytest-mpl.txt
Created April 30, 2019 06:57
Testing matplotlib image outputs with the pytest-mpl plugin
# To generate baseline images
py.test --mpl-generate-path=baseline
# To run pytest with the matplotlib plugin
py.test --mpl
# See full details here
# https://github.com/matplotlib/pytest-mpl
@GenevieveBuckley
GenevieveBuckley / 2to3
Created April 30, 2019 07:19
Converting python 2 code to python 3
For the whole repository:
$ 2to3 --output-dir=python3-version/mycode -W -n python2-version/mycode
For a single file:
$ 2to3 filename.py
# See details at:
# https://docs.python.org/2/library/2to3.html
# Stack overflow
@GenevieveBuckley
GenevieveBuckley / python_wheels.txt
Created May 1, 2019 00:28
Creating python wheels
# Installing a python wheel
pip install some-package.whl
# Creating a python wheel
pip wheel --wheel-dir=path/to/save/wheel wheel_filename
# See https://python101.pythonlibrary.org/chapter39_wheels.html
# PEP427 (describes the wheel format)
@GenevieveBuckley
GenevieveBuckley / .gitignore
Created May 2, 2019 02:03
Python .gitignore template file
# Sphinx docs
docs/_build
# Logging
logs/*
!logs/.gitkeep
# Testing and coverage
cov.xml
.pytest_cache/
@GenevieveBuckley
GenevieveBuckley / python_builds.txt
Created May 21, 2019 06:09
Building wheels and exe files with python
# Build a wheel (outputs to dist/ directory)
python setup.py sdist bdist_wheel
# Build with pyinstaller
pyinstaller myfile.spec -w -F -y
## If no spec file currently exists
pyinstaller mypackage/main.py
@GenevieveBuckley
GenevieveBuckley / app.py
Created June 13, 2019 06:49
Non-blocking PyQt while loop callback using threading
"""Example of a non-blocking PyQt while loop callback using threading
Example adapted from this StackOverflow answer:
https://stackoverflow.com/questions/22340230/python-pyqt-how-run-while-loop-without-locking-main-dialog-window?answertab=votes#tab-top
Ported from PyQt4 to PyQt5 using the tool pyqt4topyqt5:
https://github.com/rferrazz/pyqt4topyqt5
"""
import os
@GenevieveBuckley
GenevieveBuckley / QImageViewer.py
Created June 13, 2019 07:13 — forked from acbetter/QImageViewer.py
Image Viewer Example by PyQt5 and Python 3
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QImage, QPixmap, QPalette, QPainter
from PyQt5.QtPrintSupport import QPrintDialog, QPrinter
from PyQt5.QtWidgets import QLabel, QSizePolicy, QScrollArea, QMessageBox, QMainWindow, QMenu, QAction, \
qApp, QFileDialog