Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run mypy in the directory of the nearest pyproject.toml or mypy.ini #316

Merged

Conversation

jwhitaker-gridcog
Copy link
Contributor

@jwhitaker-gridcog jwhitaker-gridcog commented Aug 20, 2024

This should fix the issues #190 and #259 .

Implements a new variable for cwd, ${filePyproject} ${nearestConfig}. If cwd is set as such, then the lsp will search upwards from the current file for a pyproject.toml or mypy.ini. If found, mypy will be run in its directory. If not found, it will run in workspaceFolder.

Questions:

  • that variable is ugly, should I call it something else? -> ${nearestConfig}
  • should I look for other files as well (mypy.ini? done)

@jwhitaker-gridcog
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Gridcog"

@jwhitaker-gridcog jwhitaker-gridcog changed the title run mypy in the directory of the nearest pyproject.toml run mypy in the directory of the nearest pyproject.toml or mypy.ini Aug 20, 2024
@jwhitaker-gridcog jwhitaker-gridcog force-pushed the run-mypy-in-nearest-pyproject branch from 8b68a2c to 2d84c25 Compare August 20, 2024 07:50
Copy link
Member

@karthiknadig karthiknadig left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. Some minor changes and suggestions.

README.md Outdated
@@ -47,7 +47,7 @@ There are several settings you can configure to customize the behavior of this e
<tr>
<td>mypy-type-checker.cwd</td>
<td><code>${workspaceFolder}</code></td>
<td>Sets the current working directory used to lint Python files with Mypy. By default, it uses the root directory of the workspace <code>${workspaceFolder}</code>. You can set it to <code>${fileDirname}</code> to use the parent folder of the file being linted as the working directory for Mypy.
<td>Sets the current working directory used to lint Python files with Mypy. By default, it uses the root directory of the workspace <code>${workspaceFolder}</code>. You can set it to <code>${fileDirname}</code> to use the parent folder of the file being linted as the working directory for Mypy. You can also set it to <code>${filePyproject}</code> to use the folder of the nearest parent <code>pyproject.toml</code>.
Copy link
Member

Choose a reason for hiding this comment

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

The name should likely be ${nearestConfig} since it does both pyproject and ini.
/cc @luabud

@@ -650,6 +650,27 @@ def get_cwd(settings: Dict[str, Any], document: Optional[workspace.Document]) ->
return os.fspath(pathlib.Path(document.path).parent)
return settings["workspaceFS"]

if settings["cwd"] == "${filePyproject}":
if document is None:
Copy link
Member

Choose a reason for hiding this comment

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

we can probably move (document is None) case to the beginning of the function. Since it is common to all scenarios.

README.md Outdated Show resolved Hide resolved
@karthiknadig karthiknadig self-assigned this Aug 28, 2024
@karthiknadig karthiknadig added the feature-request Request for new features or functionality label Aug 28, 2024
@karthiknadig karthiknadig added this to the September 2024 milestone Aug 28, 2024
@jwhitaker-gridcog jwhitaker-gridcog force-pushed the run-mypy-in-nearest-pyproject branch from 3b4e9cd to add689d Compare September 2, 2024 21:47
@jwhitaker-gridcog
Copy link
Contributor Author

hey, rebased on new main, fixed fmt lint and squash a couple of fixups, but PR checks need approval again sorry

karthiknadig
karthiknadig previously approved these changes Sep 3, 2024
@eleanorjboyd
Copy link
Member

hi @jwhitaker-gridcog! Thanks for the submission- could you just make sure the linting check passes? Thanks!

@karthiknadig
Copy link
Member

Looks like you just need to run black:
image

@jwhitaker-gridcog
Copy link
Contributor Author

ty both, sorry i got the js fmt but missed py. also tweaked log messages.

@karthiknadig karthiknadig enabled auto-merge (squash) September 27, 2024 15:35
@karthiknadig karthiknadig force-pushed the run-mypy-in-nearest-pyproject branch from 48070a4 to 43e8e46 Compare September 27, 2024 15:39
@karthiknadig karthiknadig merged commit a356c8e into microsoft:main Sep 27, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants