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

Conversation

samet-akcay
Copy link
Contributor

@samet-akcay samet-akcay commented Feb 20, 2023

Description

  • This PR changes the project structure to src layout. The overall tree structure will be as follows:
├── CHANGELOG.md
├── CITATION.cff
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── datasets
├── docs
│   ├── anomalib.png
│   ├── Makefile
│   └── source
├── LICENSE
├── MANIFEST.in
├── notebooks
│   ├── 000_getting_started
│   ├── 100_datamodules
│   ├── 200_models
│   ├── 300_benchmarking
│   ├── 400_openvino
│   └── README.md
├── pyproject.toml
├── README.md
├── requirements
│   ├── base.txt
│   ├── dev.txt
│   ├── docs.txt
│   ├── extras.txt
│   └── openvino.txt
├── setup.py
├── src
│   └── anomalib
├── tests
│   ├── helpers
│   ├── __init__.py
│   ├── nightly
│   └── pre_merge
├── third-party-programs.txt
├── tools
│   ├── benchmarking
│   ├── hpo
│   ├── inference
│   ├── test.py
│   └── train.py
└── tox.ini

This official python link outlines the main advantages of this layout. Some of these are as follows:

  • The src layout requires installation of the project to be able to run its code, and the flat layout does not.
    This means that the src layout involves an additional step in the development workflow of a project (typically, an editable installation is used for development and a regular installation is used for testing).

  • The src layout helps prevent accidental usage of the in-development copy of the code.
    This is relevant since the Python interpreter includes the current working directory as the first item on the import path. This means that if an import package exists in the current working directory with the same name as an installed import package, the variant from the current working directory will be used. This can lead to subtle misconfiguration of the project’s packaging tooling, which could result in files not being included in a distribution.

  • The src layout helps avoid this by keeping import packages in a directory separate from the root directory of the project, ensuring that the installed copy is used.

  • The src layout helps enforce that an editable installation is only able to import files that were meant to be importable.
    This is especially relevant when the editable installation is implemented using a path configuration file that adds the directory to the import path.
    The flat layout would add the other project files (eg: README.md, tox.ini) and packaging/tooling configuration files (eg: setup.py, noxfile.py) on the import path. This would make certain imports work in editable installations but not regular installations.

Changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (non-breaking change which refactors the code base)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the pre-commit style and check guidelines of this project.
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes
  • I have added a summary of my changes to the CHANGELOG (not for minor changes, docs and tests).

@github-actions github-actions bot added CI Dependencies Pull requests that update a dependency file Setup labels Feb 20, 2023
@samet-akcay samet-akcay enabled auto-merge (squash) February 20, 2023 12:42
Comment on lines +76 to +77
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# PYTEST CONFIGURATION #
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

Copy link
Collaborator

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

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

Thanks. One question

tox.ini Outdated Show resolved Hide resolved
@github-actions github-actions bot added the Tests label Mar 2, 2023
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov
Copy link

codecov bot commented Mar 8, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -3.63 ⚠️

Comparison is base (d0b8ce8) 84.97% compared to head (b0926af) 81.34%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #921      +/-   ##
==========================================
- Coverage   84.97%   81.34%   -3.63%     
==========================================
  Files         169      176       +7     
  Lines        6521     6812     +291     
==========================================
  Hits         5541     5541              
- Misses        980     1271     +291     
Impacted Files Coverage Δ
src/anomalib/__init__.py 100.00% <ø> (ø)
src/anomalib/config/__init__.py 100.00% <ø> (ø)
src/anomalib/data/__init__.py 60.97% <ø> (ø)
src/anomalib/data/avenue.py 71.42% <ø> (ø)
src/anomalib/data/base/__init__.py 100.00% <ø> (ø)
src/anomalib/data/base/datamodule.py 96.34% <ø> (ø)
src/anomalib/data/base/dataset.py 97.72% <ø> (ø)
src/anomalib/data/base/depth.py 31.57% <ø> (ø)
src/anomalib/data/base/video.py 100.00% <ø> (ø)
src/anomalib/data/btech.py 84.21% <ø> (ø)
... and 173 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Collaborator

@ashwinvaidya17 ashwinvaidya17 left a comment

Choose a reason for hiding this comment

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

Thanks

@samet-akcay samet-akcay merged commit 5cadb65 into openvinotoolkit:main Mar 9, 2023
@samet-akcay samet-akcay deleted the switch-to-src-layout branch November 28, 2023 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Dependencies Pull requests that update a dependency file Notebooks Setup Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants