From d25a29ab5091cf71654f1699661a94e2b3cbeea8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 10 Feb 2025 10:08:12 +0100 Subject: [PATCH 1/2] GitHub Actions: Lint Python code only for SyntaxErrors Turn off 800+ lint rules to only look for Python SyntaxErrors. * https://docs.astral.sh/ruff --- .github/workflows/ci.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..d2e90f4 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +# This Action uses minimal steps to run in ~5 seconds to rapidly: +# lint Python code using ruff which provides intuitive GitHub Annotations to contributors. +# https://docs.astral.sh/ruff/ + +name: ci +on: + push: + # branches: [main] + pull_request: + # branches: [main] +jobs: + ruff: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: astral-sh/ruff-action@v3 + with: + args: check --ignore=ALL # Turn off 800+ lint rules to only look for Python SyntaxErrors. From 4844e43c9f313d39976fbb3cc9352706efc8b3bf Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 10 Feb 2025 10:29:37 +0100 Subject: [PATCH 2/2] uv tool run --python=3.12 --from=future futurize --stage1 --write . --- capitulos/code/11-pythonic-obj/private/expose.py | 4 +++- capitulos/code/11-pythonic-obj/private/leakprivate.py | 6 ++++-- capitulos/code/11-pythonic-obj/private/no_respect.py | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/capitulos/code/11-pythonic-obj/private/expose.py b/capitulos/code/11-pythonic-obj/private/expose.py index 1db9612..b7f605d 100755 --- a/capitulos/code/11-pythonic-obj/private/expose.py +++ b/capitulos/code/11-pythonic-obj/private/expose.py @@ -1,9 +1,11 @@ #!/usr/bin/env jython # NOTE: Jython is still Python 2.7 in late2020 +from __future__ import print_function + import Confidential message = Confidential('top secret text') secret_field = Confidential.getDeclaredField('secret') secret_field.setAccessible(True) # break the lock! -print 'message.secret =', secret_field.get(message) +print('message.secret =', secret_field.get(message)) diff --git a/capitulos/code/11-pythonic-obj/private/leakprivate.py b/capitulos/code/11-pythonic-obj/private/leakprivate.py index 572ef77..d4dc2bb 100644 --- a/capitulos/code/11-pythonic-obj/private/leakprivate.py +++ b/capitulos/code/11-pythonic-obj/private/leakprivate.py @@ -1,6 +1,8 @@ #!/usr/bin/env jython # NOTE: Jython is still Python 2.7 in late2020 +from __future__ import print_function + from java.lang.reflect import Modifier import Confidential @@ -10,5 +12,5 @@ # list private fields only if Modifier.isPrivate(field.getModifiers()): field.setAccessible(True) # break the lock - print 'field:', field - print '\t', field.getName(), '=', field.get(message) + print('field:', field) + print('\t', field.getName(), '=', field.get(message)) diff --git a/capitulos/code/11-pythonic-obj/private/no_respect.py b/capitulos/code/11-pythonic-obj/private/no_respect.py index 39ae7eb..1f47043 100644 --- a/capitulos/code/11-pythonic-obj/private/no_respect.py +++ b/capitulos/code/11-pythonic-obj/private/no_respect.py @@ -9,6 +9,7 @@ Set this to false and Jython provides access to non-public fields, methods, and constructors of Java objects. """ +from __future__ import print_function import Confidential @@ -16,4 +17,4 @@ for name in dir(message): attr = getattr(message, name) if not callable(attr): # non-methods only - print name + '\t=', attr + print(name + '\t=', attr)