Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit 43f9041

Browse files
committed
CI on Windows using AppVeyor
1 parent 8dbc8e3 commit 43f9041

File tree

5 files changed

+86
-43
lines changed

5 files changed

+86
-43
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ libsass: SASS_ for Python
99
:target: https://travis-ci.org/dahlia/libsass-python
1010
:alt: Build Status
1111

12+
.. image:: https://ci.appveyor.com/api/projects/status/yghrs9jw7b67c0ia
13+
:target: https://ci.appveyor.com/project/dahlia/libsass-python
14+
:alt: Build Status (Windows)
15+
1216
.. image:: https://img.shields.io/coveralls/dahlia/libsass-python.svg
1317
:target: https://coveralls.io/r/dahlia/libsass-python
1418
:alt: Coverage Status

appveyor.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
version: "{build}"
2+
environment:
3+
global:
4+
VS90COMNTOOLS: "%VS110COMNTOOLS%"
5+
VS100COMNTOOLS: "%VS110COMNTOOLS%"
6+
matrix:
7+
- PYTHON: "C:\\Python34_32"
8+
PYTHON_VERSION: "3.4.1"
9+
PYTHON_ARCH: "32"
10+
- PYTHON: "C:\\Python34_64"
11+
PYTHON_VERSION: "3.4.1"
12+
PYTHON_ARCH: "64"
13+
matrix:
14+
fast_finish: true
15+
init:
16+
- "ECHO %PYTHON%"
17+
- ps: "ls C:/Python*"
18+
install:
19+
- "git -C %APPVEYOR_BUILD_FOLDER% submodule update --init"
20+
- ps: (new-object net.webclient).DownloadFile('https://raw.githubusercontent.com/ogrisel/python-appveyor-demo/master/appveyor/install.ps1', 'C:/python-install.ps1')
21+
- "powershell C:/python-install.ps1"
22+
build: false
23+
test_script:
24+
- "%PYTHON%\\python.exe setup.py test"
25+
after_test:
26+
- ps: (new-object net.webclient).DownloadFile('https://bootstrap.pypa.io/get-pip.py', 'C:/get-pip.py')
27+
- "%PYTHON%\\python.exe C:/get-pip.py"
28+
- "%PYTHON%\\Scripts\\pip.exe --version"
29+
- "%PYTHON%\\Scripts\\pip.exe install wheel"
30+
- "%PYTHON%\\python.exe setup.py bdist_wheel"
31+
artifects:
32+
- path: dist\*

docs/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ Travis CI
9595
:target: https://travis-ci.org/dahlia/libsass-python
9696
:alt: Build Status
9797

98+
AppVeyor (CI for Windows)
99+
https://ci.appveyor.com/project/dahlia/libsass-python
100+
101+
.. image:: https://ci.appveyor.com/api/projects/status/yghrs9jw7b67c0ia?retina=true
102+
:target: https://ci.appveyor.com/project/dahlia/libsass-python
103+
:alt: Build Status (Windows)
104+
:width: 100
105+
:height: 18
106+
98107
Coveralls (Test coverage)
99108
https://coveralls.io/r/dahlia/libsass-python
100109

ez_setup.py

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@
2626

2727
from distutils import log
2828

29+
try:
30+
from urllib.request import urlopen
31+
except ImportError:
32+
from urllib2 import urlopen
33+
2934
try:
3035
from site import USER_SITE
3136
except ImportError:
3237
USER_SITE = None
3338

34-
DEFAULT_VERSION = "3.6"
39+
DEFAULT_VERSION = "5.7"
3540
DEFAULT_URL = "https://pypi.python.org/packages/source/s/setuptools/"
3641

3742
def _python_cmd(*args):
@@ -64,17 +69,24 @@ def _build_egg(egg, archive_filename, to_dir):
6469
raise IOError('Could not build the egg.')
6570

6671

67-
def get_zip_class():
72+
class ContextualZipFile(zipfile.ZipFile):
6873
"""
6974
Supplement ZipFile class to support context manager for Python 2.6
7075
"""
71-
class ContextualZipFile(zipfile.ZipFile):
72-
def __enter__(self):
73-
return self
74-
def __exit__(self, type, value, traceback):
75-
self.close
76-
return zipfile.ZipFile if hasattr(zipfile.ZipFile, '__exit__') else \
77-
ContextualZipFile
76+
77+
def __enter__(self):
78+
return self
79+
80+
def __exit__(self, type, value, traceback):
81+
self.close()
82+
83+
def __new__(cls, *args, **kwargs):
84+
"""
85+
Construct a ZipFile or ContextualZipFile as appropriate
86+
"""
87+
if hasattr(zipfile.ZipFile, '__exit__'):
88+
return zipfile.ZipFile(*args, **kwargs)
89+
return super(ContextualZipFile, cls).__new__(cls)
7890

