mirror-cockpit-project-cockpit/.github/codeql-config.yml
Allison Karlitskaya 4a9e30bc86 all: replace import parent with an interpreter line hack
We'd like to run our executable python scripts using our new `pywrap`
feature as a better way to get their PYTHONPATH setup properly.  This
script lives in our source tree, at a fixed relative location to each
script that we're interested in, but has no absolute system path.

The #!interpreter syntax does supports relative paths, but they are
resolved relative to the current working directory, not relative to the
file in which they appear, which makes this feature pretty useless.

There are some tricks we can do to get our designed 'relative'
behaviour, though.

Something like this works:

    #!/usr/bin/env -S sh -c '"${0%/*}/pywrap" "$0"'

but it causes various file auto-detection schemes (including our own
test/static-code) to improperly conclude that this is a shell script,
rather than a Python script.  (n)vim also gets it wrong for highlighting
and linting purposes.

Fortunately there's a somewhat longer, but still acceptable version of
this we can do in Python:

    #!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/pywrap", sys.argv)

This fits well under our 118 column limit.

Note that unlike `sh`, the `-c` option in Python doesn't require the
script to be passed as a separate argument, which means we don't need to
use the non-POSIX splitting tricks of `/usr/bin/env -S`.

Note also: it appears as though our hardcoding of /usr/bin/python3 here
might be venv-unfriendly, but it's not: /usr/bin/python3 (which surely
exists) is used only for running this one tiny fragment of code.  Our
pywrap script itself finds python3 in the path.

Let's move all of our previous users of `import parent` over to the new
approach.

We can remove a couple of `parent.py` symlinks we had lying
around, as well.

We also remove `parent.py` itself, since otherwise vulture complains
about it being unused.  Subprojects will be forced to adjust on upgrade.

Remove a CodeQL exemption that was necessitated by our `import parent`
shenanigans.
2023-05-26 16:17:29 +02:00

10 lines
322 B
YAML

query-filters:
- exclude:
# complains about `...` method bodies and `await`, i.e. mostly false positives
id: py/ineffectual-statement
- exclude:
# TODO: these are nice to fix, but not that important
id: py/empty-except
- exclude:
# this is a matter of taste
id: py/redundant-else