How to use the defined variable in a package?

Issue #5 resolved
Sergey Sedykh
created an issue

Hi!

I've defined a varible like this:

{
  "print_output": true,
  "env":
  {
    "Windows": 
    {
      "PHPCSPATH": "C:\\Users\\user_name\\dev\\vvv\\www\\phpcs\\scripts\\phpcs.bat",
    }
  }
}

How can I use this variable in a package user settings file?

I tried this:

{
    "phpcs_executable_path": "PHPCSPATH"
}

But it doesn't work :(

Thanks a lot!

Comments (9)

  1. Daniele Niero repo owner

    Hi Elliot Sergey, (why did I call you Elliot?)

    This is not a bug but I'm afraid you can't do that. See, what you are trying to do is using a variable created at load-time by EnvironmentSettings to set another variable assigned at load time by another package. Packages are loaded when Sublime starts and you have not control on the order they are loaded, if they are loaded in order at all (they might be loaded in parallel, I have no idea really). So what probably is happening here is that my package is not loaded yet when you try to use a variables it sets from from a second packages.

    The problem is that the second pacage wants that variable when it loads and not after when it is executed, isn't it?

    Does it make sense?

  2. Daniele Niero repo owner

    Ok, I could only take a quick look at that plugin and I think you are right, it is a run-time request and therefore there maybe a way.

    from line 198 to line 206 in phpcs.py he sets the application_path but he isn't tring to resolve it at all, he just assumes that it is a full qualified and valid path. So you could try to change line 199 from application_path = pref.phpcs_executable_path to application_path = os.path.expandvars(pref.phpcs_executable_path)

    This should do the trick. There are other lines where he set the application_path, so it may require more work...

    Basically, what I'm saying, is that php package doesn't support environment variables in first place and If I'm on the right track here, I think you've opened a bug (or feature request) in the wrong package, you should have opened it in his and ask for support for environment variables as value in the settings :) Actually, I'd think you should ask it anyway.

    That said, I'm not a php coder so I have no mean to double check if anything I'm saying here is correct :/

    Let me know if I can help further.

  3. Sergey Sedykh reporter

    Thanks for digging into this. I tried your solution, but it didn't work :( The console generated some other errors.

    I think I'd better ask about it the package author.

    Thank you for your time.

  4. Log in to comment