Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ jobs:
run: conda list
- name: conda config
run: conda config --show-sources

- name: Run unit tests
run: |
pytest -vv --cov=constructor --cov-branch tests/ -m "not examples"
Expand All @@ -152,6 +153,7 @@ jobs:
AZURE_SIGNTOOL_KEY_VAULT_URL: ${{ secrets.AZURE_SIGNTOOL_KEY_VAULT_URL }}
CONSTRUCTOR_EXAMPLES_KEEP_ARTIFACTS: "${{ runner.temp }}/examples_artifacts"
CONSTRUCTOR_SIGNTOOL_PATH: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.26100.0/x86/signtool.exe"
CONSTRUCTOR_VERBOSE: 1
run: |
rm -rf coverage.json
pytest -vv --cov=constructor --cov-branch tests/test_examples.py
Expand Down
23 changes: 20 additions & 3 deletions constructor/briefcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@
import logging
import re
import shutil
import sys
import sysconfig
import tempfile
from pathlib import Path
from subprocess import run

import tomli_w
IS_WINDOWS = sys.platform == "win32"
if IS_WINDOWS:
import tomli_w
else:
tomli_w = None # This file is only intended for Windows use

from . import preconda
from .utils import DEFAULT_REVERSE_DOMAIN_ID, copy_conda_exe, filename_dist
Expand Down Expand Up @@ -100,6 +105,16 @@ def get_bundle_app_name(info, name):
return bundle, app_name


def get_license(info):
"""Retrieve the specified license as a dict or return a placeholder if not set."""

if "license_file" in info:
return {"file": info["license_file"]}

placeholder_license = Path(__file__).parent / "nsis" / "placeholder_license.txt"
return {"file": str(placeholder_license)} # convert to str for TOML serialization


