Skip to content

Commit a0c7c60

Browse files
committed
Fix filename selector matching Windows filenames
- Fix filename matching to use os.sep - Add Appveyor builds
1 parent 1a7cfc7 commit a0c7c60

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

.appveyor.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
environment:
2+
matrix:
3+
- PYTHON: "C:\\Python27"
4+
APPVEYOR_PYTHON_VERSION: "2.7.x" # currently 2.7.11
5+
6+
- PYTHON: "C:\\Python34"
7+
APPVEYOR_PYTHON_VERSION: "3.4.x" # currently 3.4.3
8+
9+
init:
10+
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
11+
- "ECHO PATH=%PATH%"
12+
- python --version
13+
14+
build: off
15+
16+
install:
17+
- pip install tox wheel
18+
19+
test_script:
20+
- tox -e pytest
21+
- tox -e flakes-v250,flakes-v241,flakes-v230,flakes-v224,flakes-v220
22+
23+
deploy_script:
24+
- python setup.py sdist bdist_wheel
25+
26+
artifacts:
27+
- path: dist\* .coverage coverage.xml

flake8_putty/config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
except ImportError:
1313
markers = None
1414

15+
IS_WINDOWS = (sys.platform == 'win32')
16+
1517
SELECTOR_SPLITTER = re.compile(r' *(/.*?(?<!\\)/|[^/][^,]*) *,?')
1618

1719
ENVIRONMENT_MARKER_PREFIXES = (
@@ -236,7 +238,10 @@ def __eq__(self, other):
236238
def file_match_any(self, filename):
237239
"""Match any filename."""
238240
if filename.startswith('.' + os.sep):
239-
filename = filename[2:]
241+
filename = filename[len(os.sep) + 1:]
242+
if os.sep != '/':
243+
filename = filename.replace(os.sep, '/')
244+
240245
for selector in self.file_selectors:
241246
if (selector.pattern.endswith('/') and
242247
filename.startswith(selector.pattern)):

tests/test_config.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"""Test config parser."""
33
from __future__ import unicode_literals
44

5+
import os
6+
57
from unittest import TestCase
68

79
from flake8_putty.config import (
@@ -258,7 +260,7 @@ class TestMatch(TestCase):
258260
def test_selector_filename(self):
259261
p = Parser('foo.py : E101')
260262
assert p._rules[0].file_match_any('foo.py')
261-
assert p._rules[0].file_match_any('./foo.py')
263+
assert p._rules[0].file_match_any('.{0}foo.py'.format(os.sep))
262264
assert not p._rules[0].file_match_any('bar.py')
263265
assert not p._rules[0].file_match_any('foo/bar.py')
264266

@@ -270,7 +272,7 @@ def test_selector_filename_missing(self):
270272
def test_selector_filename_multi(self):
271273
p = Parser('foo.py, bar.py : E101')
272274
assert p._rules[0].file_match_any('foo.py')
273-
assert p._rules[0].file_match_any('./foo.py')
275+
assert p._rules[0].file_match_any('.{0}foo.py'.format(os.sep))
274276
assert p._rules[0].file_match_any('bar.py')
275277
assert not p._rules[0].file_match_any('foo/bar.py')
276278

@@ -295,7 +297,9 @@ def test_selector_directory_multi(self):
295297
def test_selector_directory_wildcard(self):
296298
p = Parser('tests/*/test_*.py : E101')
297299
assert p._rules[0].file_match_any('tests/foo/test_bar.py')
298-
assert p._rules[0].file_match_any('./tests/foo/bar/test_baz.py')
300+
assert p._rules[0].file_match_any(
301+
'.{0}tests/foo/bar/test_baz.py'.format(os.sep),
302+
)
299303
assert p._rules[0].file_match_any('tests/foo/bar/test_.py')
300304
assert not p._rules[0].file_match_any('tests/test_foo.py')
301305

tox.ini

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ skip_missing_interpreters = True
33
envlist = flakes-v{250,241,230,224,220},green,pytest,test
44

55
[testenv]
6-
passenv = CI TRAVIS_BUILD_ID TRAVIS TRAVIS_BRANCH TRAVIS_JOB_NUMBER TRAVIS_PULL_REQUEST TRAVIS_JOB_ID TRAVIS_REPO_SLUG TRAVIS_COMMIT
6+
passenv =
7+
CI
8+
TRAVIS TRAVIS_BUILD_ID TRAVIS_BRANCH TRAVIS_JOB_NUMBER TRAVIS_PULL_REQUEST
9+
TRAVIS_JOB_ID TRAVIS_REPO_SLUG TRAVIS_COMMIT
10+
APPVEYOR APPVEYOR_ACCOUNT_NAME APPVEYOR_PROJECT_SLUG APPVEYOR_REPO_NAME
11+
APPVEYOR_REPO_COMMIT APPVEYOR_REPO_BRANCH APPVEYOR_BUILD_VERSION
12+
APPVEYOR_JOB_ID APPVEYOR_PULL_REQUEST_NUMBER
713
commands =
814
flakes: flake8 --version
915
flakes: flake8 {posargs}
@@ -40,7 +46,8 @@ deps =
4046
v250,v241: hacking
4147
v250,v241: flake8-coding
4248
v250,v241: flake8-tuple
43-
v250,v241: flake8-mock
49+
# https://github.com/aleGpereira/flake8-mock/issues/3
50+
v250,v241: flake8-mock ; sys_platform != 'win32' or python_version < '3'
4451
v250,v241: flake8-dodgy
4552
v250,v241: flake8-tidy-imports
4653
v250,v241: flake8-import-order # hacking has a similar rule
@@ -50,7 +57,9 @@ deps =
5057
# The following are run in a different toxenv,
5158
# as they are similar to one of the above plugins
5259
v230,v224: flake8-blind-except # hacking has a similar rule
53-
v230,v224: flake8-isort # similar to flake8-import-order
60+
# isort uses customised rules in setup.cfg to behave like flake8-import-order
61+
# https://github.com/timothycrosley/isort/issues/419
62+
v230,v224: flake8-isort ; sys_platform != 'win32'
5463
v230,v224: flake8-future ; python_version > '2.6' # similar to flake8-future-import
5564
v230,v224: git+https://github.com/jayvdb/flake8-future@py26 ; python_version < '2.7'
5665

0 commit comments

Comments
 (0)