Skip to content

Commit

Permalink
Add to downstream ci (#13)
Browse files Browse the repository at this point in the history
* Add to downstream ci
  • Loading branch information
sandorkertesz authored May 8, 2024
1 parent 0d4083f commit 39345dd
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 96 deletions.
3 changes: 3 additions & 0 deletions .github/ci-hpc-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build:
python: 3.10
parallel: 1
11 changes: 11 additions & 0 deletions .github/workflows/cd-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: cd

on:
push:
tags:
- '**'

jobs:
pypi:
uses: ecmwf-actions/reusable-workflows/.github/workflows/cd-pypi.yml@v2
secrets: inherit
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: ci

on:
# Trigger the workflow on push to master or develop, except tag creation
push:
branches:
- 'master'
- 'develop'
tags-ignore:
- '**'

# Trigger the workflow on pull request
pull_request:

# Trigger the workflow manually
workflow_dispatch:

# Trigger after public PR approved for CI
pull_request_target:
types: [labeled]

jobs:
# Run CI including downstream packages on self-hosted runners
downstream-ci:
name: downstream-ci
if: ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }}
uses: ecmwf-actions/downstream-ci/.github/workflows/downstream-ci.yml@main
with:
findlibs: ecmwf/findlibs@${{ github.event.pull_request.head.sha || github.sha }}
codecov_upload: true
python_qa: true
secrets: inherit


# Build downstream packages on HPC
downstream-ci-hpc:
name: downstream-ci-hpc
if: ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }}
uses: ecmwf-actions/downstream-ci/.github/workflows/downstream-ci-hpc.yml@main
with:
findlibs: ecmwf/findlibs@${{ github.event.pull_request.head.sha || github.sha }}
secrets: inherit
10 changes: 10 additions & 0 deletions .github/workflows/label-public-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Manage labels of pull requests that originate from forks
name: label-public-pr

on:
pull_request_target:
types: [opened, synchronize]

jobs:
label:
uses: ecmwf-actions/reusable-workflows/.github/workflows/label-pr.yml@v2
31 changes: 0 additions & 31 deletions .github/workflows/python-publish.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@ __pycache__/
*.pyc
?.*
*.egg-info/

### VisualStudioCode ###
.vscode/

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

