Skip to content

Commit

Permalink
Replace travis with GH actions and refactor tests
Browse files Browse the repository at this point in the history
Also remove ERT as dependency
  • Loading branch information
jcrivenaes committed Dec 3, 2021
1 parent a195124 commit edc07c9
Show file tree
Hide file tree
Showing 24 changed files with 226 additions and 90 deletions.
22 changes: 22 additions & 0 deletions .github/actions/build-xtgeoapp-grd3dmaps/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build
description: builds xtgeoapp-grd3dmaps

inputs:
python-version:
required: true

runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ inputs.python-version }}

- name: Upgrade pip
run: python -m pip install pip -U
shell: bash

- name: install xtgeoapp-grd3maps
run: pip install .
shell: bash
15 changes: 15 additions & 0 deletions .github/actions/test_setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Set up for tests"
description: "Set up the xtgeoapp-grd3dmaps test environment"

inputs:
python-version:
required: true

runs:
using: "composite"
steps:
- uses: "./.github/actions/build-xtgeoapp-grd3dmaps"
with:
python-version: ${{ inputs.python-version }}
- run: pip install -r requirements/requirements_tests.txt
shell: bash
31 changes: 31 additions & 0 deletions .github/workflows/test_scripts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
testing:
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
os: [ubuntu-latest]
include:
- os: macos-latest
python-version: 3.8
- os: windows-latest
python-version: 3.8
- os: ubuntu-latest
python-version: 3.7
- os: ubuntu-latest
python-version: 3.9
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: "./.github/actions/test_setup"
with:
python-version: ${{ matrix.python-version }}
- name: Run test
run: python -m pytest tests/test_scripts --disable-warnings -x
26 changes: 26 additions & 0 deletions .github/workflows/test_vs_ert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test vs ERT

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
test_vs_ert:
strategy:
matrix:
python-version: [3.6, 3.8]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v1
- uses: "./.github/actions/test_setup"
with:
python-version: ${{ matrix.python-version }}
- name: Run test vs ERT
# the promise install is needed due to bug in ERT installer; remove when fixed
run: >
python -m pip install ert &&
python -m pip install promise &&
python -m pytest tests/test_vs_ert --disable-warnings -x
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

35 changes: 35 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# NOTE: you have to use single-quoted strings in TOML for regular expressions.

