Since I don't have Python 3.14 on my system (yet), here are the steps I
used to reproduce:
sudo dnf install python3.14
python3.14 -m venv /tmp/py3.14
source /tmp/py3.14/bin/activate
pip install yaml pathspec
python3.14 -m unittest discover
# or
python3.14 -m unittest tests.test_cli.CommandLineTestCase.test_run_default_format_output_in_tty
This commit fixes that by piping *only* `sys.stdout`, not `sys.stderr`
too. I'm not sure why I wrote this code in 2016 (see commit a2c68fdf),
but the new one makes more sense to me now.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2336947
This is a simple preparation for the next commit, to get rid of
low-level `fcntl.fcntl()` calls, since `os.set_blocking()` now exists
(since Python 3.5).
Since yamllint version 0.5.2 (in 2016, just after yamllint was created)
this example in documentation doesn't work. Indeed, commit dbbecb5
(which aimed to solve another problem) removed the ability to import
yamllint submodules directly.
This commit makes it clearer inside documentation.
Fixes https://github.com/adrienverge/yamllint/issues/698
Commit 2344380 "Cleanly skip broken symlinks that are ignored" fixed a
problem on symbolic links but also introduced a change on how ignored
files should be treated, depending on whether they're explicitely passed
as command-line arguments or not [^1].
This change is annoying for users that dynamically build the list of
files to pass as arguments, e.g. [^2]:
find -name '*\.yaml' | xargs yamllint
The present commit adds unit tests for `yamllint [FILES]...` and
`yamllint --list-files [FILES]...`, that passed with previous version
1.34.0, and restore the behavior of this version.
As a result it also reverts the API change of commit 2344380 on
`yamllint.linter.run(stream, config)`.
[^1]: https://github.com/adrienverge/yamllint/issues/657#issuecomment-1948009315
[^2]: https://github.com/adrienverge/yamllint/issues/657#issuecomment-1948093680
Before this commit, yamllint would output "[Errno 2] No such file or
directory" when running on a directory which contained a broken symbolic
link, even if the file is set to be ignored in yamllint configuration.
This commit fixes that, and adds corresponding tests.
As a side effect this changes `yamllint.linter.run(stream, config)`, so
tools that would use this API need to filter ignored files beforehand.
Fixes https://github.com/adrienverge/yamllint/issues/399
https://yamllint.readthedocs.io/en/v1.34.0/ was rendered differently
than previous versions, very probably due to change of commit ca7f8b9
"Migrate to use .readthedocs.yaml for docs generation".
Let's restore the `sphinx_rtd_theme` theme.
Specification of YAML ≤ 1.1 has 22 boolean values:
y | Y | n | N
yes | Yes | YES | no | No | NO
true | True | TRUE | false | False | FALSE
on | On | ON | off | Off | OFF
Whereas YAML 1.2 spec recognizes only 6 [^1]:
true | True | TRUE | false | False | FALSE
For documents that explicit state their YAML spec version at the top of
the document, let's adapt the list of forbidden values.
In the future, we should:
- implement a configuration option to declare the default YAML spec
version, e.g. `default-yaml-spec-version: 1.2`,
- consider making 1.2 the default in a future release (this would be a
slight breaking change, but yamllint always tried to be
1.2-compatible).
- consider adapting yamllint to other 1.1 vs. 1.2 differences [^2].
Solves: https://github.com/adrienverge/yamllint/issues/587
Related to: #559#540#430#344#247#232#158
[^1]: https://yaml.org/spec/1.2.2/#1032-tag-resolution
[^2]: https://yaml.org/spec/1.2.2/ext/changes/#changes-in-version-12-revision-120-2009-07-21
CPY001 Missing copyright notice at top of file
Do not apply this rule to empty files:
tests/rules/__init__.py
and to files generated by tools:
docs/conf.py
B904 Within an `except` clause, raise exceptions with
`raise ... from err` or `raise ... from None` to
distinguish them from errors in exception handling
- The format() call was missing in the first place for `filename`.
- Other format() calls are obviously useless now that f-strings
perform string interpolation.
Before this change one of yamllint’s tests wasn’t being run on GitHub
Actions Runners because the HOME environment variable couldn’t be
overridden. I just tested it, and it looks like the HOME variable can be
overridden now, so that test no longer needs to be skipped.
Several environment variables can influence which config file yamllint
chooses to use [1]. Before this change, if you set those environment
variables and ran “python -m unittest discover”, then you could cause
certain tests to use the wrong config file and fail.
Fixes#621.
[1]: <152ba20f33/yamllint/cli.py (L180-L188)>
Some unittests set environment variables, but then delete them as part
of their cleanup process. Deleting them is OK. Any test that needs an
environment variable should set that environment variable itself. Once
the test process stops, any changes made to the environment will be lost
[1].
Before this change, there was one location where an environment variable
was restored to its original value instead of deleted. Restoring that
variable was unnecessary.
This commit was created to prepare for a future commit which will delete
HOME before any of the tests even start. Without this change, that
future change would crash. You can’t restore a variable that’s been
deleted.
Fixes#605.
[1]: <https://stackoverflow.com/q/716011/7593853>
Before this change, if certain tests were failing in certain ways, then
running “python -m unittest --buffer” would cause an AttributeError in
the unittest module itself.
Here’s what unittest does when you use the --buffer argument:
1. It sets sys.stdout and sys.stderr to StringIOs [1].
2. It runs a test.
3. If the test failed, it runs getvalue() on sys.stdout and sys.stderr
to get data from its StringIOs.
tests/test_cli.py has its own RunContext class that does something
similar. Before this change, here’s what could happen:
1. unittest sets sys.stdout and sys.stderr to StringIOs.
2. unittest runs a test that uses RunContext.
3. A RunContext gets entered. It sets sys.stdout and sys.stderr to its
own StringIOs.
4. The RunContext gets exited. It sets sys.stdout and sys.stderr to
sys.__stdout__ and sys.__stderr__.
5. The test fails.
6. unittest assumes that sys.stdout is still set to one of its
StringIOs, and runs sys.stdout.getvalue().
7. unittest crashes with this error:
AttributeError: '_io.TextIOWrapper' object has no attribute 'getvalue'
[1]: <2305ca5144/Lib/unittest/result.py (L65)>
[2]: <2305ca5144/Lib/unittest/result.py (L87)>
Flow maps and sequences need quotes if the values contain any of the
flow tokens ({}, [], ','). However, yamllint generates false positives
in these cases:
$ yamllint -d 'rules: {quoted-strings: {required: only-when-needed}}' - <<<'field: ["string[bracket]"]'
1:9 error string value is redundantly quoted with any quotes (quoted-strings)
To fix this, track when inside a flow map/sequence and skip the quoting
checks except for the quoting type.
Closes#516