Skip to content

Commit

Permalink
Fix koapy install/uninstall pywin32 command
Browse files Browse the repository at this point in the history
  • Loading branch information
elbakramer committed Dec 16, 2021
1 parent 4b7e2fe commit a920320
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 0 additions & 1 deletion koapy/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from koapy.cli.commands.update import update
from koapy.cli.utils import fail_with_usage, verbose_option
from koapy.cli.utils.credential import get_credential
from koapy.config import config
from koapy.utils.logging import get_logger

logger = get_logger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion koapy/cli/commands/get/codelist_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import pygtrie

from koapy import KiwoomOpenApiPlusEntrypoint
from koapy.utils.logging.Logging import Logging


Expand Down Expand Up @@ -91,6 +90,8 @@ def __init__(self, screen):
self._logger = Logging.get_logger("koapy")
self._logger.addHandler(self._handler)

from koapy import KiwoomOpenApiPlusEntrypoint

self._entrypoint = KiwoomOpenApiPlusEntrypoint()
self._entrypoint.EnsureConnected()

Expand Down
12 changes: 7 additions & 5 deletions koapy/cli/utils/pywin32.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@


def get_pywin32_postinstall_script(filepath):
url = "https://raw.githubusercontent.com/elbakramer/pywin32/patch-1/pywin32_postinstall.py"
url = (
"https://raw.githubusercontent.com/mhammond/pywin32/main/pywin32_postinstall.py"
)
response = requests.get(url)
with open(filepath, "wb") as f:
f.write(response.content)


def install_pywin32(version=None):
if version is None:
version = "301"
version = "302"
cmd = ["pip", "install", "pywin32>={}".format(version)]
logger.info("Running command: %s", subprocess.list2cmdline(cmd))
subprocess.check_call(cmd)
Expand All @@ -33,13 +35,13 @@ def install_pywin32(version=None):


def uninstall_pywin32():
cmd = ["pip", "uninstall", "pywin32"]
logger.info("Running command: %s", subprocess.list2cmdline(cmd))
subprocess.check_call(cmd)
with tempfile.TemporaryDirectory() as tempdir:
script_filename = "pywin32_postinstall.py"
script_filepath = os.path.join(tempdir, script_filename)
get_pywin32_postinstall_script(script_filepath)
cmd = [sys.executable, script_filepath, "-remove"]
logger.info("Running command: %s", subprocess.list2cmdline(cmd))
subprocess.check_call(cmd)
cmd = ["pip", "uninstall", "pywin32"]
logger.info("Running command: %s", subprocess.list2cmdline(cmd))
subprocess.check_call(cmd)

0 comments on commit a920320

Please sign in to comment.