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

feat: Support custom toml path #581

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

max-muoto
Copy link
Contributor

@max-muoto max-muoto commented Jan 29, 2025

This PR adds support for custom tach.toml paths for all tach server for usage in the VSCode plugin.

@@ -21,17 +20,7 @@
TachSetupError,
TachVisibilityError,
)
from tach.extension import (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Avoiding direct imports for functions so we can directly mock without including the cli module in the path for the mocked function. When you import directly like this instead of mocking tach.extension.my_func you mock the cli module which can be a little bit awkward. The Google Python style guide additionally recommends this:

Use import statements for packages and modules only, not for individual types, classes, or functions.

Let me know if we're fine with this!

Copy link
Member

Choose a reason for hiding this comment

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

That works for me 👍

@max-muoto max-muoto force-pushed the support-custom-toml-path branch from 2b2ba63 to e2278f9 Compare February 3, 2025 04:29
@max-muoto max-muoto force-pushed the support-custom-toml-path branch from 9763b81 to e26a23b Compare February 3, 2025 05:06
@max-muoto max-muoto marked this pull request as ready for review February 3, 2025 05:06
@max-muoto max-muoto changed the title Support custom toml path feat: Support custom toml path Feb 3, 2025
def main() -> None:
args, parser = parse_arguments(sys.argv[1:])
def main(argv: list[str] = sys.argv[1:]) -> None:
args, parser = parse_arguments(argv)
project_root = fs.find_project_config_root() or Path.cwd()
Copy link
Member

@emdoyle emdoyle Feb 3, 2025

Choose a reason for hiding this comment

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

Given the use case in #579 , we also need to adjust the project_root which is passed to tach_server based on the location of the actual config file. This is needed for Tach to correctly interpret source_roots and differentiate between first-party and third-party imports.

I believe the config parsing code in Rust tracks the location of the config file, but it would be better for now to just adjust the usage of find_project_config_root in main to handle this specific LSP case.

except Exception as e:
print(f"Failed to parse project config: {e}")
sys.exit(1)


def main() -> None:
args, parser = parse_arguments(sys.argv[1:])
def main(argv: list[str] = sys.argv[1:]) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

Not a huge deal because direct CLI usage is unlikely, but in this function there is a call to print_no_config_found which should now take the custom config argument so that the error message can be more accurate. Right now it will always say tach.toml is not found, even when specifying another name.

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