[tool.black]
line-length = 88
target-version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
# The following are specific to Black, you probably don't want those.
| blib2to3
| tests/data
| tests/yaml
| profiling
)/
'''

[build-system]
requires = [
"pip>=19.1.1",
"setuptools>=43",
"wheel",
"setuptools_scm",
"Sphinx",
"sphinx-rtd-theme",
]
13 changes: 13 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pytest tests/tests* -o log_cli=true -s

[pytest]
minversion = 6.0
addopts = --verbose
log_cli = False
log_cli_format = %(levelname)8s (%(relativeCreated)6.0fms) %(filename)44s [%(funcName)40s()] %(lineno)4d >> %(message)s
log_cli_level = INFO
testpaths =
tests
markers =
integration: Integration tests
requires_ert: A test requiring ert in the environment
3 changes: 1 addition & 2 deletions requirements.txt → requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PyYAML
ert
numpy
pyyaml
xtgeo
xtgeoviz
3 changes: 2 additions & 1 deletion requirements_dev.txt → requirements/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Sphinx>=1.4.8

black
coverage>=4.1
flake8
Expand All @@ -7,5 +7,6 @@ pylint
pytest-runner>=2.11.1
pytest>=2.9.2
rstcheck
sphinx>=1.4.8
watchdog>=0.8.3
wheel>=0.29.0
5 changes: 5 additions & 0 deletions requirements/requirements_docs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pip>=19.1.1
setuptools>=43
setuptools_scm
sphinx
sphinx-rtd-theme
4 changes: 4 additions & 0 deletions requirements/requirements_setup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest-runner
setuptools>=43
setuptools_scm
wheel
1 change: 1 addition & 0 deletions requirements/requirements_tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest
30 changes: 23 additions & 7 deletions scripts/setup_functions.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""Setup helpers for setup.py in xtgeoviz package."""
"""Setup helpers for setup.py."""
import fnmatch
import os
from distutils.command.clean import clean as _clean
from os.path import exists
from pathlib import Path
from shutil import rmtree
import fnmatch

from distutils.command.clean import clean as _clean
from setuptools_scm import get_version


def parse_requirements(filename):
"""Load requirements from a pip requirements file."""
try:
lineiter = (line.strip() for line in open(filename))
lineiter = Path(filename).read_text(encoding="utf8").splitlines()
return [line for line in lineiter if line and not line.startswith("#")]
except OSError:
return []
Expand Down Expand Up @@ -75,16 +77,30 @@ def run(self):

for dir_ in CleanUp.CLEANFOLDERS:
if exists(dir_):
print("Removing: {}".format(dir_))
print(f"Removing: {dir_}")
if not self.dry_run and exists(dir_):
rmtree(dir_)

for dir_ in CleanUp.CLEANFOLDERSRECURSIVE:
for pdir in self.dfind(dir_, "."):
print("Remove folder {}".format(pdir))
print(f"Remove folder {pdir}")
rmtree(pdir)

for fil_ in CleanUp.CLEANFILESRECURSIVE:
for pfil in self.ffind(fil_, "."):
print("Remove file {}".format(pfil))
print(f"Remove file {pfil}")
os.unlink(pfil)


# ======================================================================================
# Sphinx
# ======================================================================================

CMDSPHINX = {
"build_sphinx": {
"project": ("setup.py", "xtgeoapp-grd3dapp"),
"version": ("setup.py", get_version()),
"release": ("setup.py", ""),
"source_dir": ("setup.py", "docs"),
}
}
71 changes: 24 additions & 47 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,39 @@
#!/usr/bin/env python

"""The setup script."""
import fileinput
import os
import sys
import sysconfig
from glob import glob
from os.path import basename
from os.path import splitext
from os.path import basename, splitext
from pathlib import Path

from setuptools import setup, find_packages
from scripts import setup_functions
from setuptools import find_packages, setup

CMDCLASS = {"clean": setup_functions.CleanUp}

APPS = ("grid3d_hc_thickness", "grid3d_average_map")


def parse_requirements(filename):
"""Load requirements from a pip requirements file"""
try:
lineiter = (line.strip() for line in open(filename))
return [line for line in lineiter if line and not line.startswith("#")]
except IOError:
return []
from scripts import setup_functions as setupx

CMDCLASS = {"clean": setupx.CleanUp}

def src(x):
root = os.path.dirname(__file__)
return os.path.abspath(os.path.join(root, x))


def _post_install():
"""Replace the shebang line of console script fra spesific to a general"""
print("POST INSTALL")
spath = sysconfig.get_paths()["scripts"]
xapps = []
for app in APPS:
xapps.append(os.path.join(spath, app))
print(xapps)
for line in fileinput.input(xapps, inplace=1):
line = line.replace(spath + "/python", "/usr/bin/env python")
sys.stdout.write(line)

APPS = ("grid3d_hc_thickness", "grid3d_average_map")

with open("README.rst") as readme_file:
with open("README.rst", encoding="utf8") as readme_file:
readme = readme_file.read()

with open("HISTORY.rst") as history_file:
with open("HISTORY.rst", encoding="utf8") as history_file:
history = history_file.read()


requirements = parse_requirements("requirements.txt")
REQUIREMENTS = setupx.parse_requirements("requirements/requirements.txt")
REQUIREMENTS_SETUP = setupx.parse_requirements("requirements/requirements_setup.txt")
REQUIREMENTS_TESTS = setupx.parse_requirements("requirements/requirements_tests.txt")
REQUIREMENTS_DOCS = setupx.parse_requirements("requirements/requirements_docs.txt")
REQUIREMENTS_EXTRAS = {"tests": REQUIREMENTS_TESTS, "docs": REQUIREMENTS_DOCS}

setup_requirements = ["pytest-runner", "wheel", "setuptools_scm>=3.2.0"]
HC_FUNCTION = "grid3d_hc_thickness=xtgeoapp_grd3dmaps.avghc.grid3d_hc_thickness:main"
AVG_FUNCTION = "grid3d_average_map=xtgeoapp_grd3dmaps.avghc.grid3d_average_map:main"

test_requirements = ["pytest"]

hc_function = "grid3d_hc_thickness=" "xtgeoapp_grd3dmaps.avghc.grid3d_hc_thickness:main"
avg_function = "grid3d_average_map=" "xtgeoapp_grd3dmaps.avghc.grid3d_average_map:main"
def src(anypath):
"""Find src folders."""
return Path(__file__).parent / anypath


setup(
Expand All @@ -76,14 +51,14 @@ def _post_install():
package_dir={"": "src"},
py_modules=[splitext(basename(path))[0] for path in glob("src/*.py")],
entry_points={
"console_scripts": [hc_function, avg_function],
"console_scripts": [HC_FUNCTION, AVG_FUNCTION],
"ert": [
"xtgeoapp_grd3dmaps_jobs = xtgeoapp_grd3dmaps.hook_implementations.jobs"
],
},
cmdclass=CMDCLASS,
command_options=setupx.CMDSPHINX,
include_package_data=True,
install_requires=requirements,
zip_safe=False,
keywords="xtgeo",
classifiers=[
Expand All @@ -98,6 +73,8 @@ def _post_install():
"Programming Language :: Python :: 3.9",
],
test_suite="tests",
tests_require=test_requirements,
setup_requires=setup_requirements,
install_requires=REQUIREMENTS,
tests_require=REQUIREMENTS_TESTS,
setup_requires=REQUIREMENTS_SETUP,
extras_requires=REQUIREMENTS_EXTRAS,
)
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@
import pytest


def pytest_runtest_setup(item):
"""Called for each test."""

markers = [value.name for value in item.iter_markers()]

# pytest.mark.requires_ert:
if "requires_ert" in markers:
if not shutil.which("ert"):
pytest.skip("Skip test if not ERT present (executable 'ert' is missing)")


@pytest.fixture(name="datatree", scope="session", autouse=True)
def fixture_datatree(tmp_path_factory):
"""Create a tmp folder structure for testing."""
Expand Down
Loading

0 comments on commit edc07c9

Please sign in to comment.