Skip to content

Commit

Permalink
minor fixes (#350)
Browse files Browse the repository at this point in the history
* [setup.cfg] enable doctest for pytest runs
* do not recurse into doc dir (prevent importing conf.py)
* [gha/build/pypi] test via pyargs (python-path, not file path)
  this should circumvent the import conflict of conftest.py
* cleanup scripts directory. Added entry point for welding_schema
* add entry_points.console_scripts to conda-recipe
  • Loading branch information
marscher authored May 3, 2021
1 parent ce11f9d commit 19b2e97
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ jobs:
- name: run pytest
run: |
pip install pytest pytest-cov pytest-xdist
pytest -n2 --dist=loadfile
cd /tmp
pytest -n2 --dist=loadfile --pyargs weldx
cd -
- name: set pypi test repo defaults
run: |
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ prune .binder
prune .github
prune devtools
prune doc
prune scripts
prune tutorials

global-exclude .*
5 changes: 4 additions & 1 deletion devtools/conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ build:
number: 0
noarch: python
script: pip install . -v

entry_points:
{% for e in data['entry_points']['console_scripts'] %}
- {{ e }}
{% endfor %}
requirements:
build:
- pip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from weldx.util import _clean_notebook

p = Path(__file__).parents[1]
notebooks = p.glob("tutorials/*.ipynb")
notebooks = p.glob("../../tutorials/*.ipynb")
for nb in notebooks:
_clean_notebook(nb)
Empty file removed scripts/__init__.py
Empty file.
6 changes: 5 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ install_requires =
ipywidgets
k3d
meshio

include_package_data = True

[options.extras_require]
Expand All @@ -66,6 +67,8 @@ asdf_extensions =
weldx = weldx.asdf.extension:WeldxExtension
weldx-asdf = weldx.asdf.extension:WeldxAsdfExtension

console_scripts =
welding_schema = weldx.asdf.cli.welding_schema:main

[flake8]
# References:
Expand All @@ -91,7 +94,7 @@ match_dir = [^\.][^\docs].*
ignore = D203,D213

[tool:pytest]
addopts = --tb=short --color=yes -rs --cov=weldx --cov-report=term-missing:skip-covered
addopts = --tb=short --color=yes -rs --cov=weldx --cov-report=term-missing:skip-covered --doctest-modules
#addopts = --tb=short --color=yes -rs -p no:cov
# custom test markers, see https://docs.pytest.org/en/latest/example/markers.html#mark-examples
markers =
Expand All @@ -100,6 +103,7 @@ asdf_schema_root = weldx/asdf/schemas
#asdf_schema_tests_enabled = true
asdf_schema_skip_tests =
weldx.bam.de/weldx/datamodels/single_pass_weld-1.0.0.schema.yaml
norecursedirs = doc

[isort]
profile = black
Expand Down
1 change: 1 addition & 0 deletions weldx/asdf/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Contains command line interface scripts dealing with ASDF."""
58 changes: 55 additions & 3 deletions scripts/welding_schema.py → weldx/asdf/cli/welding_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
# Welding schema
"""single_pass_weld schema."""
import sys
from io import BytesIO
from typing import Optional, Tuple


def single_pass_weld_example(out_file="single_pass_weld_example.asdf"):
def single_pass_weld_example(
out_file: str = "single_pass_weld_example.asdf",
) -> Optional[Tuple[BytesIO, dict]]:
"""Create ASDF file containing all required fields of the single_pass_weld schema.
Parameters
----------
out_file :
destination file, if None returns a BytesIO buffer.
Returns
-------
buff, tree
When writing to memory, return the buffer and the tree (as dictionary).
"""
# Imports
import asdf
import numpy as np
Expand Down Expand Up @@ -299,5 +317,39 @@ def single_pass_weld_example(out_file="single_pass_weld_example.asdf"):
)


def parse_args(argv):
"""Parse args."""
import argparse
from pathlib import Path

parser = argparse.ArgumentParser()
parser.add_argument(
"-o", "--output", default="single_pass_weld_example.asdf", type=Path
)

args = parser.parse_args(argv if argv is not None else sys.argv)
return args


def main(argv=None):
"""Invoke single_pass_weld_example.
Examples
--------
>>> import tempfile
>>> f = tempfile.NamedTemporaryFile(delete=True)
>>> with f:
... main(['-o', f.name])
"""
args = parse_args(argv)
out = args.output
if out.exists() and out.stat().st_size > 0:
print(f"Destination {out} already exists. Quitting.")
sys.exit(1)

single_pass_weld_example(out)


if __name__ == "__main__":
single_pass_weld_example()
main()
2 changes: 1 addition & 1 deletion weldx/tests/asdf_tests/test_asdf_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from scripts.welding_schema import single_pass_weld_example
from weldx.asdf.cli.welding_schema import single_pass_weld_example
from weldx.asdf.util import get_yaml_header


Expand Down
3 changes: 1 addition & 2 deletions weldx/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""pytest configuration."""
import pytest
from weldx.asdf.cli.welding_schema import single_pass_weld_example


@pytest.fixture(scope="class")
Expand All @@ -23,8 +24,6 @@ def test_foo(self):
...
"""
from scripts.welding_schema import single_pass_weld_example

buff, tree = single_pass_weld_example(out_file=None)
request.cls.single_pass_weld_tree = tree
request.cls.single_pass_weld_file = buff
2 changes: 1 addition & 1 deletion weldx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ def xr_check_coords(dax: xr.DataArray, ref: dict) -> bool:
... },
... d3={"values": ["x", "y", "z"], "dtype": "<U1"},
... )
>>> wx.utility.xr_check_coords(dax, ref)
>>> wx.util.xr_check_coords(dax, ref)
True
"""
Expand Down

0 comments on commit 19b2e97

Please sign in to comment.