diff --git a/.github/workflows/valid-style.yml b/.github/workflows/valid-style.yml index 3e15eb1240a..91ab7339046 100644 --- a/.github/workflows/valid-style.yml +++ b/.github/workflows/valid-style.yml @@ -13,8 +13,7 @@ concurrency: jobs: - # Validate that the code can be run on all the Python versions - # supported by Spack + # Validate that the code can be run on all the Python versions supported by Spack validate: runs-on: ubuntu-latest steps: @@ -87,6 +86,7 @@ jobs: spack -d bootstrap now --dev spack -d style -t black spack unit-test -V + # Check we don't make the situation with circular imports worse import-check: runs-on: ubuntu-latest steps: @@ -146,3 +146,21 @@ jobs: else printf '\033[1;32mImport check passed: %s <= %s\033[0m\n' "$edges_after" "$edges_before" fi + + # Further style checks from pylint + pylint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 + with: + fetch-depth: 0 + - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b + with: + python-version: '3.13' + cache: 'pip' + - name: Install Python packages + run: | + pip install --upgrade pip setuptools pylint + - name: Pylint (Spack Core) + run: | + pylint -j 4 --disable=all --enable=unspecified-encoding --ignore-paths=lib/spack/external lib diff --git a/lib/spack/llnl/util/tty/color.py b/lib/spack/llnl/util/tty/color.py index 51a5a1b5b1e..edba41dc55c 100644 --- a/lib/spack/llnl/util/tty/color.py +++ b/lib/spack/llnl/util/tty/color.py @@ -161,7 +161,7 @@ def _err_check(result, func, args): ) # Use conout$ here to handle a redirectired stdout/get active console associated # with spack - with open(r"\\.\CONOUT$", "w") as conout: + with open(r"\\.\CONOUT$", "w", encoding="utf-8") as conout: # Link above would use kernel32.GetStdHandle(-11) however this would not handle # a redirected stdout appropriately, so we always refer to the current CONSOLE out # which is defined as conout$ on Windows. diff --git a/lib/spack/llnl/util/tty/log.py b/lib/spack/llnl/util/tty/log.py index 612d9ff380e..25e17537013 100644 --- a/lib/spack/llnl/util/tty/log.py +++ b/lib/spack/llnl/util/tty/log.py @@ -762,7 +762,7 @@ def __enter__(self): self.reader = open(self.logfile, mode="rb+") # Dup stdout so we can still write to it after redirection - self.echo_writer = open(os.dup(sys.stdout.fileno()), "w") + self.echo_writer = open(os.dup(sys.stdout.fileno()), "w", encoding=sys.stdout.encoding) # Redirect stdout and stderr to write to logfile self.stderr.redirect_stream(self.writer.fileno()) self.stdout.redirect_stream(self.writer.fileno()) diff --git a/lib/spack/spack/test/llnl/util/filesystem.py b/lib/spack/spack/test/llnl/util/filesystem.py index 4b05c0ea22e..d6609b18d56 100644 --- a/lib/spack/spack/test/llnl/util/filesystem.py +++ b/lib/spack/spack/test/llnl/util/filesystem.py @@ -506,9 +506,7 @@ def test_filter_files_with_different_encodings(regex, replacement, filename, tmp # This should not raise exceptions fs.filter_file(regex, replacement, target_file, **keyword_args) # Check the strings have been replaced - extra_kwargs = {"errors": "surrogateescape"} - - with open(target_file, mode="r", **extra_kwargs) as f: + with open(target_file, mode="r", encoding="utf-8", errors="surrogateescape") as f: assert replacement in f.read() @@ -558,9 +556,7 @@ def test_filter_files_multiple(tmpdir): fs.filter_file(r"\", "", target_file) fs.filter_file(r"\", "", target_file) # Check the strings have been replaced - extra_kwargs = {"errors": "surrogateescape"} - - with open(target_file, mode="r", **extra_kwargs) as f: + with open(target_file, mode="r", encoding="utf-8", errors="surrogateescape") as f: assert "" not in f.read() assert "" not in f.read() assert "" not in f.read() diff --git a/lib/spack/spack/test/modules/conftest.py b/lib/spack/spack/test/modules/conftest.py index 1feee7adcba..1a490548d37 100644 --- a/lib/spack/spack/test/modules/conftest.py +++ b/lib/spack/spack/test/modules/conftest.py @@ -23,7 +23,7 @@ def _impl(spec_like, module_set_name="default", explicit=True): generator = writer_cls(spec, module_set_name, explicit) generator.write(overwrite=True) written_module = pathlib.Path(generator.layout.filename) - content = written_module.read_text().splitlines() + content = written_module.read_text(encoding="utf-8").splitlines() generator.remove() return content diff --git a/lib/spack/spack/util/executable.py b/lib/spack/spack/util/executable.py index 35238059b28..7bbd119cbeb 100644 --- a/lib/spack/spack/util/executable.py +++ b/lib/spack/spack/util/executable.py @@ -203,7 +203,7 @@ def process_cmd_output(out, err): def streamify(arg, mode): if isinstance(arg, str): - return open(arg, mode), True + return open(arg, mode), True # pylint: disable=unspecified-encoding elif arg in (str, str.split): return subprocess.PIPE, False else: