refactor: move package source to src/ layout#32
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #32 +/- ##
==========================================
+ Coverage 88.23% 88.40% +0.17%
==========================================
Files 13 14 +1
Lines 408 414 +6
Branches 16 16
==========================================
+ Hits 360 366 +6
Misses 40 40
Partials 8 8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Moves sample_plugin/ into src/ to adopt the standard src-layout, which prevents accidental imports from the source tree during tests and fixes editable-install compatibility with mypy and other tools that rely on proper package discovery. - backend/sample_plugin/ moved to backend/src/sample_plugin/ - backend/pyproject.toml: add `where = ["src"]` to [tool.setuptools.packages.find] - backend/MANIFEST.in: update recursive-include path, remove stale requirements/ lines - backend/tox.ini: update quality tool invocations to use src/sample_plugin path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
5830a19 to
af561b0
Compare
bradenmacdonald
left a comment
There was a problem hiding this comment.
Thanks @feanil ! I tested this by making an editable install into my edx-platform venv, and it seems to be working well. I left some suggestions but feel free to save them for a future PR.
| where = ["src"] | ||
| include = ["sample_plugin*"] | ||
| exclude = ["sample_plugin.tests*"] | ||
|
|
There was a problem hiding this comment.
Nit: I think if you put the following in, you can delete MANIFEST.in:
| [tool.setuptools.package-data] | |
| # Include these data files when building the wheel, if any are present in src/ | |
| sample_plugin = ["**/*.html", "**/*.png", "**/*.gif", "**/*.js", "**/*.css", "**/*.jpg", "**/*.jpeg", "**/*.svg"] | |
Or, since we're using setuptools-scm, we could use:
[tool.setuptools]
include-package-data = true
to pull in all files in src tracked by git without needing to maintain this separate list of file extensions.
There was a problem hiding this comment.
Also, whether using MANIFEST.in or package-data in pyproject.toml, I would recommend creating an empty py.typed file at src/sample_plugin/py.typed and then adding "py.typed", to this list, e.g. sample_plugin = ["py.typed", "**/*.html", "**/*.png", ... so that mypy will pick up any type definitions if other python projects are importing and using this code. Not so necessary for a plugin but very important for any reusable libraries.
| [tool.setuptools.packages.find] | ||
| where = ["src"] | ||
| include = ["sample_plugin*"] | ||
| exclude = ["sample_plugin.tests*"] |
There was a problem hiding this comment.
| exclude = ["sample_plugin.tests*"] |
I think this exclude is not necessary when you have where = ["src"] and the tests are outside of the src folder.
There was a problem hiding this comment.
I'll remove include = ["sample_plugin*"] too, since the existence of a src folder makes me expect that anything within src should be included.
| isort --check-only --diff tests test_utils sample_plugin manage.py test_settings.py | ||
| pycodestyle src/sample_plugin tests manage.py | ||
| pydocstyle src/sample_plugin tests manage.py | ||
| isort --check-only --diff tests test_utils src/sample_plugin manage.py test_settings.py |
kdmccormick
left a comment
There was a problem hiding this comment.
Nice, nothing to add beyond what Farhan and Braden have said.
Summary
backend/sample_plugin/tobackend/src/sample_plugin/to adopt the standardsrc/layoutwhere = ["src"]to[tool.setuptools.packages.find]inbackend/pyproject.tomlbackend/MANIFEST.into use the new path and removes stalerequirements/linesbackend/tox.iniquality commands (pylint, pycodestyle, pydocstyle, isort) to referencesrc/sample_pluginMotivated by feedback on openedx/public-engineering#506: the
src/layout prevents accidental imports from the source tree during tests and fixes editable-install compatibility with mypy and other static analysis tools.