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

settings djlint.configuration relative paths #128

Closed
vasekch opened this issue Dec 16, 2022 · 6 comments
Closed

settings djlint.configuration relative paths #128

vasekch opened this issue Dec 16, 2022 · 6 comments

Comments

@vasekch
Copy link

vasekch commented Dec 16, 2022

I have workspace open on a project folder e.g. /home/foo/projectA/
I'm customizing djlint with my own config file in project folder /home/foo/projectA/.djlintrc
I'm having template files in various subdirs e.g. ./templates/main.html, ./myapp/templates/page.html

Let me elaborate on various options in settings.json

    // all works ok, but I don't like the absolute path
    "djlint.configuration": "/home/foo/projectA/.djlintrc"
    // relative path in project doesn't work - Error: Invalid value for '--configuration': Path '.djlintrc' does not exist.
    "djlint.configuration": ".djlintrc"
    // homedir expantion doesn't work - Error: Invalid value for '--configuration': Path '.djlintrc' does not exist.
    "djlint.configuration": "~/projectA/.djlintrc"
    // if I put relative path from the file I'm linting, it works

    // works for file `./templates/main.html`
    "djlint.configuration": "../.djlintrc"

    // works for file `./myapp/templates/pagehtml`
    "djlint.configuration": "../../.djlintrc"

It feels quite tricky to set this correctly, which seems to be absolute path for me (dislike).

It seems that cwd for djlint execution is path of a target file. For finding config file it may be beneficial to execute djlint from workspace base dir.

Ideally, would it be possible to pickup .djlintrc file in workspace base folder automatically by default?

BTW: docs say:

djLint’s CLI options can be configured directly in the VS Code settings.

But I'm only able to pass djlint.configuration argument, is it possible to pass for example max_line_length or such?

P.S.: Thanks for this extension, 💚!

@vasekch
Copy link
Author

vasekch commented Dec 16, 2022

in addition to the last question, I only seem to have a few CLI options available in the settings.json

image

@monosans
Copy link
Member

This problem was caused by this change: #82. But we cannot just roll it back, because that would cause other problems.

I propose you two solutions to this problem:

  • Use an absolute path to the config file.
  • Stop using djlint.configuration, and instead just put the config file in the root of the project, djLint will find it and use it.

is it possible to pass for example max_line_length or such

No, this option cannot be configured through the CLI, only through the config file. The list of available CLI options can be seen with the djlint --help command.

@vasekch
Copy link
Author

vasekch commented Dec 19, 2022

Thanks for reply - ad more CLI - my bad, you're right, now I get it.

I'd love to stop using djlint.configuration, but extension does not pick up my .djlintrc file from the workspace, not sure why. It simply runs linting with default config. When I point to the file directly it works.

I have slightly complicated workspace (4 git repos in the main directory), but not sure what am I doing wrong. The .djlintrc is in the main dir as well as python venv (where from is djlint binary picked up correctly).

Is there a way I can debug picking default config? It seem not to work even when I execute djlint manually, so perhaps I have some issue in my venv / path / something

@vasekch vasekch closed this as completed Dec 19, 2022
@christopherpickering
Copy link
Contributor

@vasekch is there any chance you make make a test repository I can see the problem in? Thanks!

@vasekch
Copy link
Author

vasekch commented Dec 19, 2022

@christopherpickering it seems to be "above" git 🙂

I think I got to the bottom of in in this routine https://github.com/Riverside-Healthcare/djLint/blob/master/src/djlint/settings.py#L29

As I mentioned I have VSC workspace with 4 git repos and couple of them have django templates in them. When djlint is executed config path function find_project_root gets stuck on the repo level, but my config file is one level above in the workspace main dir.

On top of this I symlink the config file from the main dir into one of the repos.

Schematically

/project
/project/.vscode/settings.json
/project/repoA/.git/
/project/repoA/.djlint
/project/repoB/.git/
/project/repoB/app/templates/main.html
/project/repoC/.git/
/project/repoC/app/templates/othermain.html
/project/venv/
/project/requirements.txt -> ./repoA/requirements.txt
/project/.djlint -> ./repoA/.djlint

repoA is kind of project setup repo. repoB and repoC contain django templates.

So it seems that find_project_root results into repoB and repoC and that's why my config is not loaded.

Maybe the project root path detection should consider venv path or cwd. That would be a change in the code of djLint itself, but connected with #82.

I feel to small to have strong opinion here. Putting the config file in all django template repos would resolve the problem, but that's not dry enough. I'd love to use relative path in wokspace settings, but no big deal with the abolute path.

As I'm thinking about it, our project setup may get improved if repoA is on the project level and others are git submodules or something (but I have no power in that field).

@vasekch vasekch reopened this Dec 19, 2022
@christopherpickering
Copy link
Contributor

Yeah for this I honestly just used the same design as black and isort when looking for the project root. If you have a nice idea of how to use the venv path feel free to start a pr... if you didn't already.. just getting back in here.

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

No branches or pull requests

3 participants