Skip to content

Commit

Permalink
Merge pull request #194 from jacebrowning/appveyor
Browse files Browse the repository at this point in the history
Enable Appveyor to test Windows compatiblity
  • Loading branch information
jacebrowning committed Apr 22, 2016
2 parents 7a59713 + c529441 commit c387dd4
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 72 deletions.
15 changes: 15 additions & 0 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cache:
- env

install:
# Export build paths
- copy C:\MinGW\bin\mingw32-make.exe C:\MinGW\bin\make.exe
- set PATH=%PATH%;C:\MinGW\bin
- make --version
# Install project dependenies
- make depends-ci

build: off

test_script:
- make ci
3 changes: 2 additions & 1 deletion .pep8rc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

# E501: line too long (checked by PyLint)
# E711: comparison to None (used to improve test style)
ignore = E501,E711
# E712: comparison to True (used to improve test style)
ignore = E501,E711,E712
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ $(INSTALLED_FLAG): Makefile setup.py requirements.txt

$(PIP):
$(SYS_PYTHON) -m venv --clear $(ENV)
ifndef APPVEYOR
$(PIP) install --upgrade pip setuptools
endif

# Tools Installation ###########################################################

Expand Down Expand Up @@ -281,25 +283,31 @@ test-unit: depends-ci
$(PYTEST) $(PYTEST_OPTS) $(PACKAGE)
@- mv $(FAILURES).bak $(FAILURES)
ifndef TRAVIS
ifndef APPVEYOR
$(COVERAGE_SPACE) jacebrowning/memegen unit
endif
endif

.PHONY: test-int
test-int: depends-ci
@ if test -e $(FAILURES); then $(PYTEST) $(PYTEST_OPTS_FAILFAST) tests; fi
$(PYTEST) $(PYTEST_OPTS) tests
ifndef TRAVIS
ifndef APPVEYOR
$(COVERAGE_SPACE) jacebrowning/memegen integration
endif
endif

.PHONY: tests test-all
tests: test-all
test-all: depends-ci
@ if test -e $(FAILURES); then $(PYTEST) $(PYTEST_OPTS_FAILFAST) $(PACKAGE) tests; fi
$(PYTEST) $(PYTEST_OPTS) $(PACKAGE) tests
ifndef TRAVIS
ifndef APPVEYOR
$(COVERAGE_SPACE) jacebrowning/memegen overall
endif
endif

.PHONY: read-coverage
read-coverage:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

An API to generate meme images based solely on requested URLs.

[![Build Status](http://img.shields.io/travis/jacebrowning/memegen/master.svg)](https://travis-ci.org/jacebrowning/memegen)
[![Coverage Status](http://img.shields.io/coveralls/jacebrowning/memegen/master.svg)](https://coveralls.io/r/jacebrowning/memegen)
Unix: [![Unix Build Status](http://img.shields.io/travis/jacebrowning/memegen/master.svg)](https://travis-ci.org/jacebrowning/memegen)
Windows: [![Windows Build Status](https://img.shields.io/appveyor/ci/jacebrowning/memegen.svg)](https://ci.appveyor.com/project/jacebrowning/memegen)

Metrics: [![Coverage Status](http://img.shields.io/coveralls/jacebrowning/memegen/master.svg)](https://coveralls.io/r/jacebrowning/memegen)
[![Scrutinizer Code Quality](http://img.shields.io/scrutinizer/g/jacebrowning/memegen.svg)](https://scrutinizer-ci.com/g/jacebrowning/memegen/?branch=master)

## Generating Images
Expand Down
1 change: 0 additions & 1 deletion data/templates/sad-biden/default.jpg

This file was deleted.

Binary file added data/templates/sad-biden/default.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion data/templates/sad-bush/default.jpg

This file was deleted.

Binary file added data/templates/sad-bush/default.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion data/templates/sad-obama/default.jpg

This file was deleted.

Binary file added data/templates/sad-obama/default.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!env/bin/python

import os
import subprocess
import logging
from subprocess import check_output

from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
Expand All @@ -21,7 +21,8 @@
for name, command in [
('DEPLOY_DATE', "TZ=America/Detroit date '+%F %T'"),
]:
output = check_output(command, shell=True, universal_newlines=True).strip()
output = subprocess.run(command, shell=True, stdout=subprocess.PIPE,
universal_newlines=True).stdout.strip() or "???"
os.environ[name] = os.getenv(name, output)

# Configure the command-line interface
Expand Down
28 changes: 17 additions & 11 deletions memegen/domain/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import re
import hashlib
import shutil
from pathlib import Path
import tempfile
import logging

import time
Expand Down Expand Up @@ -109,9 +111,12 @@ def get_path(self, *styles):

for name in (n.lower() for n in (*styles, self.DEFAULT) if n):
for extension in self.EXTENSIONS:
path = os.path.join(self.dirpath, name + extension)
if os.path.isfile(path):
return path
path = Path(self.dirpath, name + extension)
try:
if path.is_file():
return path
except OSError:
continue

return None

Expand Down Expand Up @@ -164,13 +169,13 @@ def validate_meta(self):

def validate_link(self):
if self.link:
flag = os.path.join(self.dirpath, self.VALID_LINK_FLAG)
if os.path.isfile(flag):
flag = Path(self.dirpath, self.VALID_LINK_FLAG)
if flag.is_file():
log.info("Link already checked: %s", self.link)
else:
log.info("Checking link %s ...", self.link)
try:
response = requests.get(self.link, timeout=5)
response = requests.head(self.link, timeout=5)
except requests.exceptions.ReadTimeout:
log.warning("Connection timed out")
return True # assume URL is OK; it will be checked again
Expand All @@ -180,7 +185,7 @@ def validate_link(self):
self._error("link is invalid (%s)", response.status_code)
return False
else:
with open(flag, 'w') as stream:
with open(str(flag), 'w') as stream:
stream.write(str(int(time.time())))
return True

Expand Down Expand Up @@ -237,9 +242,10 @@ def download_image(url):
if not url or not url.startswith("http"):
return None

# /tmp is detroyed after every Heroku request
path = "/tmp/" + hashlib.md5(url.encode('utf-8')).hexdigest()
if os.path.isfile(path):
path = Path(tempfile.gettempdir(),
hashlib.md5(url.encode('utf-8')).hexdigest())

if path.is_file():
log.debug("Already downloaded: %s", url)
return path

Expand All @@ -254,7 +260,7 @@ def download_image(url):

if response.status_code == 200:
log.info("Downloading %s", url)
with open(path, 'wb') as outfile:
with open(str(path), 'wb') as outfile:
response.raw.decode_content = True
shutil.copyfileobj(response.raw, outfile)
return path
Expand Down
13 changes: 8 additions & 5 deletions memegen/stores/image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# pylint: disable=no-member

import os
import shutil
from contextlib import suppress
import logging

import sqlalchemy as sa
Expand Down Expand Up @@ -84,13 +86,14 @@ def create(self, image):
if self.exists(image) and not self.regenerate_images:
return

ImageModel(image)
try:
ImageModel(image)
except ImportError:
log.warning("Unable to store models on this machine")

image.root = self.root
image.generate()

try:
with suppress(IOError):
os.remove(self.latest)
except IOError:
pass
os.symlink(image.path, self.latest)
shutil.copy(image.path, self.latest)

0 comments on commit c387dd4

Please sign in to comment.