From 77a5451c1f1c7ef5f8321a055994e0e770ae41f6 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Mon, 30 Nov 2020 10:57:36 -0800 Subject: [PATCH] Add flake8 for checking our Python scripts We only have one for now, but we can start enforcing this now. --- .flake8 | 6 ++++++ .github/workflows/{shellcheck.yml => lints.yml} | 13 ++++++++----- rust/bridge/jni/bin/gen_java_decl.py | 11 ++++++----- 3 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 .flake8 rename .github/workflows/{shellcheck.yml => lints.yml} (62%) diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..e476f37d --- /dev/null +++ b/.flake8 @@ -0,0 +1,6 @@ +[flake8] +ignore = + # E501 line too long + E501, + # E741 ambiguous variable name + E741, diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/lints.yml similarity index 62% rename from .github/workflows/shellcheck.yml rename to .github/workflows/lints.yml index adbdd0f3..1c12aeae 100644 --- a/.github/workflows/shellcheck.yml +++ b/.github/workflows/lints.yml @@ -1,19 +1,22 @@ -name: Shellcheck +name: Lints # This is in a separate job because we have shell scripts scattered across all our targets, # *and* some of them have common dependencies. on: push: branches: [ master ] - paths: ['**/*.sh'] + paths: ['**/*.sh', '**/*.py'] pull_request: - branches: [ master ] - paths: ['**/*.sh'] + paths: ['**/*.sh', '**/*.py'] jobs: - build: + lint: + name: Check helper scripts + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - run: pip3 install flake8 - run: shellcheck **/*.sh + - run: python3 -m flake8 . diff --git a/rust/bridge/jni/bin/gen_java_decl.py b/rust/bridge/jni/bin/gen_java_decl.py index 2fd4068d..9fcc30dc 100755 --- a/rust/bridge/jni/bin/gen_java_decl.py +++ b/rust/bridge/jni/bin/gen_java_decl.py @@ -19,7 +19,7 @@ cbindgen = subprocess.Popen(['cbindgen'], cwd=os.path.join(our_abs_dir, '..'), s stdout = str(stdout.decode('utf8')) stderr = str(stderr.decode('utf8')) -ignore_this_warning = re.compile("WARN: Can't find .*\. This usually means that this type was incompatible or not found\.") +ignore_this_warning = re.compile(r"WARN: Can't find .*\. This usually means that this type was incompatible or not found\.") unknown_warning = False @@ -36,7 +36,8 @@ for l in stderr.split('\n'): if unknown_warning: sys.exit(1) -java_decl = re.compile('([a-zA-Z]+) Java_org_signal_client_internal_Native_([A-Z][a-zA-Z]+)_1([A-Za-z0-9]+)\(JNIEnv .?env, JClass class_(, .*)?\);') +java_decl = re.compile(r'([a-zA-Z]+) Java_org_signal_client_internal_Native_([A-Z][a-zA-Z]+)_1([A-Za-z0-9]+)\(JNIEnv .?env, JClass class_(, .*)?\);') + def translate_to_java(typ): # jobject is not given here; instead use a type @@ -60,6 +61,7 @@ def translate_to_java(typ): raise Exception("Don't know what to do with a", typ) + cur_type = None decls = [] @@ -82,9 +84,9 @@ for line in stdout.split('\n'): java_ret_type = translate_to_java(ret_type) java_args = [] - if args != None: + if args is not None: for arg in args.split(', ')[1:]: - (arg_type,arg_name) = arg.split(' ') + (arg_type, arg_name) = arg.split(' ') java_arg_type = translate_to_java(arg_type) java_args.append('%s %s' % (java_arg_type, arg_name)) @@ -102,4 +104,3 @@ if not os.access(native_java, os.F_OK): fh = open(native_java, 'w') fh.write(contents) fh.close() -