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

Treat relative paths in config file relative to config file, not cwd #7967

Open
blueyed opened this issue Nov 18, 2019 · 3 comments
Open

Treat relative paths in config file relative to config file, not cwd #7967

blueyed opened this issue Nov 18, 2019 · 3 comments

Comments

@blueyed
Copy link
Contributor

blueyed commented Nov 18, 2019

When using mypy_path = src it should be treated relative to the config file (if any), not the current working directory.
This also applies to the default of cache_dir (.cache_dir), which currently gets created in the current working directory always.

I.e. a detected/found (project) config file could be treated as the root for options with relative defaults also.

As for mypy_path this could be achieved in the type callback, which then however would need the config file / root as a new argument:

'mypy_path': lambda s: [expand_path(p.strip()) for p in re.split('[,:]', s)],

As for global user config files, it should treat relative files therein relative to it, but it should not be used as a root for default settings like cache_dir.

@hauntsaninja
Copy link
Collaborator

Closing, since we implemented #7968

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Nov 26, 2020

I thought about this again because of #9751 and I'm reopening:
a) This is how I would expect things to behave, so it's likely to be a continued stumbling block
b) When specifying files, prepending MYPY_CONFIG_FILE_DIR to each of them is a bit painful
c) While this would be a breaking change, I'd be pretty surprised if this affected many people (somewhat data informed; I've seen a fair number of mypy CI setups as part of mypy_primer)

@Greedquest
Copy link

Another possible approach, rather than to specify paths relative to the config file, would be to set the cwd for both discovering and interpreting config files to be the root of the package that mypy is being invoked from. That way:

  • You wouldn't break the workflow of having a config file in your home path that specifies a default mypy_path of a stubs dir for all packages made by that user
    • e.g all the user's packages look like package_root/stubs so they put mypy_path=stubs in ~/.config/mypy/config to use this default package structure. They would then invoke mypy from the package_root dir. If you change then it becomes ~/.config/mypy/config/stubs which is ofc incorrect.
  • A user could call mypy on a single module in a package and wouldn't have to pass --config-file if their config is at the root of the project, making ide versions slightly easier to implement.

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 a pull request may close this issue.

3 participants