<commit_before>import json
import os
import subprocess

import sublime
import sublime_plugin


def open_project_in_window(window, project_file, subl='subl'):
    window.run_command("close_project")
    window.run_command("close_all")

    subprocess.check_call([subl, '--project', project_file, ])

# settings are reloaded automatically, no need to fetch these every time
settings = sublime.load_settings('ProjectFolders.sublime-settings')


class ProjectfolderCommand(sublime_plugin.WindowCommand):
    def description(self):
        return 'Open a folder and the associated project'

    def open_project_folder(self, path):
        print('opening project associated with {}'.format(path))
        basename = os.path.basename(path)
        project_file = os.path.join(path, basename + '.sublime-project')
        print('project file: {}'.format(project_file))

        # if the project does not exist, create it
        if not os.path.exists(project_file):
            with open(project_file, 'w') as out:
                json.dump({}, out)

        open_project_in_window(self.window, project_file)

    def run(self):
        # collect list of packages
        dirs = ['~']

        entries = []

        for basedir in dirs:
            for dn in os.listdir(os.path.expanduser(basedir)):
                entries.append(os.path.join(basedir, dn))

        entries.sort()

        def _open_entry(n):
            if n == -1:
                return

            self.open_project_folder(os.path.expanduser(entries[n]))

        self.window.show_quick_panel(entries, _open_entry)<commit_msg>Get top level project dirs from settings file.<commit_after>import json
import os
import subprocess

import sublime
import sublime_plugin


def open_project_in_window(window, project_file, subl='subl'):
    window.run_command("close_project")
    window.run_command("close_all")

    subprocess.check_call([subl, '--project', project_file, ])

# settings are reloaded automatically, no need to fetch these every time
settings = sublime.load_settings('ProjectFolders.sublime-settings')


class ProjectfolderCommand(sublime_plugin.WindowCommand):
    def description(self):
        return 'Open a folder and the associated project'

    def open_project_folder(self, path):
        print('opening project associated with {}'.format(path))
        basename = os.path.basename(path)
        project_file = os.path.join(path, basename + '.sublime-project')
        print('project file: {}'.format(project_file))

        # if the project does not exist, create it
        if not os.path.exists(project_file):
            with open(project_file, 'w') as out:
                json.dump({}, out)

        open_project_in_window(self.window, project_file)

    def run(self):
        # collect list of packages
        dirs = settings.get('project_dirs')

        entries = []

        for basedir in dirs:
            sub_entries = []
            for dn in os.listdir(os.path.expanduser(basedir)):
                sub_entries.append(os.path.join(basedir, dn))
            entries.extend(sorted(sub_entries))

        def _open_entry(n):
            if n == -1:
                return

            self.open_project_folder(os.path.expanduser(entries[n]))

        self.window.show_quick_panel(entries, _open_entry)
{'fraction_non_alphanumeric': 0.10373066424021839, 'fraction_numerical': 0.0006066120715802245, 'mean_word_length': 2.8708920187793425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2800242', 'n_tokens_mistral': 988, 'n_tokens_neox': 945, 'n_words': 226}