Sublime Forum

Is it possible to avoid polluting sublime-project when using set_project_data?

#1

Consider this dummy.sublime-project:

{
	"build_systems":
	[
	],
	"folders":
	[
		{
			"path": ".",
		}
	]
}

If you run sublime.active_window().set_project_data({**sublime.active_window().project_data(), "foo": "10"}) you’ll get:

{
	"build_systems":
	[
	],
	"folders":
	[
		{
			"path": ".",
		}
	],
	"foo": "10",
}

And then if you run sublime.active_window().set_project_data({k:v for k,v in sublime.active_window().project_data().items() if k!="foo"}) you’ll get:

{
	"build_systems":
	[
	],
	"folders":
	[
		{
			"path": ".",
		}
	],
	/*"foo": "10",*/
}

Why is set_project_data keeping that foo member commented rather than deleting it… I guess because sublime-project is not strictly speaking json and you don’t want to make any destructive operations like get rid of comments, right? Anyway, I’ve realized about this one because I’ve got some
plugins that are deactivating/activating stuff so I saw some of my projects becoming polluted because this set_project_data behaviour.

Is there any workaround to avoid keeping these unused entries and keeping my sublime-project files as tidy and compact as possible?

Thanks :slight_smile:

0 Likes

#2

This is a known bug. See

1 Like

#3

Nice, I wasn’t aware of that one so thanks to point it out… Still I’m not sure how the set_project_data could be modified without becoming a destructive operation?

I’m assuming behind the curtains the api uses something similar to https://pypi.org/project/demjson/

Consider this example:

{
    "build_systems":
    [
    ],
    "folders":
    [
        {
            "path": ".",
        }
    ],
    /*"dont_deleteme": "i'm a legit value",*/

    // I'm a valid comment, don't delete me


    /*"deleteme": "i'm a leftover",*/
}

In that case let’s say you use set_project_data({'build_systems':[], 'folders': []}), what output would you expect?

Maybe adding an additional argument to the set_project_data that allows to “clean up completely” the project_data set_project_data(dct: Dict, strict:bool=False)? Or maybe just providing another method to the api set_project_data_strict. Dunno, just brainstorming here… :confused:

0 Likes

#4

I just believe it’s a bug that they need to solve. Introducing a new API is just masking the main problem.

0 Likes