# 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):
Expand All @@ -110,7 +125,7 @@ def write_pyproject_toml(tmp_dir, info):
"project_name": name,
"bundle": bundle,
"version": version,
"license": ({"file": info["license_file"]} if "license_file" in info else {"text": ""}),
"license": get_license(info),
"app": {
app_name: {
"formal_name": f"{info['name']} {info['version']}",
Expand All @@ -130,6 +145,9 @@ def write_pyproject_toml(tmp_dir, info):


def create(info, verbose=False):
if not IS_WINDOWS:
raise Exception(f"Invalid platform '{sys.platform}'. Only Windows is supported.")

tmp_dir = Path(tempfile.mkdtemp())
write_pyproject_toml(tmp_dir, info)

Expand All @@ -150,7 +168,6 @@ def create(info, verbose=False):
raise FileNotFoundError(
f"Dependency 'briefcase' does not seem to be installed.\nTried: {briefcase}"
)

logger.info("Building installer")
run(
[briefcase, "package"] + (["-v"] if verbose else []),
Expand Down
6 changes: 3 additions & 3 deletions constructor/briefcase/run_installation.bat
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
set PREFIX=%cd%
_conda constructor --prefix %PREFIX% --extract-conda-pkgs
set "PREFIX=%cd%"
_conda constructor --prefix "%PREFIX%" --extract-conda-pkgs

set CONDA_PROTECT_FROZEN_ENVS=0
set CONDA_ROOT_PREFIX=%PREFIX%
set CONDA_SAFETY_CHECKS=disabled
set CONDA_EXTRA_SAFETY_CHECKS=no
set CONDA_PKGS_DIRS=%PREFIX%\pkgs

_conda install --offline --file %PREFIX%\conda-meta\initial-state.explicit.txt -yp %PREFIX%
_conda install --offline --file "%PREFIX%\conda-meta\initial-state.explicit.txt" -yp "%PREFIX%"
2 changes: 1 addition & 1 deletion examples/azure_signtool/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: Signed_AzureSignTool
version: X
version: 1.0.0
installer_type: exe
channels:
- https://repo.anaconda.com/pkgs/main/
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_nsis_template/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: custom
version: X
version: 1.0.0
ignore_duplicate_files: True
installer_filename: {{ name }}-installer.exe
installer_type: exe
Expand Down
2 changes: 1 addition & 1 deletion examples/customize_controls/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

name: NoCondaOptions
version: X
installer_type: all
installer_type: {{ "exe" if os.name == "nt" else "all" }}

channels:
- https://repo.anaconda.com/pkgs/main/
Expand Down
2 changes: 1 addition & 1 deletion examples/customized_welcome_conclusion/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: CustomizedWelcomeConclusion
version: X
version: 1.0.0
installer_type: all
channels:
- https://repo.anaconda.com/pkgs/main/
Expand Down
2 changes: 1 addition & 1 deletion examples/exe_extra_pages/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% set name = "extraPageSingle" %}
{% endif %}
name: {{ name }}
version: X
version: 1.0.0
installer_type: all
channels:
- https://repo.anaconda.com/pkgs/main/
Expand Down
4 changes: 2 additions & 2 deletions examples/extra_envs/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "../../constructor/data/construct.schema.json"

name: ExtraEnvs
version: X
installer_type: all
version: 1.0.0
installer_type: {{ "exe" if os.name == "nt" else "all" }}
channels:
- https://conda.anaconda.org/conda-forge
specs:
Expand Down
2 changes: 1 addition & 1 deletion examples/extra_files/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: ExtraFiles
version: X
version: 1.0.0
installer_type: all
license_file: TEST_LICENSE.txt
check_path_spaces: False
Expand Down
2 changes: 1 addition & 1 deletion examples/from_env_txt/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: EnvironmentTXT
version: X
version: 1.0.0
installer_type: all
environment_file: env.txt
initialize_by_default: false
Expand Down
4 changes: 2 additions & 2 deletions examples/from_env_yaml/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "../../constructor/data/construct.schema.json"

name: EnvironmentYAML
version: X
installer_type: all
version: 1.0.0
installer_type: {{ "exe" if os.name == "nt" else "all" }}
environment_file: env.yaml
initialize_by_default: false
register_python: False
2 changes: 1 addition & 1 deletion examples/from_existing_env/construct.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# yaml-language-server: $schema=../../constructor/data/construct.schema.json
"$schema": "../../constructor/data/construct.schema.json"
name: Existing
version: X
version: 1.0.0
installer_type: all
environment: {{ os.environ.get("CONSTRUCTOR_TEST_EXISTING_ENV", os.environ["CONDA_PREFIX"]) }}
channels:
Expand Down
2 changes: 1 addition & 1 deletion examples/from_explicit/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: Explicit
version: X
version: 1.0.0
installer_type: all
environment_file: explicit_linux-64.txt
initialize_by_default: false
Expand Down
2 changes: 1 addition & 1 deletion examples/initialization/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ initialize_by_default: true
register_python: false
check_path_spaces: true
check_path_length: false
installer_type: all
installer_type: {{ "exe" if os.name == "nt" else "all" }}
2 changes: 1 addition & 1 deletion examples/miniforge-mamba2/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ specs:
- miniforge_console_shortcut 1.* # [win]

# Added for extra testing
installer_type: all
installer_type: {{ "exe" if os.name == "nt" else "all" }}
post_install: test_install.sh # [unix]
post_install: test_install.bat # [win]
initialize_by_default: false
Expand Down
2 changes: 1 addition & 1 deletion examples/miniforge/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ specs:
- miniforge_console_shortcut 1.* # [win]

# Added for extra testing
installer_type: all
installer_type: {{ "exe" if os.name == "nt" else "all" }}
post_install: test_install.sh # [unix]
post_install: test_install.bat # [win]
initialize_by_default: false
Expand Down
2 changes: 1 addition & 1 deletion examples/mirrored_channels/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: Mirrors
version: X
version: 1.0.0

channels:
- conda-forge
Expand Down
2 changes: 1 addition & 1 deletion examples/noconda/constructor_input.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: NoConda
version: X
version: 1.0.0
installer_type: all
channels:
- https://repo.anaconda.com/pkgs/main/
Expand Down
2 changes: 1 addition & 1 deletion examples/outputs/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: Outputs
version: X
version: 1.0.0
installer_type: sh # [unix]
installer_type: exe # [win]
channels:
Expand Down
4 changes: 2 additions & 2 deletions examples/protected_base/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "../../constructor/data/construct.schema.json"

name: ProtectedBaseEnv
version: X
installer_type: all
version: 1.0.0
installer_type: {{ "exe" if os.name == "nt" else "all" }}

channels:
- defaults
Expand Down
4 changes: 2 additions & 2 deletions examples/register_envs/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "../../constructor/data/construct.schema.json"

name: RegisterEnvs
version: X
installer_type: all
version: 1.0.0
installer_type: {{ "exe" if os.name == "nt" else "all" }}
channels:
- https://repo.anaconda.com/pkgs/main/
specs:
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"$schema": "../../constructor/data/construct.schema.json"

name: Scripts
version: X
installer_type: all
version: 1.0.0
installer_type: {{ "exe" if os.name == "nt" else "all" }}
channels:
- https://repo.anaconda.com/pkgs/main/
specs:
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/post_install.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
echo Added by post-install script > "%PREFIX%\post_install_sentinel.txt"
if not "%INSTALLER_NAME%" == "Scripts" exit 1
if not "%INSTALLER_VER%" == "X" exit 1
if not "%INSTALLER_VER%" == "1.0.0" exit 1
if not "%INSTALLER_PLAT%" == "win-64" exit 1
if not "%INSTALLER_TYPE%" == "EXE" exit 1
if not "%INSTALLER_UNATTENDED%" == "1" exit 1
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ echo "CUSTOM_VARIABLE_2=${CUSTOM_VARIABLE_2}"
echo "PREFIX=${PREFIX}"

test "${INSTALLER_NAME}" = "Scripts"
test "${INSTALLER_VER}" = "X"
test "${INSTALLER_VER}" = "1.0.0"
# shellcheck disable=SC2016 # String interpolation disabling is deliberate
test "${CUSTOM_VARIABLE_1}" = 'FIR$T-CUSTOM_'\''STRING'\'' WITH SPACES AND @*! "CHARACTERS"'
# shellcheck disable=SC2016 # String interpolation disabling is deliberate
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/pre_install.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if not "%INSTALLER_NAME%" == "Scripts" exit 1
if not "%INSTALLER_VER%" == "X" exit 1
if not "%INSTALLER_VER%" == "1.0.0" exit 1
if not "%INSTALLER_PLAT%" == "win-64" exit 1
if not "%INSTALLER_TYPE%" == "EXE" exit 1
if not "%INSTALLER_UNATTENDED%" == "1" exit 1
Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/pre_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ echo "CUSTOM_VARIABLE_2=${CUSTOM_VARIABLE_2}"
echo "PREFIX=${PREFIX}"

test "${INSTALLER_NAME}" = "Scripts"
test "${INSTALLER_VER}" = "X"
test "${INSTALLER_VER}" = "1.0.0"
# shellcheck disable=SC2016 # String interpolation disabling is deliberate
test "${CUSTOM_VARIABLE_1}" = 'FIR$T-CUSTOM_'\''STRING'\'' WITH SPACES AND @*! "CHARACTERS"'
# shellcheck disable=SC2016 # String interpolation disabling is deliberate
Expand Down
2 changes: 1 addition & 1 deletion examples/shortcuts/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

name: MinicondaWithShortcuts
version: X
installer_type: all
installer_type: {{ "exe" if os.name == "nt" else "all" }}

channels:
- conda-test/label/menuinst-tests
Expand Down
2 changes: 1 addition & 1 deletion examples/signing/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "../../constructor/data/construct.schema.json"

name: Signed
version: X
version: 1.0.0
installer_type: all
channels:
- https://repo.anaconda.com/pkgs/main/
Expand Down
2 changes: 1 addition & 1 deletion examples/virtual_specs_failed/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ initialize_by_default: false
register_python: false
check_path_spaces: false
check_path_length: false
installer_type: all
installer_type: {{ "exe" if os.name == "nt" else "all" }}
2 changes: 1 addition & 1 deletion examples/virtual_specs_ok/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ initialize_by_default: false
register_python: false
check_path_spaces: false
check_path_length: false
installer_type: all
installer_type: {{ "exe" if os.name == "nt" else "all" }}
Loading
Loading