-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
#1350 - Improvements to handling of License file(s) #1367
#1350 - Improvements to handling of License file(s) #1367
Conversation
5e71017
to
5dac570
Compare
Yay, everything passes now. 🎉 |
Hey, just dropping in to help with reviewing a bit, hope this is useful, otherwise, just tell me to shut up :) |
6d60ccb
to
3ab5208
Compare
The rebase to keep on top of #1349 and the other changes was a little tricky, but I feel like the changes still fit pretty well and it was worth it since new tests found an easily fixed mistake with how I was using Path objects in This PR is once again ready for a merge! 🎉 |
I am not sure what this PR tries to solve. Instead of using a new |
T.L.D.R. Version = Yes @sdispater You are right about being able to achieve some of this just by using At the moment you can include a license file using There is currently an evolving discussion about the next set of changes to the package metadata format. https://discuss.python.org/t/improving-license-clarity-with-better-package-metadata/2154 and while the discussion isn't finalised yet the idea of adding a specific field to the package metadata to specify which included files are license related seems to have no one arguing against it so it is likely to be part of the next revision. The changes in this PR, put Case in point, I mentioned the open PR on |
for license_file in local_config["license-files"]: | ||
package.license_files.add(Path(poetry_file.parent) / license_file) | ||
else: | ||
for license_file in poetry_file.parent.glob("LICENSE*"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure whether the stdlib's globbing implementation supports this, but {COPYING*,LICENSE*}
should be enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The standard library globbing doesnt support multiple patterns unfortunately. https://docs.python.org/3/library/glob.html#glob.glob
I've just tried a few variations but none of them are particularly nice looking, and black
has a tendency to reformat them over more lines than the code they would replace.
for glob_pattern in ("LICENSE*", "COPYING*"):
for license_file in poetry_file.parent.glob(glob_pattern):
package.license_files.add(
license_file.relative_to(poetry_file.parent)
)
The code above was the nicest result and I'm happy to change it but it is at the end of the day... really just a fancier way of doing the same thing as the original code below.
for license_file in poetry_file.parent.glob("LICENSE*"):
package.license_files.add(license_file.relative_to(poetry_file.parent))
for license_file in poetry_file.parent.glob("COPYING*"):
package.license_files.add(license_file.relative_to(poetry_file.parent))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@funkyfuture Any more thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i made some remarks.
3ab5208
to
23a6c0e
Compare
@@ -146,8 +146,9 @@ def find_files_to_add(self, exclude_build=True): # type: (bool) -> list | |||
) | |||
to_add.append(Path("pyproject.toml")) | |||
|
|||
# If a license file exists, add it | |||
for license_file in self._path.glob("LICENSE*"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep this line if there are no license_files
specified in the pyproject.toml
file, so that people relying on the current behavior are not surprised and published packages are not suddenly missing license files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sdispater - I agree this should remain the "default path" and I made sure to retain this behaviour as part of my changes. This functionality was consolidated into the package setup stuff (which is now in factory.py
) and is currently being discussed above: #1367 (comment) & #1367 (comment)
The specific lines for automatically adding LICENSE*
and COPYING*
is in factory.py
here:
And I also added a test case for this existing/default behaviour when no license_files
have been specified. 😃https://github.com/techdragon/poetry/blob/issue-1350-license-metadata-improvements/tests/masonry/builders/test_complete.py#L394-L416
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sdispater Since the functionality is retained as desired, but powered by new code in a different place, if you don't mind, id like to mark this as resolved. 😄
As an optional feature I think this is a good idea. It will likely not make it to the |
Back for a new year and I see that pypa/setuptools#1767 has been merged and poetry 1.0.0 has shipped! So I'm going to try and find a little time this week to update this PR. |
23a6c0e
to
391f024
Compare
28207ec
to
408a4e5
Compare
- Fixes python-poetry#1350 - Added support for specifying a set of license files as part of the project config. - Moved the license file config into the package configuration. (`Factory.create_poetry()`) this matches how similar configurations such as “readme” are configured. - Updated the builders to use the project level license file list instead of searching for their own (previously different) lists of license files. - Moved the existing auto-discovery behaviours to become the default case during `create_poetry()` if nothing specific was configured. - Added tests for the new features - Documented the new configuration field. - Added the “license-files” field to the poetry-schema.json - Updated pre-commit config to use the correct black source repo, and set the default language for better consistency with any other pre-commit checks that will be added in the future. - Fix python-poetry#866 by modifing the base template used by `SdistBuilder`. It now uses `setuptools`, since as documented by @seifertm in issue python-poetry#866 `pip` uses `setuptools` anyway and this clears the way to immediately supporting pypa/setuptools#1767 once this is merged and released from `setuptools`. Until `setuptools` updates to support multiple license files, this will result in a single log line in the debug output from `setuptools` so this is ok to merge before the change to `setuptools` is merged.
408a4e5
to
9e807f7
Compare
@techdragon are you still interested in bringing this to Poetry? If so, please merge master and change the target branch to master. This will allow for review against the current codebase. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Factory.create_poetry()
) this matches how similar configurations such as “readme” are configured.create_poetry()
if nothing specific was configured.SdistBuilder
. It now usessetuptools
, since as documented by @seifertm in issue Generated setup.py should use setuptools.setup instead of distutils.core.setup #866pip
usessetuptools
anyway and this clears the way to immediately supporting Add support forlicense_files
option in metadata pypa/setuptools#1767 once this is merged and released fromsetuptools
. Untilsetuptools
updates to support multiple license files, this will result in a single log line in the debug output fromsetuptools
so this is ok to merge before the change tosetuptools
is merged.Pull Request Check List
This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!
Note: If your Pull Request introduces a new feature or changes the current behavior, it should be based
on the
develop
branch. If it's a bug fix or only a documentation update, it should be based on themaster
branch.If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!