Skip to content

Commit

Permalink
fix(tests): gh workflow, import statements, pre-commit (#1)
Browse files Browse the repository at this point in the history
* fix(tests): import statement in test_mesh

Update issue form link in contributing guide to point to correct repo

* build: remove schema linter

was falsely copied over from other repo

* build(test): fix test call, update Python version

Update Python version to 3.11 and add style and
type-checking steps.

* test: fix test package name, coverage paths

* test: remove path object as context manager

using paths as context manager gives no benefit of releasing resources,

* chore: remove unused pydantic-mypy config

* test(coverage): fix coverage data collection

disable -n option to set number of workers. It fails coverage

* chore(precommit): remove pydantic dep from mypy hook

fix copypasta error that left pydantic as a dependency for the mypy

* ci(tests): fix linting and test envs

add environments for linting & testing to avoid pre-commit hooks in ci

* test: fix numpy array return type

use numpy.typing.NDArray to type array and dtype correctly

* ci: ignore missing imports or trimesh and scipy

mypy was throwing errors about missing library stubs
  • Loading branch information
Olaf-Wolf3D authored Nov 8, 2023
1 parent 5d43641 commit 2815266
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 58 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/linter.yml

This file was deleted.

13 changes: 8 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
python-version: ['3.11']

steps:
- uses: actions/checkout@v3
Expand All @@ -36,8 +36,11 @@ jobs:
- name: Install Hatch
run: pip install --upgrade hatch

- name: Run tests
run: hatch run cov

- name: Run linting
run: hatch run lint:all
run: hatch run lint:style

- name: Run type-checking
run: hatch run lint:typing

- name: Run tests
run: hatch run test:cov
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ repos:
rev: 'v1.5.1'
hooks:
- id: mypy
additional_dependencies:
- "pydantic>=2.1"
additional_dependencies: [numpy]

- repo: https://github.com/espressif/conventional-precommit-linter
rev: v1.2.1
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ Here are some resources to help you get started with open source contributions:
### Create a new issue

If you spot a problem with the schemas or package, [search if an issue already exists](https://docs.github.com/en/github/searching-for-information-on-github/searching-on-github/searching-issues-and-pull-requests#search-by-the-title-body-or-comments).
If a related issue doesn't exist, you can open a new issue using a relevant [issue form](https://github.com/readyplayerme/texturesynthesis/issues/new/choose).
If a related issue doesn't exist, you can open a new issue using a relevant [issue form](https://github.com/readyplayerme/meshops/issues/new/choose).

### Solve an issue

Scan through our [existing issues](https://github.com/readyplayerme/texturesynthesis/issues) to find one that interests you.
Scan through our [existing issues](https://github.com/readyplayerme/meshops/issues) to find one that interests you.
You can narrow down the search using `labels` as filters.

### Labels

Labels can help you find an issue you'd like to help with.
The [`good first issue` label](https://github.com/readyplayerme/texturesynthesis/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) is for problems or updates we think are ideal for new joiners.
The [`good first issue` label](https://github.com/readyplayerme/meshops/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) is for problems or updates we think are ideal for new joiners.

## Contribute

Expand Down
57 changes: 38 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ dependencies = [
]

[project.optional-dependencies]
tests = [
test = [
"pytest",
"pytest-xdist",
"coverage[toml]>=6.5",
]
lint = [
"black>=23.3.0",
"mypy>=1.5.1",
"ruff>=0.0.285",
]
dev = [
"readyplayerme.meshops[tests]",
"readyplayerme.meshops[test, lint]",
"pre-commit",
]

Expand All @@ -58,13 +64,6 @@ packages = ["src/readyplayerme"]
description = "Python virtual environment in project dir to quickly get up and running in an IDE like VSCode."
type = "virtual"
path = ".venv"
dependencies = [
"black>=23.3.0",
"mypy>=1.5.1",
"ruff>=0.0.285",
"coverage[toml]>=6.5",
"pytest",
]
features = [
"dev",
]
Expand Down Expand Up @@ -100,11 +99,27 @@ all = [
"cov",
]

[tool.hatch.envs.lint]
description = "Python virtual environment to be used in CI to run linting and type checking."
# Note: This still inherits the path from the default env, so it will use the same venv.
features = [
"lint",
]
post-install-commands = []

[tool.hatch.envs.test]
description = "Python virtual environment to be used in CI to run tests."
# Note: This still inherits the path from the default env, so it will use the same venv.
features = [
"test",
]
post-install-commands = []

[[tool.hatch.envs.all.matrix]]
python = ["3.10", "3.11"]

[tool.pytest.ini_options]
addopts="-n 4"
#addopts="-n auto"

[tool.black]
target-versions = ["py310", "py311"]
Expand Down Expand Up @@ -227,6 +242,7 @@ warn_unused_ignores = true
disallow_any_generics = true
check_untyped_defs = true
no_implicit_reexport = true
plugins = ["numpy.typing.mypy_plugin"]

[[tool.mypy.overrides]]
module = "readyplayerme.*"
Expand All @@ -235,25 +251,28 @@ ignore_missing_imports = true
# for strict mypy:
disallow_untyped_defs = false

[tool.pydantic-mypy]
init_forbid_extra = true
init_typed = true
warn_required_dynamic_aliases = true
warn_untyped_fields = true
[[tool.mypy.overrides]]
module = "trimesh.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "scipy.*"
ignore_missing_imports = true

[tool.coverage.run]
source_pkgs = ["readyplayerme/meshops", "tests"]
source_pkgs = ["readyplayerme", "tests"]
branch = true
parallel = true
omit = [
"src/readyplayerme/meshops/__about__.py",
"src/readyplayerme/*/__about__.py",
]

[tool.coverage.paths]
readyplayerme_meshops = ["src/readyplayerme/meshops", "*/meshops/src/readyplayerme/meshops"]
tests = ["tests", "*/content-validation-schemas/tests"]
coverage_debugging = ["src/readyplayerme", "*/meshops/src/readyplayerme"]
tests = ["tests", "*/meshops/tests"]

[tool.coverage.report]
include_namespace_packages = true
exclude_lines = [
"no cov",
"if __name__ == .__main__.:",
Expand Down
3 changes: 2 additions & 1 deletion src/readyplayerme/meshops/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TypeAlias

import numpy as np
import numpy.typing as npt
import trimesh

# Abstraction for the mesh type.
Expand Down Expand Up @@ -37,7 +38,7 @@ def read_glb(filename: str | Path) -> Mesh:
return trimesh.load(filename, process=False, force="mesh")


def get_border_vertices(mesh: Mesh) -> np.array:
def get_border_vertices(mesh: Mesh) -> npt.NDArray[np.int64]:
"""Return the indices of the vertices on the borders of a mesh.
:param mesh: The mesh to get the border vertices from.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Unit tests for the mesh module."""
from pathlib import Path

from readyplayerme.texturesynthesis import mesh
from readyplayerme.meshops import mesh

mocks_path = Path(__file__).parent.parent.parent / "mocks"


def test_read_glb():
"""Test the read_glb function returns the expected type."""
with mocks_path / "input-mesh.glb" as filename:
result = mesh.read_glb(filename)
filename = mocks_path / "input-mesh.glb"
result = mesh.read_glb(filename)
assert isinstance(result, mesh.Mesh), "The result should be an instance of mesh.Mesh"


Expand All @@ -18,8 +18,8 @@ def test_border_vertices():
import numpy as np

# TODO: create a fixture for loading the file, or mock it, loading the mesh should not be part of the test!
with mocks_path / "uv-seams.glb" as filename:
geo = mesh.read_glb(filename)
filename = mocks_path / "uv-seams.glb"
geo = mesh.read_glb(filename)
border_vertices = mesh.get_border_vertices(geo)

assert np.array_equiv(np.sort(border_vertices), [0, 2, 4, 6, 7, 9, 10])

0 comments on commit 2815266

Please sign in to comment.