Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to src layout #921

Merged
merged 12 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion notebooks/000_getting_started/001_getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"outputs": [],
"source": [
"MODEL = \"padim\" # 'padim', 'cflow', 'stfpm', 'ganomaly', 'dfkde', 'patchcore'\n",
"CONFIG_PATH = root_directory / f\"anomalib/models/{MODEL}/config.yaml\"\n",
"CONFIG_PATH = root_directory / f\"src/anomalib/models/{MODEL}/config.yaml\"\n",
"with open(file=CONFIG_PATH, mode=\"r\", encoding=\"utf-8\") as file:\n",
" print(file.read())"
]
Expand Down
18 changes: 18 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,19 @@ follow_imports = "skip"
follow_imports_for_stubs = true


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# PYTEST CONFIGURATION #
Comment on lines +76 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the changes to this file related to switching to src layout or is this something separate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's separate, but would be good to have. VSCode would automatically detect the tests

[tool.pytest.ini_options]
addopts = [
"--strict-markers",
"--strict-config",
"--showlocals",
"-ra",
]
testpaths = "tests"
pythonpath = "src"


# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# COVERAGE CONFIGURATION #
[tool.coverage.report]
Expand All @@ -84,6 +97,11 @@ exclude_lines = [
"raise ValueError",
]

[tool.coverage.paths]
source = [
"src",
".tox/*/site-packages",
]

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# NBQA CONFIGURATION #
Expand Down
4 changes: 4 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pre-commit
pytest
pytest-cov
pytest-sugar
pytest-xdist
coverage[toml]
tox
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from setuptools import find_packages, setup


def load_module(name: str = "anomalib/__init__.py") -> ModuleType:
def load_module(name: str = "src/anomalib/__init__.py") -> ModuleType:
"""Load Python Module.

Args:
Expand Down Expand Up @@ -45,7 +45,7 @@ def get_version() -> str:
Returns:
str: `anomalib` version.
"""
anomalib = load_module(name="anomalib/__init__.py")
anomalib = load_module(name="src/anomalib/__init__.py")
version = anomalib.__version__
return version

Expand Down Expand Up @@ -102,7 +102,8 @@ def get_required_packages(requirement_files: list[str]) -> list[str]:
'Licensed under the Apache License, Version 2.0 (the "License")'
"See LICENSE file for more details.",
python_requires=">=3.7",
packages=find_packages(exclude=("tests",)),
package_dir={"": "src"},
packages=find_packages(where="src", include=["anomalib", "anomalib.*"]),
install_requires=INSTALL_REQUIRES,
extras_require=EXTRAS_REQUIRE,
package_data={"": ["config.yaml"]},
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def get_configurable_parameters(
)

if config_path is None:
config_path = Path(f"anomalib/models/{model_name}/{config_filename}.{config_file_extension}")
config_path = Path(f"src/anomalib/models/{model_name}/{config_filename}.{config_file_extension}")

config = OmegaConf.load(config_path)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run_train_test(config):

@TestDataset(num_train=200, num_test=30, path=get_dataset_path(), seed=42)
def test_normalizer(path=get_dataset_path(), category="shapes"):
config = get_configurable_parameters(config_path="anomalib/models/padim/config.yaml")
config = get_configurable_parameters(config_path="src/anomalib/models/padim/config.yaml")
config.dataset.path = path
config.dataset.category = category
config.metrics.threshold.method = "adaptive"
Expand Down
2 changes: 1 addition & 1 deletion tests/pre_merge/utils/metrics/test_adaptive_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_manual_threshold():
Test if the manual threshold gets used in the F1 score computation when
adaptive thresholding is disabled and no normalization is used.
"""
config = get_test_configurable_parameters(config_path="anomalib/models/padim/config.yaml")
config = get_test_configurable_parameters(config_path="src/anomalib/models/padim/config.yaml")

config.dataset.num_workers = 0
config.model.normalization_method = "none"
Expand Down
19 changes: 11 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ passenv = ftp_proxy
deps =
coverage[toml]
pytest
pytest-cov
flaky
nbmake
-r{toxinidir}/requirements/base.txt
Expand All @@ -31,15 +32,17 @@ deps =

commands =
; 1. Run Coverage First.
coverage erase
coverage run --include=anomalib/* -m pytest {posargs:tests/pre_merge/} -ra --showlocals
; https://github.com/openvinotoolkit/anomalib/issues/94
coverage report -m --fail-under=85
coverage xml -o {toxworkdir}/coverage.xml
pytest tests/pre_merge \
--cov=anomalib \
--cov-report=xml:{toxworkdir}/coverage.xml \
--cov-fail-under=8.5 \
{posargs}

; 2. Test Jupyter Notebooks.
; TODO: CVS-102917 - Add tests for 300_benchmarking and 400_openvino
pytest --nbmake notebooks --ignore=notebooks/300_benchmarking --ignore=notebooks/400_openvino --ignore=notebooks/500_use_cases/501_dobot
pytest --nbmake notebooks \
--ignore=notebooks/300_benchmarking \
--ignore=notebooks/400_openvino \
--ignore=notebooks/500_use_cases/501_dobot

[testenv:nightly]
basepython = python3
Expand All @@ -57,7 +60,7 @@ deps =
-r{toxinidir}/requirements/extras.txt
commands =
coverage erase
coverage run --include=anomalib/* -m pytest tests/nightly/ -ra --showlocals
coverage run --include=anomalib/* -m pytest tests/nightly/
coverage report -m --fail-under=33
coverage xml -o {toxworkdir}/coverage.xml

Expand Down