# Support for Project snippet scope
.vscode/*.code-snippets

# Ignore code-workspaces
*.code-workspace
79 changes: 50 additions & 29 deletions findlibs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# nor does it submit to any jurisdiction.
#

import configparser
import ctypes.util
import os
import sys
import configparser
from pathlib import Path

__version__ = "0.0.5"
Expand All @@ -21,38 +21,53 @@
"win32": ".dll",
}


def _get_paths_from_config():
locations = [Path(p).expanduser() for p in [
"~/.config/findlibs/findlibs.conf",
"~/.findlibs",
]]
locations = [
Path(p).expanduser()
for p in [
"~/.config/findlibs/findlibs.conf",
"~/.findlibs",
]
]

locations = [p for p in locations if p.exists()]

if len(locations) == 0: return []
if len(locations) > 1:
raise ValueError(f"There are multiple config files! Delete all but one of {locations}")
if len(locations) == 0:
return []
if len(locations) > 1:
raise ValueError(
f"There are multiple config files! Delete all but one of {locations}"
)

config = configparser.RawConfigParser(allow_no_value = True) # Allow keys without values
config.optionxform = lambda option: option # Preserve case of keys

with open(locations[0], "r") as f:
config = configparser.RawConfigParser(
allow_no_value=True
) # Allow keys without values
config.optionxform = lambda option: option # Preserve case of keys

with open(locations[0], "r"):
config.read(locations[0])
if "Paths" not in config: return []
# replace $HOME with ~, expand ~ to full path,
# resolve any relative paths to absolute paths
paths = {Path(p.replace("$HOME", "~")).expanduser()
for p in config["Paths"] or []}

if "Paths" not in config:
return []
# replace $HOME with ~, expand ~ to full path,
# resolve any relative paths to absolute paths
paths = {Path(p.replace("$HOME", "~")).expanduser() for p in config["Paths"] or []}

relative_paths = [p for p in paths if not p.is_absolute()]
if relative_paths:
raise ValueError(f"Don't use relative paths in the config file ({locations[0]}), offending paths are: {relative_paths}")

raise ValueError(
(
f"Don't use relative paths in the config file ({locations[0]}),"
f" offending paths are: {relative_paths}"
)
)

files = [p for p in paths if not p.is_dir()]
if files:
raise ValueError(f"Don't put files in the config file ({locations[0]}), offending files are: {files}")

raise ValueError(
f"Don't put files in the config file ({locations[0]}), offending files are: {files}"
)

return paths

Expand Down Expand Up @@ -101,18 +116,17 @@ def find(lib_name, pkg_name=None):
if env in os.environ:
home = os.path.expanduser(os.environ[env])
for lib in ("lib", "lib64"):
fullname = os.path.join(
home, lib, libname
)
fullname = os.path.join(home, lib, libname)
if os.path.exists(fullname):
return fullname

config_paths = _get_paths_from_config()

for root in config_paths:
for lib in ("lib", "lib64"):
for lib in ("lib", "lib64"):
filepath = root / lib / f"lib{lib_name}{extension}"
if filepath.exists(): return str(filepath)
if filepath.exists():
return str(filepath)

for path in (
"LD_LIBRARY_PATH",
Expand All @@ -123,7 +137,14 @@ def find(lib_name, pkg_name=None):
if os.path.exists(fullname):
return fullname

for root in ("/", "/usr/", "/usr/local/", "/opt/", "/opt/homebrew/", os.path.expanduser("~/.local")):
for root in (
"/",
"/usr/",
"/usr/local/",
"/opt/",
"/opt/homebrew/",
os.path.expanduser("~/.local"),
):
for lib in ("lib", "lib64"):
fullname = os.path.join(root, lib, libname)
if os.path.exists(fullname):
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 110
extend-ignore = E203, W503
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ def read(fname):
packages=setuptools.find_packages(),
include_package_data=True,
install_requires=[],
extras_require={
'test': ["pytest", "pyfakefs"]
},
extras_require={"test": ["pytest", "pyfakefs"]},
zip_safe=True,
keywords="tool",
classifiers=[
Expand Down
3 changes: 3 additions & 0 deletions tests/downstream-ci-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
pytest-cov
pyfakefs
21 changes: 14 additions & 7 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

import pytest
import pyfakefs # registers a fixture called "fs" with pytest
import sys
import os
import findlibs
import sys
from pathlib import Path

import pyfakefs # noqa registers a fixture called "fs" with pytest
import pytest

import findlibs

pkg_name = "foobar"
extension = findlibs.EXTENSIONS.get(sys.platform, ".so")
libname = f"lib{pkg_name}{extension}"

conda_prefix = '/test/conda/prefix'
conda_prefix = "/test/conda/prefix"
os.environ["CONDA_PREFIX"] = conda_prefix
env_variable_location = os.environ[f"{pkg_name}_HOME"] = "/test/environment/variable"
ld_library_location = os.environ["LD_LIBRARY_PATH"] = "/test/ld_library/"
Expand All @@ -30,13 +32,18 @@
sys.prefix,
conda_prefix,
env_variable_location,
"/", "/usr/", "/usr/local/", "/opt/", "/opt/homebrew/", os.path.expanduser("~/.local")
"/",
"/usr/",
"/usr/local/",
"/opt/",
"/opt/homebrew/",
os.path.expanduser("~/.local"),
]


@pytest.mark.parametrize("location", test_locations)
def test_find(fs, location):
libpath = Path(location) / "lib" / libname
print(f"creating {libpath}")
fs.create_file(libpath)
assert findlibs.find(pkg_name) == str(libpath)

Loading

0 comments on commit 39345dd

Please sign in to comment.