Skip to content

Commit

Permalink
Merge pull request #156 from vasily-v-ryabov/cache_handling
Browse files Browse the repository at this point in the history
Fix "pip install comtypes" error, add the test on AppVeyor
  • Loading branch information
vasily-v-ryabov authored Jul 10, 2018
2 parents 534c5e2 + 4bc767f commit 36e997b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ environment:

test_script:
- C:\%py%\python.exe setup.py install
- C:\%py%\Scripts\pip.exe uninstall comtypes -y
- C:\%py%\python.exe test_pip_install.py
2 changes: 1 addition & 1 deletion comtypes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

# comtypes version numbers follow semver (http://semver.org/) and PEP 440
__version__ = "1.1.5"
__version__ = "1.1.6"

import logging
class NullHandler(logging.Handler):
Expand Down
21 changes: 18 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"comtypes package install script"

"""comtypes package install script"""
import sys
import os
import ctypes
Expand Down Expand Up @@ -85,7 +84,6 @@ def read_version():
# Determine the version number by reading it from the file
# 'comtypes\__init__.py'. We cannot import this file (with py3,
# at least) because it is in py2.x syntax.
ns = {}
for line in open("comtypes/__init__.py"):
if line.startswith("__version__ = "):
var, value = line.split('=')
Expand All @@ -94,6 +92,23 @@ def read_version():


class post_install(install):

# both this static variable and method initialize_options() help to avoid
# weird setuptools error with "pip install comtypes", details are here:
# https://github.com/enthought/comtypes/issues/155
# the working solution was found here:
# https://github.com/pypa/setuptools/blob/3b90be7bb6323eb44d0f28864509c1d47aa098de/setuptools/command/install.py
user_options = install.user_options + [
('old-and-unmanageable', None, "Try not to use this!"),
('single-version-externally-managed', None,
"used by system package builders to create 'flat' eggs"),
]

def initialize_options(self):
install.initialize_options(self)
self.old_and_unmanageable = None
self.single_version_externally_managed = None

def run(self):
install.run(self)
# Custom script we run at the end of installing - this is the same script
Expand Down
24 changes: 24 additions & 0 deletions test_pip_install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""This test covers 'pip install' issue #155"""
import os
import sys
import subprocess

def read_version():
# Determine the version number by reading it from the file
# 'comtypes\__init__.py'. We cannot import this file (with py3,
# at least) because it is in py2.x syntax.
for line in open("comtypes/__init__.py"):
if line.startswith("__version__ = "):
var, value = line.split('=')
return value.strip().strip('"').strip("'")
raise NotImplementedError("__version__ is not found in __init__.py")

# prepare the same package that is usually uploaded to PyPI
subprocess.check_call([sys.executable, 'setup.py', 'sdist', '--format=zip'])

filename_for_upload = 'comtypes-%s.zip' % read_version()
target_package = os.path.join(os.getcwd(), 'dist', filename_for_upload)

# run "pip install comtypes-x.y.z.zip"
pip_exe = os.path.join(os.path.dirname(sys.executable), 'Scripts', 'pip.exe')
subprocess.check_call([pip_exe, 'install', target_package])

0 comments on commit 36e997b

Please sign in to comment.