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

Provide build system variables that contain the project folder that the current file is in and the relative path from there #970

Open
FichteFoll opened this issue Aug 17, 2015 · 1 comment

Comments

@FichteFoll
Copy link
Collaborator

Problem

You can only get the path of the "first folder" that you opened in the project and the full path to the file in question, but you can not use variables in substitutions (e.g. ${file/$folder//}). It's also restricted to one folder only (i.e. the first one), but that will rarely be a problem.

Example use case: You want to use python -m path.to.module in your project dir instead of executing the file directly.

Solution proposal

Provide $current_folder and $file_relative_to_folder variables. The variables are filled by iterating over all folders in the project and will be set from the first folder that contains the current file.
The resulting build system would then look as follows (hope I got the regex straight):

{
    "shell_cmd": "python -m ${file_relative_to_folder/([/\\\\])|((?:__init__)?\\.py)/(?1.:)(?2:)/g}",
    "working_dir": "$current_folder"
}

Workaround

Something like this:

{
    "target": "custom_python_module_build",
    "file_path": "$file"
}
import sublime_plugin


class CustomPythonModuleBuildCommand(sublime_plugin.WindowCommand):
    def run(self, file_path, **kwargs):
        for folder in self.window.folders():
            if file_path.startswith(folder):
                relative_path = file_path[len(folder):].strip("/\\")
                relative_path = relative_path.replace("/", ".").replace("\\", ".")
                kwargs['shell_cmd'] = "python -m %s" % relative_path
                kwargs['working_dir'] = folder
                self.window.run_command("exec", kwargs)
                return
@FichteFoll FichteFoll changed the title Provide a build system variables that contain the project folder that the current file is in and the relative path from there Provide build system variables that contain the project folder that the current file is in and the relative path from there Aug 17, 2015
@Narretz
Copy link

Narretz commented Nov 29, 2021

Six years later and this feature still doesn't exist. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants