Skip to content

Commit

Permalink
Introduce the concept of IDE profile, thonny#3280
Browse files Browse the repository at this point in the history
  • Loading branch information
aivarannamaa committed Aug 14, 2024
1 parent 4295267 commit 68e6a75
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
20 changes: 18 additions & 2 deletions thonny/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions thonny/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<profile_name>",
)

parser.add_argument(
"files",
help="",
Expand Down
8 changes: 8 additions & 0 deletions thonny/workbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 68e6a75

Please sign in to comment.