fix: directory is not package unless contains metadata file #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
iter_packagespreviously considered any directory in a package_path to be a package.This adds a check that the metadata.path is a file before considering the directory to be a package.
When monas loads its configuration from the top level
pyproject.toml, it reads the "packages" field to find local packages via thepackage_pathsproperty.iter_packageswill scan thepackage_paths, and check if each one is a directory before turning it into aPyPackageclass and yielding it as one of the local monorepo packages.The
PyPackageclass will initialize just fine when provided an empty directory. This behavior starts with a check if there is apyproject.tomlfile, and if one is not found, it will set its metadata to an empty dict. TheSetupCfgMetadataclass'smatchfunction will returnTrueif provided such an empty dict. This means an empty directory scanned byiter_packageswill be initialized as a valid setupcfg project, even in there is no matchingsetup.cfgfile contained in the directory.I think there may be an argument to preventing this class from initializing at all if there is not a valid
setup.cfgfile contained in the directory. I wasn't sure if the existing logic was intentional, so I didn't change it.Instead, I just added a check to
iter_packagesthat verifies that the expected metadata file exists before returning it as a package.