Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
python_version: '3.6'
python_architecture: 'x86'
py37:
python_version: '3.7.4'
python_version: '3.7'
python_architecture: 'x86'

- template: etc/ci/azure-win.yml
Expand Down
4 changes: 1 addition & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# change these variables to customize this script locally
################################
# you can define one or more thirdparty dirs, each prefixed with TPP_DIR
export TPP_DIR_BASE="thirdparty/base"
export TPP_DIR_DEV="thirdparty/dev"
export TPP_DIR_PROD="thirdparty/prod"
export TPP_DIR_BASE="thirdparty"

# default configurations for dev
CONF_DEFAULT="etc/conf/dev"
Expand Down
112 changes: 54 additions & 58 deletions configure.bat
Original file line number Diff line number Diff line change
@@ -1,58 +1,54 @@
@echo ON
setlocal
@rem Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved.

@rem ################################
@rem # Defaults. change these variables to customize this script locally
@rem ################################
@rem # you can define one or more thirdparty dirs, each prefixed with TPP_DIR
set TPP_DIR_BASE=thirdparty/base
set TPP_DIR_DEV=thirdparty/dev
set TPP_DIR_PROD=thirdparty/prod

set DEFAULT_PYTHON=python

@rem # default configurations
set CONF_DEFAULT="etc/conf/dev"
@rem #################################

@rem this always has a trailing backslash
set CFG_ROOT_DIR=%~dp0

@rem a possible alternative way and simpler way to slurp args
@rem set CFG_CMD_LINE_ARGS=%*

@rem Collect all command line arguments in a variable
set CFG_CMD_LINE_ARGS=

:collectarg
if ""%1""=="""" goto continue
set CFG_CMD_LINE_ARGS=%CFG_CMD_LINE_ARGS% %1
shift
goto collectarg

:continue


@rem Set defaults
if "%CFG_CMD_LINE_ARGS%"=="" set CFG_CMD_LINE_ARGS=%CONF_DEFAULT%
if "%PYTHON_EXE%"=="" set PYTHON_EXE=%DEFAULT_PYTHON%


call "%PYTHON_EXE%" %CFG_ROOT_DIR%\etc\configure.py %CFG_CMD_LINE_ARGS%


@rem Return a proper return code on failure
if %errorlevel% neq 0 (
exit /b %errorlevel%
)


@rem Activate the virtualenv
endlocal
if exist "%CFG_ROOT_DIR%bin\activate" (
"%CFG_ROOT_DIR%bin\activate"
)
goto EOS

:EOS
@echo OFF
setlocal
@rem Copyright (c) nexB Inc. http://www.nexb.com/ - All rights reserved.

@rem ################################
@rem # Defaults. change these variables to customize this script locally
@rem ################################
@rem # you can define one or more thirdparty dirs, each prefixed with TPP_DIR
set TPP_DIR=thirdparty

set DEFAULT_PYTHON=python

@rem # default configurations for dev
set CONF_DEFAULT="etc/conf/dev"
@rem #################################

set CFG_ROOT_DIR=%~dp0

@rem Collect all command line arguments in a variable
set CFG_CMD_LINE_ARGS=

@rem a possible alternative way and simpler way to slurp args
@rem set CFG_CMD_LINE_ARGS=%*


:collectarg
if ""%1""=="""" goto continue
call set CFG_CMD_LINE_ARGS=%CFG_CMD_LINE_ARGS% %1
shift
goto collectarg

:continue

@rem Set defaults when no args are passed
if "%CFG_CMD_LINE_ARGS%"=="" set CFG_CMD_LINE_ARGS="%CONF_DEFAULT%"
if "%PYTHON_EXE%"=="" set PYTHON_EXE=%DEFAULT_PYTHON%


call "%PYTHON_EXE%" "%CFG_ROOT_DIR%etc\configure.py" %CFG_CMD_LINE_ARGS%
@rem Return a proper return code on failure

if %errorlevel% neq 0 (
exit /b %errorlevel%
)


@rem Activate the virtualenv
endlocal
if exist "%CFG_ROOT_DIR%bin\activate" (
"%CFG_ROOT_DIR%bin\activate"
)
goto EOS

