Skip to content

Commit

Permalink
make it compatible with windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pchtsp committed Jul 12, 2024
1 parent 1cabad0 commit 906fc6a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
22 changes: 16 additions & 6 deletions pulp/apis/copt_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
import warnings

from uuid import uuid4
from .core import sparse, ctypesArrayFill, PulpSolverError
from .core import clock

from .core import LpSolver, LpSolver_CMD
from .core import (
sparse,
ctypesArrayFill,
PulpSolverError,
LpSolver,
LpSolver_CMD,
clock,
operating_system,
)
from ..constants import (
LpStatusNotSolved,
LpStatusOptimal,
Expand Down Expand Up @@ -896,9 +901,14 @@ def __init__(
)
# workaround to deactivate logging when msg=False
if not self.msg:
devnull = open("/dev/null", "w")
oldstdout_fno = os.dup(sys.stdout.fileno())
os.dup2(devnull.fileno(), 1)
if operating_system == "win":
# windows doesn't have /dev/null
os.dup2(0, 1)
else:
# linux and mac should have /dev/null
devnull = open("/dev/null", "w")
os.dup2(devnull.fileno(), 1)
self.coptenv = coptpy.Envr()
self.coptmdl = self.coptenv.createModel()
os.dup2(oldstdout_fno, 1)
Expand Down
7 changes: 1 addition & 6 deletions pulp/pulp.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,7 @@
from . import constants as const
from . import mps_lp as mpslp

try:
from collections.abc import Iterable
except ImportError:
# python 2.7 compatible
from collections.abc import Iterable

from collections.abc import Iterable
import logging

log = logging.getLogger(__name__)
Expand Down

0 comments on commit 906fc6a

Please sign in to comment.