7991

8092
@contextlib.contextmanager
@@ -85,7 +97,7 @@ def archive_context(filename):
8597
old_wd = os.getcwd()
8698
try:
8799
os.chdir(tmpdir)
88-
with get_zip_class()(filename) as archive:
100+
with ContextualZipFile(filename) as archive:
89101
archive.extractall()
90102

91103
# going in the directory
@@ -183,14 +195,11 @@ def has_powershell():
183195
if platform.system() != 'Windows':
184196
return False
185197
cmd = ['powershell', '-Command', 'echo test']
186-
devnull = open(os.path.devnull, 'wb')
187-
try:
198+
with open(os.path.devnull, 'wb') as devnull:
188199
try:
189200
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
190201
except Exception:
191202
return False
192-
finally:
193-
devnull.close()
194203
return True
195204

196205
download_file_powershell.viable = has_powershell
@@ -201,14 +210,11 @@ def download_file_curl(url, target):
201210

202211
def has_curl():
203212
cmd = ['curl', '--version']
204-
devnull = open(os.path.devnull, 'wb')
205-
try:
213+
with open(os.path.devnull, 'wb') as devnull:
206214
try:
207215
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
208216
except Exception:
209217
return False
210-
finally:
211-
devnull.close()
212218
return True
213219

214220
download_file_curl.viable = has_curl
@@ -219,14 +225,11 @@ def download_file_wget(url, target):
219225

220226
def has_wget():
221227
cmd = ['wget', '--version']
222-
devnull = open(os.path.devnull, 'wb')
223-
try:
228+
with open(os.path.devnull, 'wb') as devnull:
224229
try:
225230
subprocess.check_call(cmd, stdout=devnull, stderr=devnull)
226231
except Exception:
227232
return False
228-
finally:
229-
devnull.close()
230233
return True
231234

232235
download_file_wget.viable = has_wget
@@ -236,45 +239,36 @@ def download_file_insecure(url, target):
236239
Use Python to download the file, even though it cannot authenticate the
237240
connection.
238241
"""
242+
src = urlopen(url)
239243
try:
240-
from urllib.request import urlopen
241-
except ImportError:
242-
from urllib2 import urlopen
243-
src = dst = None
244-
try:
245-
src = urlopen(url)
246-
# Read/write all in one block, so we don't create a corrupt file
247-
# if the download is interrupted.
244+
# Read all the data in one block.
248245
data = src.read()
249-
dst = open(target, "wb")
250-
dst.write(data)
251246
finally:
252-
if src:
253-
src.close()
254-
if dst:
255-
dst.close()
247+
src.close()
248+
249+
# Write all the data in one block to avoid creating a partial file.
250+
with open(target, "wb") as dst:
251+
dst.write(data)
256252

257253
download_file_insecure.viable = lambda: True
258254

259255
def get_best_downloader():
260-
downloaders = [
256+
downloaders = (
261257
download_file_powershell,
262258
download_file_curl,
263259
download_file_wget,
264260
download_file_insecure,
265-
]
266-
267-
for dl in downloaders:
268-
if dl.viable():
269-
return dl
261+
)
262+
viable_downloaders = (dl for dl in downloaders if dl.viable())
263+
return next(viable_downloaders, None)
270264

271265
def download_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL,
272266
to_dir=os.curdir, delay=15, downloader_factory=get_best_downloader):
273267
"""
274268
Download setuptools from a specified location and return its filename
275269
276270
`version` should be a valid setuptools version number that is available
277-
as an egg for download under the `download_base` URL (which should end
271+
as an sdist for download under the `download_base` URL (which should end
278272
with a '/'). `to_dir` is the directory where the egg will be downloaded.
279273
`delay` is the number of seconds to pause before an actual download
280274
attempt.

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
raise SystemExit(1)
5353

5454
if sys.platform == 'win32':
55+
from distutils.msvccompiler import MSVCCompiler
5556
from distutils.msvc9compiler import get_build_version
5657
vscomntools_env = 'VS{0}{1}COMNTOOLS'.format(
5758
int(get_build_version()),
@@ -65,6 +66,9 @@
6566
distutils.log.warn('%%%s%%=%s',
6667
vscomntools_env,
6768
os.environ.get(vscomntools_env, ''))
69+
c = MSVCCompiler()
70+
c.initialize()
71+
distutils.log.warn('msvc_paths = %r', c.get_msvc_paths('path'))
6872
# Workaround http://bugs.python.org/issue4431 under Python <= 2.6
6973
if sys.version_info < (2, 7):
7074
def spawn(self, cmd):

0 commit comments

Comments
 (0)