Skip to content

Instantly share code, notes, and snippets.

@Anthchirp
Anthchirp / pysect.py
Created May 19, 2021 12:19
bisecting pytest
# An unpolished script to do pytest-bisection
# By this I don't mean bisecting a repository on commits using pytest,
# but rather bisecting the powerset of tests using pytest.
# In other words:
# This script takes a list of tests where the last one fails
# You already ran the test in isolation, but then the test passes
# Therefore some *other* test causes your test to fail
# This script finds the necessary preconditions that causes your test to fail
# I said "unpolished". You need to edit pytest_start and pytest_arg to match
#!/bin/bash
# find python classes that are declared once and then list files where the name is referenced
for candidate in \
$(grep --exclude-dir=".git" --exclude-dir="__pycache__" -hoPR '^ *class \K[a-zA-Z0-9_]*' . | \
sort | uniq -c | grep " 1 " | cut -c 9-)
do
REFERENCES=$(grep --exclude-dir=".git" --exclude-dir="__pycache__" -c -cR $candidate . | grep -v ":0")
if [ "$(wc -l <<< "$REFERENCES")" -eq "1" ]; then
if [[ $REFERENCES == *":1" ]]; then
@Anthchirp
Anthchirp / openclose.py
Created December 5, 2019 14:03
Nice formatting for `strace -e trace=open,close`
from __future__ import absolute_import, division, print_function
import re
import sys
re_close = re.compile(r"close\(([^)]+)\)")
re_open = re.compile(r'open\("([^"]+)"[^)]*\) += +([^ ]+)( .*)?')
open_files = {}
@Anthchirp
Anthchirp / cpython.patch
Created April 21, 2019 16:11
🥧thon accepts any unicode variable name because better
diff --git a/Modules/main.c b/Modules/main.c
index e3683b9..a60a5c9 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -1238,7 +1238,7 @@ pymain_header(_PyMain *pymain)
return;
}
- fprintf(stderr, "Python %s on %s\n", Py_GetVersion(), Py_GetPlatform());
+ fprintf(stderr, "Pie-thon %s on %s\n", Py_GetVersion(), Py_GetPlatform());
@Anthchirp
Anthchirp / .bashrc_local
Created February 7, 2019 09:18
GIT prompt
function __ps1_git () {
# preserve exit status
local exit=$?
local repo_info
repo_info="$(git rev-parse --git-dir --is-inside-git-dir --is-inside-work-tree 2>/dev/null)"
if [ -z "$repo_info" ]; then
return $exit
fi
from __future__ import absolute_import, division, print_function
import itertools
import operator
ops = {operator.add: '+', operator.sub: '-', operator.mul: '*', operator.truediv: '/'}
def run(a, b, c, d, op1, op2, op3, order):
try:
if order == 1:
return op1(a, op2(b, op3(c, d)))
@Anthchirp
Anthchirp / whowrotedis.sh
Last active June 8, 2018 18:01
Code ownership
find . -type f | grep "\.\(py\|cc\|h\)$" | xargs -n 1 git blame -w -c -C | cut -d"(" -f 2 | cut -d")" -f 1 | sed -e "s/^\([a-zA-Z .]*\).*/\\1/" | sort | uniq -c | sort -n
#!/bin/sh
wget https://raw.githubusercontent.com/cctbx/cctbx_project/master/libtbx/auto_build/bootstrap.py
python bootstrap.py --builder=dials hot update base build
@Anthchirp
Anthchirp / .bashrc_local
Created April 26, 2017 08:26
su && screen
# Getting screen to work on a user account you su'd to.
function screen() {
/usr/bin/script -q -c "/usr/bin/screen ${*}" /dev/null
}
@Anthchirp
Anthchirp / bork.txt
Created January 13, 2017 14:45
dials 1.4.2 test breakage
libtbx.python "/scratch/jenkins_slave/workspace/dials_release_test/dials-v1-4-2/modules/xia2_regression/test/xia2/tst_mad_example.py" dials [FAIL]
Time: 910.85
Return code: 1
OKs: 0
Standard error:
Traceback (most recent call last):
File "/scratch/jenkins_slave/workspace/dials_release_test/dials-v1-4-2/build/../modules/xia2/command_line/xia2_main.py", line 282, in run
xinfo = xia2_main()
File "/scratch/jenkins_slave/workspace/dials_release_test/dials-v1-4-2/build/../modules/xia2/command_line/xia2_main.py", line 233, in xia2_main
Chatter.write(xinfo.get_output(), strip=False)