From: Karl O. Pinc Date: Wed, 14 Nov 2018 03:37:10 +0000 (-0600) Subject: Use pgwui_common.path for asset resolution X-Git-Url: https://papio.biology.duke.edu/gitweb/?a=commitdiff_plain;h=edc1d334f2226bc5e2b4b8844ccb2e5be37dd2c2;p=pgwui_common Use pgwui_common.path for asset resolution --- diff --git a/src/pgwui_common/path.py b/src/pgwui_common/path.py new file mode 100644 index 0000000..d8f427e --- /dev/null +++ b/src/pgwui_common/path.py @@ -0,0 +1,31 @@ +# Copyright (C) 2018 The Meme Factory, Inc. http://www.meme.com/ + +# This file is part of PGWUI_Common. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License +# as published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with this program. If not, see +# . +# + +# Karl O. Pinc + +'''Path library for PGWUI +''' +from pyramid.path import AssetResolver + + +def asset_abspath(asset): + '''Return the absolute path of a pyramid asset + ''' + asset_resolver = AssetResolver(None) + return asset_resolver.resolve(asset).abspath() diff --git a/src/pgwui_common/templates/auth_base.mak b/src/pgwui_common/templates/auth_base.mak index 095e987..9edac7e 100644 --- a/src/pgwui_common/templates/auth_base.mak +++ b/src/pgwui_common/templates/auth_base.mak @@ -37,11 +37,9 @@ <%! - from pyramid.path import AssetResolver + from pgwui_common.path import asset_abspath - asset_resolver = AssetResolver(None) - base_mak = (asset_resolver.resolve('pgwui_common:templates/base.mak') - .abspath()) + base_mak = asset_abspath('pgwui_common:templates/base.mak') %> <%inherit file="${base_mak}" /> diff --git a/tests/test_path.py b/tests/test_path.py new file mode 100644 index 0000000..6a73059 --- /dev/null +++ b/tests/test_path.py @@ -0,0 +1,37 @@ +# Copyright (C) 2018 The Meme Factory, Inc. http://www.meme.com/ + +# This file is part of PGWUI_Common. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU Affero General Public License +# as published by the Free Software Foundation, either version 3 of +# the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with this program. If not, see +# . +# + +# Karl O. Pinc + +from pyramid.path import AssetResolver + +import pgwui_common.path + + +# Integration tests + +# asset_abspath() + +def test_asset_abspath(): + '''Returns what pyramid's asset resolver returns''' + asset_resolver = AssetResolver(None) + asset = 'pgwui_common:templates/base.mk' + answer = asset_resolver.resolve(asset).abspath() + result = pgwui_common.path.asset_abspath(asset) + assert result == answer