Skip to content

Commit

Permalink
Merge pull request #428 from FaustinCarter/bugfix-platform-selectors-…
Browse files Browse the repository at this point in the history
…regex
  • Loading branch information
mcg1969 authored Feb 12, 2021
2 parents a47cf27 + 5527b84 commit e38d014
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 31 deletions.
38 changes: 28 additions & 10 deletions constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from constructor.exceptions import (UnableToParse, UnableToParseMissingJinja2,
YamlParsingError)


# list of tuples (key name, required, type, description)
KEYS = [
('name', True, str, '''
Expand Down Expand Up @@ -314,21 +313,40 @@ def ns_platform(platform):
win64=bool(p == 'win-64'),
)


sel_pat = re.compile(r'(.+?)\s*\[(.+)\]$')

# This regex is taken from https://github.com/conda/conda_build/metadata.py
# The following function "select_lines" is also a slightly modified version of
# the function of the same name from conda_build/metadata.py
sel_pat = re.compile(r'(.+?)\s*(#.*)?\[([^\[\]]+)\](?(2)[^\(\)]*)$')

def select_lines(data, namespace):
lines = []
for line in data.splitlines():

for i, line in enumerate(data.splitlines()):
line = line.rstrip()

trailing_quote = ""
if line and line[-1] in ("'", '"'):
trailing_quote = line[-1]

if line.lstrip().startswith('#'):
# Don't bother with comment only lines
continue
m = sel_pat.match(line)
if m:
cond = m.group(2)
if eval(cond, namespace, {}):
lines.append(m.group(1))
continue
lines.append(line)
cond = m.group(3)
try:
if eval(cond, namespace, {}):
lines.append(m.group(1) + trailing_quote)
except Exception as e:
sys.exit('''\
Error: Invalid selector in meta.yaml line %d:
offending line:
%s
exception:
%s
''' % (i + 1, line, str(e)))
else:
lines.append(line)
return '\n'.join(lines) + '\n'


Expand Down
16 changes: 8 additions & 8 deletions examples/grin/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ channels: &id1
specs:
- python
- grin
- sample [osx]
- sample # [osx]

# exclude these packages (list of names)
exclude:
- openssl [unix]
- readline [unix]
- tk [unix]
- openssl # [unix]
- readline # [unix]
- tk # [unix]
- python

# explicitly listed packages
Expand All @@ -27,9 +27,9 @@ packages:

keep_pkgs: True

pre_install: hello.sh [unix]
post_install: goodbye.sh [unix]
post_install: test-post.bat [win]
pre_install: hello.sh # [unix]
post_install: goodbye.sh # [unix]
post_install: test-post.bat # [win]

# The conda default channels which are used when running a conda which
# was installed be the constructor created (requires conda in the
Expand All @@ -38,7 +38,7 @@ conda_default_channels: *id1

# type of the installer being created. Possible values are "sh", "pkg",
# and "exe". By default, the type is "sh" on Unix, and "exe" on Windows.
installer_type: pkg [osx]
installer_type: pkg # [osx]

# installer filename (a reasonable default filename will determined by
# the `name`, (optional) `version`, OS and installer type)
Expand Down
16 changes: 8 additions & 8 deletions examples/jetsonconda/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ channels:

specs:
- python 3.6*
- conda [aarch64]
- numpy [aarch64]
- scipy [aarch64]
- pandas [aarch64]
- notebook [aarch64]
- matplotlib [aarch64]
- freetype [aarch64]
- conda # [aarch64]
- numpy # [aarch64]
- scipy # [aarch64]
- pandas # [aarch64]
- notebook # [aarch64]
- matplotlib # [aarch64]
- freetype # [aarch64]

#license_file: EULA.txt

# Welcome image for Windows installer
welcome_image: bird.png [win]
welcome_image: bird.png # [win]
6 changes: 3 additions & 3 deletions examples/maxiconda/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ channels:
specs:
- python 3.5*
- conda
- nomkl [not win]
- nomkl # [not win]
- numpy
- scipy
- pandas
- notebook
- matplotlib
- lighttpd [unix]
- lighttpd # [unix]

exclude:
- qt
Expand All @@ -23,4 +23,4 @@ exclude:
license_file: EULA.txt

# Welcome image for Windows installer
welcome_image: bird.png [win]
welcome_image: bird.png # [win]
4 changes: 2 additions & 2 deletions examples/osxpkg/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ specs:
- setuptools
- numpy

post_install: post_install.sh [unix]
installer_type: pkg [osx]
post_install: post_install.sh # [unix]
installer_type: pkg # [osx]

0 comments on commit e38d014

Please sign in to comment.