-
Notifications
You must be signed in to change notification settings - Fork 176
Briefcase installer options #1144
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
Changes from 6 commits
7e7b8bc
a83410c
575b454
6fb710d
6087f5e
27a5c73
1095957
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -115,6 +115,115 @@ def get_license(info): | |||||
| return {"file": str(placeholder_license)} # convert to str for TOML serialization | ||||||
|
|
||||||
|
|
||||||
| def is_bat_file(file_path: Path) -> bool: | ||||||
| return file_path.is_file() and file_path.suffix.lower() == ".bat" | ||||||
|
|
||||||
|
|
||||||
| def create_install_options_list(info: dict) -> list[dict]: | ||||||
| """Returns a list of dicts with data formatted for the installation options page.""" | ||||||
| options = [] | ||||||
|
|
||||||
| # Register Python (if Python is bundled) | ||||||
| has_python = False | ||||||
| for item in info.get("_dists", []): | ||||||
| if item.startswith("python-"): | ||||||
| components = item.split("-") # python-x.y.z-<build number>.suffix | ||||||
| python_version = ".".join(components[1].split(".")[:-1]) # create the string "x.y" | ||||||
| has_python = True | ||||||
| break | ||||||
|
|
||||||
| if has_python: | ||||||
| register_python = info.get("register_python", True) | ||||||
| if register_python: | ||||||
| options.append( | ||||||
| { | ||||||
| "name": "register_python", | ||||||
| "title": f"Register {info['name']} as my default Python {python_version}.", | ||||||
| "description": "Allows other programs, such as VSCode, PyCharm, etc. to automatically " | ||||||
| f"detect {info['name']} as the primary Python {python_version} on the system.", | ||||||
| "default": info.get("register_python_default", False), | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| # Initialize conda | ||||||
| initialize_conda = info.get("initialize_conda", "classic") | ||||||
| if initialize_conda: | ||||||
| if initialize_conda == "condabin": | ||||||
marcoesters marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| description = ( | ||||||
| "Adds condabin, which only contains the 'conda' executables, to PATH. " | ||||||
| "Does not require special shortcuts but activation needs " | ||||||
| "to be performed manually." | ||||||
| ) | ||||||
| else: | ||||||
| description = ( | ||||||
| "NOT recommended. This can lead to conflicts with other applications. " | ||||||
| "Instead, use the Command Prompt and Powershell menus added to the Windows Start Menu." | ||||||
| ) | ||||||
| options.append( | ||||||
| { | ||||||
| "name": "initialize_conda", | ||||||
| "title": "Add installation to my PATH environment variable", | ||||||
| "description": description, | ||||||
| "default": info.get("initialize_by_default", False), | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| # Keep package option (presented to the user as a negation (clear package cache)) | ||||||
| clear_package_cache = not info.get("keep_pkgs", False) | ||||||
| options.append( | ||||||
| { | ||||||
| "name": "clear_package_cache", | ||||||
| "title": "Clear the package cache upon completion", | ||||||
| "description": "Recommended. Recovers some disk space without harming functionality.", | ||||||
| "default": clear_package_cache, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| # Enable shortcuts | ||||||
| if info.get("_enable_shortcuts", False) is True: | ||||||
| options.append( | ||||||
| { | ||||||
| "name": "enable_shortcuts", | ||||||
| "title": "Create shortcuts", | ||||||
| "description": "Create shortcuts (supported packages only).", | ||||||
| "default": False, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| # Pre/Post install script | ||||||
| for script_type in ["pre", "post"]: | ||||||
| script_description = info.get(f"{script_type}_install_desc", "") | ||||||
| script = info.get(f"{script_type}_install", "") | ||||||
| if script_description and not script: | ||||||
| raise ValueError( | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Technically since it is a key in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point but it seemed a bit odd with a |
||||||
| f"{script_type}_install_desc was set, but {script_type}_install was not!" | ||||||
| ) | ||||||
|
|
||||||
| if script: | ||||||
| script_path = Path(script) | ||||||
| if not script_path.is_file(): | ||||||
| raise FileNotFoundError( | ||||||
| f"Specified {script_type}-install script '{script}' does not exist." | ||||||
| ) | ||||||
| if not is_bat_file(script_path): | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can just check for the suffix here. The only thing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the first file check and updated the error message. Let me know if that works, 1095957. |
||||||
| raise OSError( | ||||||
| f"Specified {script_type}-install script '{script}' must be a '.bat' file." | ||||||
| ) | ||||||
|
|
||||||
| # The UI option is only displayed if a description is set | ||||||
| if script_description: | ||||||
| options.append( | ||||||
| { | ||||||
| "name": f"{script_type}_install_script", | ||||||
| "title": f"{script_type.capitalize()}-install script", | ||||||
| "description": script_description, | ||||||
| "default": False, | ||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| return options | ||||||
|
|
||||||
|
|
||||||
| # Create a Briefcase configuration file. Using a full TOML writer rather than a Jinja | ||||||
| # template allows us to avoid escaping strings everywhere. | ||||||
| def write_pyproject_toml(tmp_dir, info): | ||||||
|
|
@@ -134,6 +243,7 @@ def write_pyproject_toml(tmp_dir, info): | |||||
| "use_full_install_path": False, | ||||||
| "install_launcher": False, | ||||||
| "post_install_script": str(BRIEFCASE_DIR / "run_installation.bat"), | ||||||
| "install_option": create_install_options_list(info), | ||||||
| } | ||||||
| }, | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 1095957