:EOS
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='license-expression',
version='1.1',
version='1.2',
license='apache-2.0',
description=desc,
long_description=desc,
Expand Down
28 changes: 25 additions & 3 deletions src/license_expression/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ExpressionParseError(ParseError, ExpressionError):
# mapping of lowercase operator strings to an operator object
OPERATORS = {'and': KW_AND, 'or': KW_OR, 'with': KW_WITH}

_simple_tokenizer = re.compile('''
_simple_tokenizer = re.compile(r'''
(?P<symop>[^\s\(\)]+)
|
(?P<space>\s+)
Expand Down Expand Up @@ -827,6 +827,19 @@ def render(self, template='{symbol.key}', *args, **kwargs):
"""
return NotImplementedError

def render_as_readable(self, template='{symbol.key}', *args, **kwargs):
"""
Return a formatted string rendering for this expression using the
`template` format string to render each symbol. Add extra parenthesis
around WITH sub-expressions for improved readbility. See `render()` for
other arguments.
"""
if isinstance(self, LicenseWithExceptionSymbol):
return self.render(
template=template, wrap_with_in_parens=False, *args, **kwargs)
else:
return self.render(template=template, wrap_with_in_parens=True, *args, **kwargs)


class BaseSymbol(Renderable, boolean.Symbol):
"""
Expand Down Expand Up @@ -1075,10 +1088,19 @@ def decompose(self):
yield self.license_symbol
yield self.exception_symbol

def render(self, template='{symbol.key}', *args, **kwargs):
def render(self, template='{symbol.key}', wrap_with_in_parens=False, *args, **kwargs):
"""
Return a formatted WITH expression. If `wrap_with_in_parens`, wrap in
parens a WITH expression, unless it is alone and not used with other AND
or OR sub-expressions.
"""
lic = self.license_symbol.render(template, *args, **kwargs)
exc = self.exception_symbol.render(template, *args, **kwargs)
return '%(lic)s WITH %(exc)s' % locals()
if wrap_with_in_parens:
temp = '(%(lic)s WITH %(exc)s)'
else:
temp = '%(lic)s WITH %(exc)s'
return temp % locals()

def __hash__(self, *args, **kwargs):
return hash((self.license_symbol, self.exception_symbol,))
Expand Down
2 changes: 1 addition & 1 deletion src/license_expression/_pyahocorasick.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def overlap(self, other):


# tokenize to separate text from parens
_tokenizer = re.compile('''
_tokenizer = re.compile(r'''
(?P<text>[^\s\(\)]+)
|
(?P<space>\s+)
Expand Down
24 changes: 24 additions & 0 deletions tests/test_license_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,30 @@ def test_primary_license_symbol_and_primary_license_key(self):
assert expected == licensing.primary_license_symbol(
parsed, decompose=False).render('{symbol.key}')

def test_render_plain(self):
l = Licensing()
result = l.parse('gpl-2.0 WITH exception-gpl-2.0-plus or MIT').render()
expected = 'gpl-2.0 WITH exception-gpl-2.0-plus OR MIT'
assert expected == result

def test_render_as_readable_does_not_wrap_in_parens_single_with(self):
l = Licensing()
result = l.parse('gpl-2.0 WITH exception-gpl-2.0-plus').render_as_readable()
expected = 'gpl-2.0 WITH exception-gpl-2.0-plus'
assert expected == result

def test_render_as_readable_wraps_in_parens_with_and_other_subexpressions(self):
l = Licensing()
result = l.parse('mit AND gpl-2.0 WITH exception-gpl-2.0-plus').render_as_readable()
expected = 'mit AND (gpl-2.0 WITH exception-gpl-2.0-plus)'
assert expected == result

def test_render_as_readable_does_not_wrap_in_parens_if_no_with(self):
l = Licensing()
result1 = l.parse('gpl-2.0 and exception OR that').render_as_readable()
result2 = l.parse('gpl-2.0 and exception OR that').render()
assert result1 == result2


class SplitAndTokenizeTest(TestCase):

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion thirdparty/dev/.keep

This file was deleted.

48 changes: 0 additions & 48 deletions thirdparty/dev/PSF.LICENSE

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.