Skip to content

Commit

Permalink
build_exe: fix typo in command line boolean option 'include-msvcr' (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelotduarte committed Sep 21, 2023
1 parent 71802a2 commit cd918dc
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 8 deletions.
17 changes: 10 additions & 7 deletions cx_Freeze/command/build_exe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Implements the 'build_exe' command."""

from __future__ import annotations

import logging
Expand All @@ -9,10 +8,10 @@

from setuptools import Command

from ..common import normalize_to_list
from ..exception import SetupError
from ..freezer import Freezer
from ..module import ConstantsModule
from cx_Freeze.common import normalize_to_list
from cx_Freeze.exception import SetupError
from cx_Freeze.freezer import Freezer
from cx_Freeze.module import ConstantsModule

__all__ = ["BuildEXE"]

Expand Down Expand Up @@ -119,12 +118,12 @@ class BuildEXE(Command):
" level 3: suppress all warning messages",
),
(
"include-msvcr=",
"include-msvcr",
None,
"include the Microsoft Visual C runtime files",
),
]
boolean_options = ["no-compress", "include_msvcr", "silent"]
boolean_options = ["no-compress", "include-msvcr", "silent"]

def add_to_path(self, name):
source_dir = getattr(self, name.lower())
Expand Down Expand Up @@ -240,6 +239,10 @@ def finalize_options(self):
else:
self.silent_setting = 1

#
if self.include_msvcr is None:
self.include_msvcr = False

# Make sure all options of multiple values are lists
for option in self.list_options:
setattr(self, option, normalize_to_list(getattr(self, option)))
Expand Down
53 changes: 52 additions & 1 deletion tests/test_command_build_exe.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Tests for cx_Freeze.command.build_exe."""

from __future__ import annotations

import os
Expand All @@ -10,6 +9,9 @@

import pytest
from generate_samples import SUB_PACKAGE_TEST, create_package
from setuptools import Distribution

from cx_Freeze.command.build_exe import BuildEXE as build_exe

PLATFORM = get_platform()
PYTHON_VERSION = get_python_version()
Expand All @@ -21,6 +23,31 @@

OUTPUT_SUBPACKAGE_TEST = "This is p.p1\nThis is p.q.q1\n"

DIST_ATTRS = {
"name": "foo",
"version": "0.0",
"executables": [],
"script_name": "setup.py",
}


@pytest.mark.skipif(sys.platform != "win32", reason="Windows tests")
@pytest.mark.parametrize(
("option", "value", "result"),
[
("include_msvcr", True, True),
("include_msvcr", None, False),
("include_msvcr", False, False),
],
)
def test_build_exe_with_include_msvcr_option(option, value, result):
"""Test the bdist_exe with include-msvcr option."""
dist = Distribution(DIST_ATTRS)
cmd = build_exe(dist, **{option: value})
cmd.finalize_options()
cmd.ensure_finalized()
assert cmd.include_msvcr == result


@pytest.mark.datafiles(FIXTURE_DIR.parent / "samples" / "advanced")
def test_build_exe_advanced(datafiles: Path):
Expand Down Expand Up @@ -94,6 +121,30 @@ def test_build_exe_simple(datafiles: Path):
assert output.startswith("Hello from cx_Freeze")


@pytest.mark.skipif(sys.platform != "win32", reason="Windows tests")
@pytest.mark.datafiles(FIXTURE_DIR.parent / "samples" / "simple")
def test_build_exe_simple_include_msvcr(datafiles: Path):
"""Test the simple sample with include_msvcr option."""
output = check_output(
[
sys.executable,
"setup.py",
"build_exe",
"--silent",
"--excludes=tkinter",
"--include-msvcr",
],
text=True,
cwd=os.fspath(datafiles),
)
print(output)
suffix = ".exe" if sys.platform == "win32" else ""
executable = datafiles / BUILD_EXE_DIR / f"hello{suffix}"
assert executable.is_file()
output = check_output([os.fspath(executable)], text=True, timeout=10)
assert output.startswith("Hello from cx_Freeze")


@pytest.mark.datafiles(FIXTURE_DIR.parent / "samples" / "sqlite")
def test_build_exe_sqlite(datafiles: Path):
"""Test the sqlite sample."""
Expand Down

0 comments on commit cd918dc

Please sign in to comment.