pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

project_includes and project_excludes are not respected in pyproject.toml

Open indoyoon opened this issue 7 months ago • 1 comments

Describe the Bug

Hi, I would like to apply those rules:

[tool.pyrefly]
project_includes = ["src1", "src2"]
project_excludes = ["**/.[!/.]*", "**/*venv/**", "tests"]

however, running pyrefly check still checks a folder "tests". Also it seems it checks folders not listed in project_includes. It correctly loads settings from the pyproject.toml.

pyrefly check
INFO Checking project configured at `/project/pyproject.toml`

Why this setting is overriden when I didn't provide CLI parameters? Thanks.

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

MacOS Zed, remote linux environment

indoyoon avatar May 30 '25 01:05 indoyoon

I wonder if the logic for how pyrefly is initialized in zed is related: https://github.com/zed-extensions/pyrefly/blob/main/src/pyrefly.rs

lolpack avatar May 30 '25 19:05 lolpack

I highly doubt that because I am running Pyrefly from the terminal, and I even don't have Pyrefly Zed extension installed.

indoyoon avatar Jun 02 '25 04:06 indoyoon

Hey @indoyoon, I have a few questions for you that will help me narrow in on what's going on:

  • Is this the whole Pyrefly part of your config?
[tool.pyrefly]
project_includes = ["src1", "src2"]
project_excludes = ["**/.[!/.]*", "**/*venv/**", "tests"]
  • How are you running Pyrefly? What's the exact command, and which directory are you executing this from relative to the config that's being found?
  • Where is the tests folder relative to the config that's being found? Also, where are the directories that are being included that aren't specified in your config relative to the config?

connernilsen avatar Jun 02 '25 20:06 connernilsen

  1. I have other rules like replace_imports_with_any and [[tool.pyrefly.sub_config]].
  2. Litterally pyrefly check is the whole thing I'm trying to use. pyproject.toml is located at the project's root, and I'm invoking the command at the same location.
  3. Here you go:
.
├── src1
├── src2
├── tests
├── venv
└── pyproject.toml

indoyoon avatar Jun 04 '25 04:06 indoyoon

@indoyoon More questions:

  1. Which version of Pyrefly are you running? (pyrefly --version)
  2. Can you attach the first few lines of pyrefly check --verbose (before the errors start)?

connernilsen avatar Jun 04 '25 20:06 connernilsen

1

From pyproject.toml

"pyrefly==0.17.1",
$ pyrefly --version
pyrefly 0.17.1

2

 INFO Checking project configured at `/project/pyproject.toml`
DEBUG Config is: {project_includes: [/project/**/*], project_excludes: [/project/**/.[!/.]*, /project/**/*venv/**/*], search_path: [/project/], python_interpreter: None, python_environment: {python_platform: linux, python_version: 3.13.1, site_package_path: [/.pyenv/versions/3.13.1/lib/python3.13, /.pyenv/versions/3.13.1/lib/python3.13/lib-dynload, /project/venv/lib/python3.13/site-packages, __editable__.project-0.97.0.dev51+g6295b0b6e.d20250522.finder.__path_hook__], site_package_path_source: Interpreter("/project/venv/bin/python3.13")}, replace_imports_with_any: []}
DEBUG Checking 906 files (listing took 0.93s)

indoyoon avatar Jun 05 '25 00:06 indoyoon

@indoyoon interesting, it looks like Pyrefly is finding your configuration, but not reading it at all. I wonder if there's some kind of parse error going on.

Do you see anything like this in your output?

ERROR /project/pyproject.toml: TOML parse error at line X, column Y

If not, would you be open to sharing your pyproject.toml here so that I can see if there's anything else going on that might be causing this? Otherwise, I can try to see if there's anything in the rest of your pyrefly check --verbose output that might indicate what else might be going on, but the pyproject.toml part might be the most helpful.

If it's something you can't share online, we could do a video call through our Discord server where I can take a more direct look at what's going on.

connernilsen avatar Jun 05 '25 13:06 connernilsen

Even if I remove all other settings, it is still the same.

[build-system]
requires = [
  "setuptools~=80.0",
  "setuptools_scm~=8.0",
]

[project]
name="ds"
authors = [
    {name = "Team", email = "[email protected]"},
]
description="Core"
requires-python =">=3.9, <3.14"
dynamic = ["version"]
dependencies = [
    "tqdm~=4.60",
]


[tool.pyrefly]
project_includes = ["src1", "src2"]
project_excludes = ["**/.[!/.]*", "**/*venv/**", "**/tests/**/*.py"]

replace_imports_with_any = [
  "docker.*",
  "google.auth.*",
  "sqlakeyset.*",
  "google.cloud.*",
  "kubernetes.*",
  "pygerrit2.*",
  "httpie.*",
  "jwcrypto.*",
  "google",
]

[tool.pyrefly.errors]
possibly-undefined = true
explicit-override = true
ignore-without-code = true

Meanwhile I will test this in the different machines

indoyoon avatar Jun 09 '25 05:06 indoyoon

Okay, I was able to get it working when commenting out the errors you have. It looks like those errors you listed are unrecognized by Pyrefly, which causes the file to be invalid and type checking to fail.

Did those errors come from pyrefly init's migration functionality from mypy or Pyright?

Do you see errors mentioning config issues near the top of your output? This is what I was seeing:

ERROR /Users/connernilsen/Documents/typecheck/pyre-check/scripts/pyproject.toml: TOML parse error at line 19, column 1
   |
19 | [tool.pyrefly]
   | ^^^^^^^^^^^^^^
unknown variant `possibly-undefined`, expected one of `annotation-mismatch`, `assert-type`, `async-error`, `bad-argument-count`, `bad-argument-type`, `bad-assignment`, `bad-class-definition`, `bad-function-defin
ition`, `bad-instantiation`, `bad-keyword-argument`, `bad-override`, `bad-return`, `bad-specialization`, `bad-unpacking`, `delete-error`, `deprecated`, `import-error`, `index-error`, `internal-error`, `invalid-an
notation`, `invalid-argument`, `invalid-inheritance`, `invalid-literal`, `invalid-overload`, `invalid-param-spec`, `invalid-super-call`, `invalid-syntax`, `invalid-type-var`, `invalid-type-var-tuple`, `implicitly
-defined-attribute`, `invalid-yield`, `match-error`, `missing-argument`, `missing-attribute`, `missing-module-attribute`, `no-access`, `no-matching-overload`, `not-a-type`, `not-callable`, `not-iterable`, `parse-
error`, `read-only`, `reveal-type`, `type-alias-error`, `typed-dict-key-error`, `unexpected-keyword`, `unbound-name`, `unknown-name`, `unsupported-operand`, `unsupported`, `unknown`

connernilsen avatar Jun 09 '25 23:06 connernilsen

I can confirm your solution is correct. But I have to admit that it is very confusing. Because misused errors (syntax error) is causing another problem, which is nonproject_excludes is not handled properly.

Thank you very much for the support!

indoyoon avatar Jun 13 '25 06:06 indoyoon

Yeah, I created #457 to address this. Looks like it was something one of the other maintainers was working on, but didn't finish before PyCon. We'll hopefully have it work better soon!

connernilsen avatar Jun 13 '25 16:06 connernilsen