diff --git a/thonny/__init__.py b/thonny/__init__.py index 22f75f3b5..934bfdfa9 100644 --- a/thonny/__init__.py +++ b/thonny/__init__.py @@ -134,7 +134,7 @@ def get_ipc_file_path(): if not sys.platform == "win32": os.chmod(ipc_dir, 0o700) - _ipc_file = os.path.join(ipc_dir, "ipc.sock") + _ipc_file = os.path.join(ipc_dir, get_profile() + "-ipc.sock") return _ipc_file @@ -296,13 +296,29 @@ def get_sys_path_directory_containg_plugins() -> str: return get_user_site_packages_dir_for_base(get_user_base_directory_for_plugins()) +def get_profile() -> str: + try: + idx = sys.argv.index("--profile") + except ValueError: + return "default" + + if len(sys.argv) > idx + 1: + return sys.argv[idx + 1] + + return "default" + + def _compute_thonny_user_dir(): env_var = os.environ.get("THONNY_USER_DIR", "") if env_var: # back-end processes always choose this path return os.path.expanduser(env_var) - # Following is only for the front-end process + return os.path.join(_compute_thonny_profiles_dir(), get_profile()) + + +def _compute_thonny_profiles_dir(): + # Following is used only in the front-end process from thonny.common import is_private_python, running_in_virtual_environment from thonny.misc_utils import get_roaming_appdata_dir diff --git a/thonny/main.py b/thonny/main.py index ae0a6fa02..cef0780fb 100644 --- a/thonny/main.py +++ b/thonny/main.py @@ -207,6 +207,13 @@ def _parse_arguments_to_dict(raw_args: List[str]) -> Dict[str, Any]: "--version", help="Show Thonny version and exit", action="version", version=get_version() ) + parser.add_argument( + "--profile", + help="The profile to create or open. If not specified, the default profile is used. Profile name must be a valid directory name.", + default="default", + metavar="", + ) + parser.add_argument( "files", help="", diff --git a/thonny/workbench.py b/thonny/workbench.py index d36cfa0fb..fb5c99399 100644 --- a/thonny/workbench.py +++ b/thonny/workbench.py @@ -280,6 +280,9 @@ def poll_events(self) -> None: self._event_polling_id = self.after(20, self.poll_events) + def get_profile(self) -> str: + return self._initial_args.get("profile", "default") + def _load_stuff_from_command_line(self, parsed_args: Dict[str, Any]) -> None: logger.info("Processing arguments %r", parsed_args) try: @@ -2764,6 +2767,11 @@ def update_title(self, event=None) -> None: title_text = "Portable Thonny" else: title_text = "Thonny" + + profile = self.get_profile() + if profile != "default": + title_text += f"〈 {profile} 〉" + if editor is not None: title_text += " - " + editor.get_long_description()