Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nsist: use "/" when comparing fnmatch patterns #148

Merged
merged 1 commit into from Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/cfgfile.rst
Expand Up @@ -276,6 +276,10 @@ the line with the key:
contradicts your ``files`` or ``packages`` option, the files in question
will be included (you can not exclude a full package/extra directory
or a single file listed in ``files``).
* Exclude patterns are applied uniformly across platforms and can use
either Unix-style forward-slash (`/`), or Windows-style back-slash (`\`)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

N.B. inline code in rst uses double backticks. It's possible to configure single backticks to mean the same, but I don't think I have on this project.

We should also build the docs and check whether the backslash shows up - it might be treated as an escape.

path separators. Exclude patterns are normalized so that patterns
written on Unix will work on Windows, and vice-versa.

Example:

Expand Down
4 changes: 2 additions & 2 deletions nsist/__init__.py
Expand Up @@ -24,7 +24,7 @@
from .copymodules import copy_modules
from .nsiswriter import NSISFileWriter
from .pypi import fetch_pypi_wheels
from .util import download, text_types, get_cache_dir
from .util import download, text_types, get_cache_dir, normalize_path

__version__ = '2.1'

Expand Down Expand Up @@ -103,7 +103,7 @@ def __init__(self, appname, version, shortcuts, *, publisher=None,
self.shortcuts = shortcuts
self.icon = icon
self.packages = packages or []
self.exclude = [os.path.normpath(p) for p in (exclude or [])]
self.exclude = [normalize_path(p) for p in (exclude or [])]
self.extra_files = extra_files or []
self.pypi_wheel_reqs = pypi_wheel_reqs or []
self.extra_wheel_sources = extra_wheel_sources or []
Expand Down
5 changes: 3 additions & 2 deletions nsist/copymodules.py
Expand Up @@ -9,6 +9,8 @@
import fnmatch
from functools import partial

from .util import normalize_path

pjoin = os.path.join

PY2 = sys.version_info[0] == 2
Expand Down Expand Up @@ -77,8 +79,7 @@ def copytree_ignore_callback(excludes, pkgdir, modname, directory, files):
# Filter by file names relative to the build directory
reldir = os.path.relpath(directory, pkgdir)
target = os.path.join('pkgs', modname, reldir)
files = [os.path.normpath(os.path.join(target, fname)) for fname in files]

files = [normalize_path(os.path.join(target, fname)) for fname in files]
# Execute all patterns
for pattern in excludes + ['*.pyc']:
ignored.update([
Expand Down
3 changes: 2 additions & 1 deletion nsist/pypi.py
Expand Up @@ -15,7 +15,7 @@
import yarg
from requests_download import download, HashTracker

from .util import get_cache_dir
from .util import get_cache_dir, normalize_path

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -261,6 +261,7 @@ def fetch_pypi_wheels(requirements, target_dir, py_version, bitness,

def is_excluded(path, exclude):
"""Return True if path matches an exclude pattern"""
path = normalize_path(path)
for pattern in (exclude or ()):
if fnmatch.fnmatch(path, pattern):
return True
Expand Down
5 changes: 5 additions & 0 deletions nsist/util.py
Expand Up @@ -64,3 +64,8 @@ def get_cache_dir(ensure_existence=False):
raise

return p


def normalize_path(path):
"""Normalize paths to contain "/" only"""
return os.path.normpath(path).replace('\\', '/')