Skip to content

Conversation

@Danipulok
Copy link

Hey!

Summary
I'm using Windows. While I was working on #3523, I had issues with rendering docs because of docs/.hooks

I decided to change some places inside docs and clai and pydantic-evals, so that they use utf-8.

Windows by default uses other encoding, and utf-8 needs to be specified.
(At least I really don't like this behavior at all, and it will be changed in python 3.15)

Note
There're some more places where utf-8 can be specified.
I noticed in some tests you actually specify utf-8, so probably you want to minimize usage of utf-8
Then I can leave utf-8 only in .docs, if it's acceptable

Copy link
Member

@Viicos Viicos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Danipulok
Copy link
Author

@Viicos hey!
Happy to enable it and lint the whole project if that works for you.
Shall I do it?

@Danipulok
Copy link
Author

I updated the PR, please check
@Viicos, @DouweM

Changes:

  • Add encoding='utf-8' everywhere;
  • Add PLW1514 rule for ruff;
  • Enable preview mode for [tool.ruff];
  • Refactored docs/.hooks/test_snippets.py‎ to make them Windows-compatible;

Notes:

  1. If [tool.ruff.format] preview = false is unset, about 75 files are changed via formatter;

  2. docs/.hooks/test_snippets.py‎ tests failed on Windows with:

            finally:
>               os.unlink(f.name)
E               PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\Dan\\AppData\\Local\\Temp\\tmpfbq5k65p.py'

docs\.hooks\test_snippets.py:104: PermissionError
                                                   Summary of Failures                                                    
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓
┃  File                          ┃  Function                        ┃  Function Line  ┃  Error Line  ┃  Error            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩
│  docs\.hooks\test_snippets.py  │  test_parse_file_sections_basic  │  81             │  104         │  PermissionError  │
└────────────────────────────────┴──────────────────────────────────┴─────────────────┴──────────────┴───────────────────┘
Results (0.67s):
         1 failed
        24 passed

Now they are working

  1. I also removed f.flush() link everywhere in docs/.hooks/test_snippets.py‎, because it had no effect when using Path.write_text(...)

  2. I also removed those 3 lines in docs/.hooks/test_snippets.py‎,, which did nothing

  3. PLW1514 does not work perfectly, so I had to manually search for open, write_text and read_text

@Danipulok
Copy link
Author

Danipulok commented Nov 25, 2025

It also seems that pinned ruff version is old and does not catch most of the encoding errors (regarding my note 5)
Should I update it in this / other PR or no?

Edit:
But it catches only 4 more errors on the latest ruff version, so I'm not sure about it...
(Catches about 4 errors out of ~60)

astral team seems to be checking initial var's type, and if it's like this: bundle_path: Path | None = None, that it won't be considered as Path, even after asserts
Also it seems they can't resolve some transformations like Path(...) / "foo.py"

Here are the docs: https://docs.astral.sh/ruff/rules/unspecified-encoding/
Here is the source code: https://github.com/astral-sh/ruff/blob/main/crates%2Fruff_linter%2Fsrc%2Frules%2Fpylint%2Frules%2Funspecified_encoding.rs#L57

IMHO, they could just check for method names, but maybe they don't want to do it
I don't think much can be done here, except for creating issues in their repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants