Skip to content

Commit 39345dd

Browse files
Add to downstream ci (#13)
* Add to downstream ci
1 parent 0d4083f commit 39345dd

12 files changed

+210
-96
lines changed

.github/ci-hpc-config.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build:
2+
python: 3.10
3+
parallel: 1

.github/workflows/cd-pypi.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: cd
2+
3+
on:
4+
push:
5+
tags:
6+
- '**'
7+
8+
jobs:
9+
pypi:
10+
uses: ecmwf-actions/reusable-workflows/.github/workflows/cd-pypi.yml@v2
11+
secrets: inherit

.github/workflows/ci.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: ci
2+
3+
on:
4+
# Trigger the workflow on push to master or develop, except tag creation
5+
push:
6+
branches:
7+
- 'master'
8+
- 'develop'
9+
tags-ignore:
10+
- '**'
11+
12+
# Trigger the workflow on pull request
13+
pull_request:
14+
15+
# Trigger the workflow manually
16+
workflow_dispatch:
17+
18+
# Trigger after public PR approved for CI
19+
pull_request_target:
20+
types: [labeled]
21+
22+
jobs:
23+
# Run CI including downstream packages on self-hosted runners
24+
downstream-ci:
25+
name: downstream-ci
26+
if: ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }}
27+
uses: ecmwf-actions/downstream-ci/.github/workflows/downstream-ci.yml@main
28+
with:
29+
findlibs: ecmwf/findlibs@${{ github.event.pull_request.head.sha || github.sha }}
30+
codecov_upload: true
31+
python_qa: true
32+
secrets: inherit
33+
34+
35+
# Build downstream packages on HPC
36+
downstream-ci-hpc:
37+
name: downstream-ci-hpc
38+
if: ${{ !github.event.pull_request.head.repo.fork && github.event.action != 'labeled' || github.event.label.name == 'approved-for-ci' }}
39+
uses: ecmwf-actions/downstream-ci/.github/workflows/downstream-ci-hpc.yml@main
40+
with:
41+
findlibs: ecmwf/findlibs@${{ github.event.pull_request.head.sha || github.sha }}
42+
secrets: inherit

.github/workflows/label-public-pr.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Manage labels of pull requests that originate from forks
2+
name: label-public-pr
3+
4+
on:
5+
pull_request_target:
6+
types: [opened, synchronize]
7+
8+
jobs:
9+
label:
10+
uses: ecmwf-actions/reusable-workflows/.github/workflows/label-pr.yml@v2

.github/workflows/python-publish.yml

-31
This file was deleted.

.gitignore

+20
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,23 @@ __pycache__/
33
*.pyc
44
?.*
55
*.egg-info/
6+
7+
### VisualStudioCode ###
8+
.vscode/
9+
10+
# Local History for Visual Studio Code
11+
.history/
12+
13+
# Built Visual Studio Code Extensions
14+
*.vsix
15+
16+
### VisualStudioCode Patch ###
17+
# Ignore all local history of files
18+
.history
19+
.ionide
20+
21+
# Support for Project snippet scope
22+
.vscode/*.code-snippets
23+
24+
# Ignore code-workspaces
25+
*.code-workspace

findlibs/__init__.py

+50-29
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
# nor does it submit to any jurisdiction.
99
#
1010

11+
import configparser
1112
import ctypes.util
1213
import os
1314
import sys
14-
import configparser
1515
from pathlib import Path
1616

1717
__version__ = "0.0.5"
@@ -21,38 +21,53 @@
2121
"win32": ".dll",
2222
}
2323

24+
2425
def _get_paths_from_config():
25-
locations = [Path(p).expanduser() for p in [
26-
"~/.config/findlibs/findlibs.conf",
27-
"~/.findlibs",
28-
]]
26+
locations = [
27+
Path(p).expanduser()
28+
for p in [
29+
"~/.config/findlibs/findlibs.conf",
30+
"~/.findlibs",
31+
]
32+
]
2933

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

32-
if len(locations) == 0: return []
33-
if len(locations) > 1:
34-
raise ValueError(f"There are multiple config files! Delete all but one of {locations}")
36+
if len(locations) == 0:
37+
return []
38+
if len(locations) > 1:
39+
raise ValueError(
40+
f"There are multiple config files! Delete all but one of {locations}"
41+
)
3542

36-
config = configparser.RawConfigParser(allow_no_value = True) # Allow keys without values
37-
config.optionxform = lambda option: option # Preserve case of keys
38-
39-
with open(locations[0], "r") as f:
43+
config = configparser.RawConfigParser(
44+
allow_no_value=True
45+
) # Allow keys without values
46+
config.optionxform = lambda option: option # Preserve case of keys
47+
48+
with open(locations[0], "r"):
4049
config.read(locations[0])
41-
42-
if "Paths" not in config: return []
43-
# replace $HOME with ~, expand ~ to full path,
44-
# resolve any relative paths to absolute paths
45-
paths = {Path(p.replace("$HOME", "~")).expanduser()
46-
for p in config["Paths"] or []}
47-
50+
51+
if "Paths" not in config:
52+
return []
53+
# replace $HOME with ~, expand ~ to full path,
54+
# resolve any relative paths to absolute paths
55+
paths = {Path(p.replace("$HOME", "~")).expanduser() for p in config["Paths"] or []}
56+
4857
relative_paths = [p for p in paths if not p.is_absolute()]
4958
if relative_paths:
50-
raise ValueError(f"Don't use relative paths in the config file ({locations[0]}), offending paths are: {relative_paths}")
51-
59+
raise ValueError(
60+
(
61+
f"Don't use relative paths in the config file ({locations[0]}),"
62+
f" offending paths are: {relative_paths}"
63+
)
64+
)
65+
5266
files = [p for p in paths if not p.is_dir()]
5367
if files:
54-
raise ValueError(f"Don't put files in the config file ({locations[0]}), offending files are: {files}")
55-
68+
raise ValueError(
69+
f"Don't put files in the config file ({locations[0]}), offending files are: {files}"
70+
)
5671

5772
return paths
5873

@@ -101,18 +116,17 @@ def find(lib_name, pkg_name=None):
101116
if env in os.environ:
102117
home = os.path.expanduser(os.environ[env])
103118
for lib in ("lib", "lib64"):
104-
fullname = os.path.join(
105-
home, lib, libname
106-
)
119+
fullname = os.path.join(home, lib, libname)
107120
if os.path.exists(fullname):
108121
return fullname
109122

110123
config_paths = _get_paths_from_config()
111124

112125
for root in config_paths:
113-
for lib in ("lib", "lib64"):
126+
for lib in ("lib", "lib64"):
114127
filepath = root / lib / f"lib{lib_name}{extension}"
115-
if filepath.exists(): return str(filepath)
128+
if filepath.exists():
129+
return str(filepath)
116130

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

126-
for root in ("/", "/usr/", "/usr/local/", "/opt/", "/opt/homebrew/", os.path.expanduser("~/.local")):
140+
for root in (
141+
"/",
142+
"/usr/",
143+
"/usr/local/",
144+
"/opt/",
145+
"/opt/homebrew/",
146+
os.path.expanduser("~/.local"),
147+
):
127148
for lib in ("lib", "lib64"):
128149
fullname = os.path.join(root, lib, libname)
129150
if os.path.exists(fullname):

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 110
3+
extend-ignore = E203, W503

setup.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ def read(fname):
4242
packages=setuptools.find_packages(),
4343
include_package_data=True,
4444
install_requires=[],
45-
extras_require={
46-
'test': ["pytest", "pyfakefs"]
47-
},
45+
extras_require={"test": ["pytest", "pyfakefs"]},
4846
zip_safe=True,
4947
keywords="tool",
5048
classifiers=[

tests/downstream-ci-requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pytest
2+
pytest-cov
3+
pyfakefs

tests/test_basic.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@
77
# granted to it by virtue of its status as an intergovernmental organisation
88
# nor does it submit to any jurisdiction.
99

10-
import pytest
11-
import pyfakefs # registers a fixture called "fs" with pytest
12-
import sys
1310
import os
14-
import findlibs
11+
import sys
1512
from pathlib import Path
1613

14+
import pyfakefs # noqa registers a fixture called "fs" with pytest
15+
import pytest
16+
17+
import findlibs
18+
1719
pkg_name = "foobar"
1820
extension = findlibs.EXTENSIONS.get(sys.platform, ".so")
1921
libname = f"lib{pkg_name}{extension}"
2022

21-
conda_prefix = '/test/conda/prefix'
23+
conda_prefix = "/test/conda/prefix"
2224
os.environ["CONDA_PREFIX"] = conda_prefix
2325
env_variable_location = os.environ[f"{pkg_name}_HOME"] = "/test/environment/variable"
2426
ld_library_location = os.environ["LD_LIBRARY_PATH"] = "/test/ld_library/"
@@ -30,13 +32,18 @@
3032
sys.prefix,
3133
conda_prefix,
3234
env_variable_location,
33-
"/", "/usr/", "/usr/local/", "/opt/", "/opt/homebrew/", os.path.expanduser("~/.local")
35+
"/",
36+
"/usr/",
37+
"/usr/local/",
38+
"/opt/",
39+
"/opt/homebrew/",
40+
os.path.expanduser("~/.local"),
3441
]
3542

43+
3644
@pytest.mark.parametrize("location", test_locations)
3745
def test_find(fs, location):
3846
libpath = Path(location) / "lib" / libname
3947
print(f"creating {libpath}")
4048
fs.create_file(libpath)
4149
assert findlibs.find(pkg_name) == str(libpath)
42-

0 commit comments

Comments
 (0)