-
Notifications
You must be signed in to change notification settings - Fork 7
418 pkg confg #497
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
Open
hiker
wants to merge
12
commits into
main
Choose a base branch
from
418_pkg_confg
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+310
−3
Open
418 pkg confg #497
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5b799aa
#418 Added tool for pkg-config and nf-config.
hiker 5ac1576
#418 Added documentation.
hiker 12aa758
#418 Fix names in tests.
hiker c43fbbd
Merge remote-tracking branch 'origin/main' into 418_pkg_confg
hiker 17e6053
Merge remote-tracking branch 'origin/main' into 418_pkg_confg
hiker 8292c03
Merge remote-tracking branch 'origin/main' into 418_pkg_confg
hiker 31f4927
Merge remote-tracking branch 'origin/main' into 418_pkg_confg
hiker 29bec17
Merge remote-tracking branch 'origin/main' into 418_pkg_confg
hiker 0b5cee4
Merge branch 'main' into 418_pkg_confg
MatthewHambley ec32a5b
Merge remote-tracking branch 'origin/main' into 418_pkg_confg
hiker bf71c2a
#418 Added new tools to fab.api
hiker 6ef553f
Merge remote-tracking branch 'origin/main' into 418_pkg_confg
hiker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| ############################################################################## | ||
| # (c) Crown copyright Met Office. All rights reserved. | ||
| # For further details please refer to the file COPYRIGHT | ||
| # which you should have received as part of this distribution | ||
| ############################################################################## | ||
|
|
||
| """This file contains the class to interface with NetCDF's nf-config script. | ||
| """ | ||
|
|
||
| from typing import List | ||
|
|
||
| from fab.tools.category import Category | ||
| from fab.tools.tool import Tool | ||
|
|
||
|
|
||
| class NfConfig(Tool): | ||
| '''This class interfaces with NetCDF's nf-config tool. It is not added | ||
| to the ToolRepository, it is intended for site-specific configurations | ||
| to make it easier to query for NetCDF settings. | ||
| ''' | ||
|
|
||
| def __init__(self): | ||
| super().__init__("nf-config", "nf-config", Category.MISC) | ||
|
|
||
| def get_compiler_flags(self) -> List[str]: | ||
| """ | ||
| :returns: the compilation flags to use for NetCDF. | ||
| """ | ||
| flags = self.run(additional_parameters=["--fflags"]) | ||
| return flags.split() | ||
|
|
||
| def get_linker_flags(self) -> List[str]: | ||
| """ | ||
| :returns: the linker flags to use for NetCDF. | ||
| """ | ||
| flags = self.run(additional_parameters=["--flibs"]) | ||
| return flags.split() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| ############################################################################## | ||
| # (c) Crown copyright Met Office. All rights reserved. | ||
| # For further details please refer to the file COPYRIGHT | ||
| # which you should have received as part of this distribution | ||
| ############################################################################## | ||
|
|
||
| """This file contains the class to interface with pkg-config. | ||
| """ | ||
|
|
||
| from typing import List | ||
|
|
||
| from fab.tools.category import Category | ||
| from fab.tools.tool import Tool | ||
|
|
||
|
|
||
| class PkgConfig(Tool): | ||
| '''This class implements a simple interface to `pkg-config`. PkgConfig is | ||
| not added to the ToolRepository, it is intended for site-specific | ||
| configurations to create an instance for each required package. | ||
|
|
||
| :param name: the name of the package. It is the responsibility of the | ||
| user to ensure that package is really available. | ||
|
|
||
| ''' | ||
|
|
||
| def __init__(self, name: str): | ||
| super().__init__(f"pkg-config({name})", "pkg-config", Category.MISC) | ||
| self._package = name | ||
|
|
||
| def get_compiler_flags(self) -> List[str]: | ||
| """ | ||
| :returns: the compilation flags to use for the specified package. | ||
| """ | ||
| flags = self.run(additional_parameters=[self._package, "--cflags"]) | ||
| return flags.split() | ||
|
|
||
| def get_linker_flags(self) -> List[str]: | ||
| """ | ||
| :returns: the linker flags to use for the specified package. | ||
| """ | ||
| flags = self.run(additional_parameters=[self._package, "--libs"]) | ||
| return flags.split() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| ############################################################################## | ||
| # (c) Crown copyright Met Office. All rights reserved. | ||
| # For further details please refer to the file COPYRIGHT | ||
| # which you should have received as part of this distribution | ||
| ############################################################################## | ||
| """ | ||
| Tests the nf-config wrapper. | ||
| """ | ||
|
|
||
| from pytest_subprocess.fake_process import FakeProcess | ||
|
|
||
| from tests.conftest import call_list | ||
|
|
||
| from fab.tools.category import Category | ||
| from fab.tools.nf_config import NfConfig | ||
|
|
||
|
|
||
| def test_constructor() -> None: | ||
| """ | ||
| Tests default constructor. | ||
| """ | ||
| nfc = NfConfig() | ||
| assert nfc.category == Category.MISC | ||
| assert nfc.name == "nf-config" | ||
| assert nfc.exec_name == "nf-config" | ||
| assert nfc.get_flags() == [] | ||
|
|
||
|
|
||
| def test_nf_config_check_available(fake_process: FakeProcess) -> None: | ||
| """ | ||
| Tests availability functionality. | ||
| """ | ||
| fake_process.register(['nf-config', '--version'], | ||
| returncode=0, | ||
| stdout="netCDF-Fortran 4.6.1") | ||
|
|
||
| nfc = NfConfig() | ||
| assert nfc.check_available() | ||
| assert call_list(fake_process) == [["nf-config", "--version"]] | ||
|
|
||
|
|
||
| def test_nf_config_check_unavailable(fake_process: FakeProcess) -> None: | ||
| """ | ||
| Tests availability failure. | ||
| """ | ||
| fake_process.register(['nf-config', '--version'], | ||
| returncode=127, | ||
| stderr="command 'nf-config' not found") | ||
| nfc = NfConfig() | ||
| assert not nfc.check_available() | ||
| assert call_list(fake_process) == [["nf-config", "--version"]] | ||
|
|
||
|
|
||
| def test_nf_config_compiler_flags(fake_process: FakeProcess) -> None: | ||
| """ | ||
| Tests getting the compiler flags. | ||
| """ | ||
| fake_process.register(['nf-config', '--fflags'], | ||
| returncode=0, | ||
| stdout="-I /somewhere") | ||
| nfc = NfConfig() | ||
| assert nfc.get_compiler_flags() == ["-I", "/somewhere"] | ||
| assert call_list(fake_process) == [["nf-config", "--fflags"]] | ||
|
|
||
|
|
||
| def test_nf_config_linker_flags(fake_process: FakeProcess) -> None: | ||
| """ | ||
| Tests availability failure. | ||
| """ | ||
| fake_process.register(['nf-config', '--flibs'], | ||
| returncode=0, | ||
| stdout="-L /somewhere -lsomewhat") | ||
| nfc = NfConfig() | ||
| assert nfc.get_linker_flags() == ["-L", "/somewhere", "-lsomewhat"] | ||
| assert call_list(fake_process) == [["nf-config", "--flibs"]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| ############################################################################## | ||
| # (c) Crown copyright Met Office. All rights reserved. | ||
| # For further details please refer to the file COPYRIGHT | ||
| # which you should have received as part of this distribution | ||
| ############################################################################## | ||
| """ | ||
| Tests the pkg-config wrapper. | ||
| """ | ||
|
|
||
| from pytest_subprocess.fake_process import FakeProcess | ||
|
|
||
| from tests.conftest import call_list | ||
|
|
||
| from fab.tools.category import Category | ||
| from fab.tools.pkg_config import PkgConfig | ||
|
|
||
|
|
||
| def test_constructor() -> None: | ||
| """ | ||
| Tests default constructor. | ||
| """ | ||
| pcf = PkgConfig('dummy') | ||
| assert pcf.category == Category.MISC | ||
| assert pcf.name == 'pkg-config(dummy)' | ||
| assert pcf.exec_name == 'pkg-config' | ||
| assert pcf.get_flags() == [] | ||
|
|
||
|
|
||
| def test_pkg_config_check_available(fake_process: FakeProcess) -> None: | ||
| """ | ||
| Tests availability functionality. | ||
| """ | ||
| fake_process.register(['pkg-config', '--version'], | ||
| returncode=0, | ||
| stdout='netCDF-Fortran 4.6.1') | ||
|
|
||
| pcf = PkgConfig('dummy') | ||
| assert pcf.check_available() | ||
| assert call_list(fake_process) == [['pkg-config', '--version']] | ||
|
|
||
|
|
||
| def test_pkg_config_check_unavailable(fake_process: FakeProcess) -> None: | ||
| """ | ||
| Tests availability failure. | ||
| """ | ||
| fake_process.register(['pkg-config', '--version'], | ||
| returncode=127, | ||
| stderr="command 'pkg-config' not found") | ||
| pcf = PkgConfig("dummy") | ||
| assert not pcf.check_available() | ||
| assert call_list(fake_process) == [['pkg-config', '--version']] | ||
|
|
||
|
|
||
| def test_pkg_config_compiler_flags(fake_process: FakeProcess) -> None: | ||
| """ | ||
| Tests getting the compiler flags. | ||
| """ | ||
| fake_process.register(['pkg-config', 'dummy', '--cflags'], | ||
| returncode=0, | ||
| stdout='-I /somewhere') | ||
| pcf = PkgConfig('dummy') | ||
| assert pcf.get_compiler_flags() == ['-I', '/somewhere'] | ||
| assert call_list(fake_process) == [['pkg-config', 'dummy', '--cflags']] | ||
|
|
||
|
|
||
| def test_pkg_config_linker_flags(fake_process: FakeProcess) -> None: | ||
| """ | ||
| Tests availability failure. | ||
| """ | ||
| fake_process.register(['pkg-config', 'dummy', '--libs'], | ||
| returncode=0, | ||
| stdout='-L /somewhere -lsomewhat') | ||
| pcf = PkgConfig('dummy') | ||
| assert pcf.get_linker_flags() == ['-L', '/somewhere', '-lsomewhat'] | ||
| assert call_list(fake_process) == [['pkg-config', 'dummy', '--libs']] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test is needed that pkg_config is honouring the
PKG_CONFIG_LIBDIRandPKG_CONFIG_PATHenvironment variables. Particularly that last one as it is how new package collections are added to the system.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should assume that
pkg-configis installed on the system (while we control gitlab ci, and many other systems, so we can ensure it is available, in general I don't think we shouldThat's also the reason why I tried to clean up tests that relied ongccor so being available).Then, how should I test that the environment variable are passed on? Creating a shell script that
echo'sthe environment? Seems a bit odd - if this is to be tested, it should be done with the base class to verify it does not add/remove anything from the environment instead? Should I do that?