Skip to content

Commit

Permalink
Blacken code (#1076)
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl authored Oct 30, 2023
1 parent c62e3c4 commit aa95d20
Show file tree
Hide file tree
Showing 350 changed files with 27,345 additions and 7,957 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Black

env:
PYTHONUNBUFFERED: 1

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install black
run: pip install black==23.7.0

- name: Check code with black
run: black --check --diff --color .
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
![URH image](https://raw.githubusercontent.com/jopohl/urh/master/data/icons/banner.png)

[![CI](https://github.com/jopohl/urh/actions/workflows/ci.yml/badge.svg)](https://github.com/jopohl/urh/actions/workflows/ci.yml)
[![Code style: black](https://img.shields.io/badge/code%20style-black-black)](https://github.com/psf/black)
[![PyPI version](https://badge.fury.io/py/urh.svg)](https://badge.fury.io/py/urh)
[![Packaging status](https://repology.org/badge/tiny-repos/urh.svg)](https://repology.org/project/urh/versions)
[![Blackhat Arsenal 2017](https://rawgit.com/toolswatch/badges/master/arsenal/usa/2017.svg)](http://www.toolswatch.org/2017/06/the-black-hat-arsenal-usa-2017-phenomenal-line-up-announced/)
Expand Down
10 changes: 7 additions & 3 deletions data/build_icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def get_used_icon_names():
with open(sourcefile, "r") as f:
for line in f:
if "QIcon.fromTheme" in line:
icon = line[line.find("QIcon.fromTheme"):]
icon = line[line.find("QIcon.fromTheme") :]
icon = icon.replace('"', "'")
start = icon.find("'") + 1
end = icon.find("'", start)
Expand All @@ -35,7 +35,11 @@ def get_used_icon_names():

def copy_icons(icon_names: set):
target_dir = "/tmp/oxy"
sizes = [s for s in os.listdir(OXYGEN_PATH) if os.path.isdir(os.path.join(OXYGEN_PATH, s))] # 8x8, 22x22 ...
sizes = [
s
for s in os.listdir(OXYGEN_PATH)
if os.path.isdir(os.path.join(OXYGEN_PATH, s))
] # 8x8, 22x22 ...
for size in sizes:
target_size_dir = os.path.join(target_dir, size)
os.makedirs(target_size_dir, exist_ok=True)
Expand All @@ -59,7 +63,7 @@ def copy_icons(icon_names: set):
for size in sizes:
f.write("\n")
f.write("[" + size + "]\n")
f.write("Size=" + size[:size.index("x")] + "\n")
f.write("Size=" + size[: size.index("x")] + "\n")
f.write("\n")

root = ET.Element("RCC")
Expand Down
22 changes: 17 additions & 5 deletions data/check_native_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,33 @@
import importlib
import os
import sys

rc = 0

if sys.platform == "win32":
shared_lib_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), "..", "src/urh/dev/native/lib/shared"))
shared_lib_dir = os.path.realpath(
os.path.join(os.path.dirname(__file__), "..", "src/urh/dev/native/lib/shared")
)
print("Attempting to read", shared_lib_dir)
if os.path.isdir(shared_lib_dir):
os.environ["PATH"] = os.environ.get("PATH", "") + os.pathsep + shared_lib_dir
print("PATH updated")

for sdr in ("AirSpy", "BladeRF", "HackRF", "RTLSDR", "LimeSDR", "PlutoSDR", "SDRPlay", "USRP"):
for sdr in (
"AirSpy",
"BladeRF",
"HackRF",
"RTLSDR",
"LimeSDR",
"PlutoSDR",
"SDRPlay",
"USRP",
):
try:
importlib.import_module('.{}'.format(sdr.lower()), 'urh.dev.native.lib')
print("{:<10} \033[92mSUCCESS\033[0m".format(sdr+":"))
importlib.import_module(".{}".format(sdr.lower()), "urh.dev.native.lib")
print("{:<10} \033[92mSUCCESS\033[0m".format(sdr + ":"))
except ImportError as e:
print("{:<10} \033[91mFAILURE\033[0m ({})".format(sdr+":", e))
print("{:<10} \033[91mFAILURE\033[0m ({})".format(sdr + ":", e))
rc = 1

sys.exit(rc)
7 changes: 4 additions & 3 deletions data/generate_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ def gen(force=False):
# Remove Line: # Form implementation generated from reading ui file '/home/joe/GIT/urh/ui/fuzzing.ui'
# to avoid useless git updates when working on another computer
for line in fileinput.input(out_file_path, inplace=True):
if line.startswith("# Form implementation generated from reading ui file") or line.startswith(
"# Created by: "):
if line.startswith(
"# Form implementation generated from reading ui file"
) or line.startswith("# Created by: "):
continue
if line.strip().startswith("QtCore.QMetaObject.connectSlotsByName("):
# disable auto slot connection, as we do not use it, and it causes crash on python 3.7
continue
print(line, end='')
print(line, end="")

for f in rc_files:
file_path = os.path.join(rc_path, f)
Expand Down
75 changes: 55 additions & 20 deletions data/pyinstaller_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@
import shutil
import sys

HIDDEN_IMPORTS = ["packaging.specifiers", "packaging.requirements", "pkg_resources.py2_warn",
"numpy.core._methods", "numpy.core._dtype_ctypes",
"numpy.random.common", "numpy.random.entropy", "numpy.random.bounded_integers"]
DATA = [("src/urh/dev/native/lib/shared", "."), ("src/urh/plugins", "urh/plugins"), ]
HIDDEN_IMPORTS = [
"packaging.specifiers",
"packaging.requirements",
"pkg_resources.py2_warn",
"numpy.core._methods",
"numpy.core._dtype_ctypes",
"numpy.random.common",
"numpy.random.entropy",
"numpy.random.bounded_integers",
]
DATA = [
("src/urh/dev/native/lib/shared", "."),
("src/urh/plugins", "urh/plugins"),
]
EXCLUDE = ["matplotlib"]


def run_pyinstaller(cmd_list: list, env: list=None):
def run_pyinstaller(cmd_list: list, env: list = None):
cmd = " ".join(cmd_list)
print(cmd, flush=True)

Expand All @@ -20,7 +30,7 @@ def run_pyinstaller(cmd_list: list, env: list=None):
os.system(cmd)


if __name__ == '__main__':
if __name__ == "__main__":
cmd = ["pyinstaller", "--clean"]
if sys.platform == "darwin":
cmd.append("--onefile")
Expand All @@ -38,37 +48,62 @@ def run_pyinstaller(cmd_list: list, env: list=None):
urh_path = os.path.realpath(os.path.join(os.path.dirname(__file__), ".."))

if sys.platform == "darwin":
cmd.append('--icon="{}"'.format(os.path.join(urh_path, "data/icons/appicon.icns")))
cmd.append(
'--icon="{}"'.format(os.path.join(urh_path, "data/icons/appicon.icns"))
)
else:
cmd.append('--icon="{}"'.format(os.path.join(urh_path, "data/icons/appicon.ico")))
cmd.append(
'--icon="{}"'.format(os.path.join(urh_path, "data/icons/appicon.ico"))
)

cmd.extend(["--distpath", "./pyinstaller"])

urh_cmd = cmd + ["--name=urh", "--windowed", "--workpath", "./urh_build",
os.path.join(urh_path, "src/urh/main.py")]

urh_debug_cmd = cmd + ["--name=urh_debug", "--workpath", "./urh_debug_build",
os.path.join(urh_path, "src/urh/main.py")]

cli_cmd = cmd + ["--workpath", "./urh_cli_build",
os.path.join(urh_path, "src/urh/cli/urh_cli.py")]
urh_cmd = cmd + [
"--name=urh",
"--windowed",
"--workpath",
"./urh_build",
os.path.join(urh_path, "src/urh/main.py"),
]

urh_debug_cmd = cmd + [
"--name=urh_debug",
"--workpath",
"./urh_debug_build",
os.path.join(urh_path, "src/urh/main.py"),
]

cli_cmd = cmd + [
"--workpath",
"./urh_cli_build",
os.path.join(urh_path, "src/urh/cli/urh_cli.py"),
]

os.makedirs("./pyinstaller")
if sys.platform == "darwin":
run_pyinstaller(urh_cmd, env=["DYLD_LIBRARY_PATH=src/urh/dev/native/lib/shared"])
run_pyinstaller(
urh_cmd, env=["DYLD_LIBRARY_PATH=src/urh/dev/native/lib/shared"]
)

import plistlib

with open("pyinstaller/urh.app/Contents/Info.plist", "rb") as f:
p = plistlib.load(f)
p["NSHighResolutionCapable"] = True
p["NSRequiresAquaSystemAppearance"] = True
p["NSMicrophoneUsageDescription"] = "URH needs access to your microphone to capture signals via Soundcard."
p[
"NSMicrophoneUsageDescription"
] = "URH needs access to your microphone to capture signals via Soundcard."
with open("pyinstaller/urh.app/Contents/Info.plist", "wb") as f:
plistlib.dump(p, f)

else:
for cmd in [urh_cmd, cli_cmd, urh_debug_cmd]:
run_pyinstaller(cmd)

shutil.copy("./pyinstaller/urh_cli/urh_cli.exe", "./pyinstaller/urh/urh_cli.exe")
shutil.copy("./pyinstaller/urh_debug/urh_debug.exe", "./pyinstaller/urh/urh_debug.exe")
shutil.copy(
"./pyinstaller/urh_cli/urh_cli.exe", "./pyinstaller/urh/urh_cli.exe"
)
shutil.copy(
"./pyinstaller/urh_debug/urh_debug.exe", "./pyinstaller/urh/urh_debug.exe"
)
44 changes: 35 additions & 9 deletions data/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ def cleanup():
Remove all cache directories
:return:
"""
script_dir = os.path.dirname(__file__) if not os.path.islink(__file__) else os.path.dirname(os.readlink(__file__))
script_dir = (
os.path.dirname(__file__)
if not os.path.islink(__file__)
else os.path.dirname(os.readlink(__file__))
)
script_dir = os.path.realpath(os.path.join(script_dir, ".."))
shutil.rmtree(os.path.join(script_dir, "dist"), ignore_errors=True)
shutil.rmtree(os.path.join(script_dir, "tmp"), ignore_errors=True)
Expand All @@ -21,11 +25,19 @@ def cleanup():


def release():
script_dir = os.path.dirname(__file__) if not os.path.islink(__file__) else os.path.dirname(os.readlink(__file__))
script_dir = (
os.path.dirname(__file__)
if not os.path.islink(__file__)
else os.path.dirname(os.readlink(__file__))
)
script_dir = os.path.realpath(os.path.join(script_dir, ".."))
os.chdir(script_dir)

current_branch = check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]).decode("UTF-8").strip()
current_branch = (
check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"])
.decode("UTF-8")
.strip()
)

if current_branch != "master":
print("You can only release from master!")
Expand All @@ -34,7 +46,10 @@ def release():
open(os.path.join(tempfile.gettempdir(), "urh_releasing"), "w").close()

from src.urh import version
version_file = os.path.realpath(os.path.join(script_dir, "src", "urh", "version.py"))

version_file = os.path.realpath(
os.path.join(script_dir, "src", "urh", "version.py")
)

cur_version = version.VERSION
numbers = cur_version.split(".")
Expand All @@ -44,7 +59,7 @@ def release():
for line in fileinput.input(version_file, inplace=True):
if line.startswith("VERSION"):
line = 'VERSION = "{0}" \n'.format(cur_version)
print(line, end='')
print(line, end="")

# Publish new version number
call(["git", "add", version_file])
Expand All @@ -61,16 +76,27 @@ def release():

# Push new tag
call(["git", "tag", "v" + cur_version, "-m", "version " + cur_version])
call(["git", "push", "origin", "--tags"]) # Creates tar package on https://github.com/jopohl/urh/tarball/va.b.c.d
call(
["git", "push", "origin", "--tags"]
) # Creates tar package on https://github.com/jopohl/urh/tarball/va.b.c.d

os.remove(os.path.join(tempfile.gettempdir(), "urh_releasing"))

# region Build docker image and push to DockerHub
os.chdir(os.path.dirname(__file__))
call(["docker", "login"])
call(["docker", "build", "--no-cache",
"--tag", "jopohl/urh:latest",
"--tag", "jopohl/urh:{}".format(cur_version), "."])
call(
[
"docker",
"build",
"--no-cache",
"--tag",
"jopohl/urh:latest",
"--tag",
"jopohl/urh:{}".format(cur_version),
".",
]
)
call(["docker", "push", "jopohl/urh:latest"])
call(["docker", "push", "jopohl/urh:{}".format(cur_version)])
# endregion
Expand Down
Loading

0 comments on commit aa95d20

Please sign in to comment.