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

#1350 - Improvements to handling of License file(s) #1367

Conversation

techdragon
Copy link

@techdragon techdragon commented Sep 10, 2019

  • Fixes License Files listing in Metadata #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 Generated setup.py should use setuptools.setup instead of distutils.core.setup #866 by modifing the base template used by SdistBuilder. It now uses setuptools, since as documented by @seifertm in issue Generated setup.py should use setuptools.setup instead of distutils.core.setup #866 pip uses setuptools anyway and this clears the way to immediately supporting Add support for license_files option in metadata 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.

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!

  • Added tests for changed code.
  • Updated documentation for changed code.

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 the master 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!

@techdragon techdragon force-pushed the issue-1350-license-metadata-improvements branch 6 times, most recently from 5e71017 to 5dac570 Compare September 12, 2019 08:11
@techdragon
Copy link
Author

Yay, everything passes now. 🎉

poetry/poetry.py Outdated Show resolved Hide resolved
@bjoernpollex
Copy link
Contributor

Hey, just dropping in to help with reviewing a bit, hope this is useful, otherwise, just tell me to shut up :)

@techdragon techdragon force-pushed the issue-1350-license-metadata-improvements branch 3 times, most recently from 6d60ccb to 3ab5208 Compare September 17, 2019 04:02
@techdragon
Copy link
Author

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 sdist.py 😄

This PR is once again ready for a merge! 🎉

@sdispater
Copy link
Member

I am not sure what this PR tries to solve. Instead of using a new license_files property, isn't it possible to use the include property?

@techdragon
Copy link
Author

T.L.D.R. Version = Yes poetry can use include for license files, but it doesn't know which files it included in the package are the license files for the package. This change makes it so poetry knows which included files are license files so the package builder classes can use that info.

@sdispater You are right about being able to achieve some of this just by using include but the point of the change is to better handle the metadata that is represented by the new field.

At the moment you can include a license file using include, but this just includes them the same as any other file and does not associate them as special in any way.

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 poetry in a position to easily adapt to this potential future revision by keeping track of which included files were license related so that this can be passed on in the package metadata.

Case in point, I mentioned the open PR on setuptools, which when merged will make it possible to pass a list into the license_files keyword argument of the setup() function. I've added this functionality into the sdist builder class since setuptools is pretty tolerant of keyword arguments it doesn't know how to handle, as outlined in the linked PR.

@kasteph kasteph added kind/feature Feature requests/implementations area/build-system Related to PEP 517 packaging (see poetry-core) labels Sep 24, 2019
docs/docs/pyproject.md Outdated Show resolved Hide resolved
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*"):
Copy link
Contributor

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.

Copy link
Author

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))

Copy link
Author

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?

Copy link
Contributor

@funkyfuture funkyfuture left a 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.

@techdragon techdragon force-pushed the issue-1350-license-metadata-improvements branch from 3ab5208 to 23a6c0e Compare September 26, 2019 08:38
@@ -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*"):
Copy link
Member

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.

Copy link
Author

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

Copy link
Author

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. 😄

@sdispater
Copy link
Member

As an optional feature I think this is a good idea. It will likely not make it to the 1.0.0 version since it's now pretty much feature-frozen but it will be integrated in a future minor version.

@sdispater sdispater added this to the Future milestone Sep 30, 2019
@techdragon
Copy link
Author

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.

@techdragon techdragon mentioned this pull request Jan 6, 2020
2 tasks
@techdragon techdragon force-pushed the issue-1350-license-metadata-improvements branch from 23a6c0e to 391f024 Compare January 7, 2020 04:46
@techdragon techdragon requested a review from sdispater January 7, 2020 04:50
@techdragon techdragon force-pushed the issue-1350-license-metadata-improvements branch 2 times, most recently from 28207ec to 408a4e5 Compare January 7, 2020 05:40
- 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.
@techdragon techdragon force-pushed the issue-1350-license-metadata-improvements branch from 408a4e5 to 9e807f7 Compare January 7, 2020 05:49
@finswimmer finswimmer requested a review from a team January 8, 2020 05:13
@neersighted neersighted self-assigned this Nov 14, 2021
@Secrus
Copy link
Member

Secrus commented May 21, 2022

@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.

@Secrus Secrus added the status/waiting-on-response Waiting on response from author label May 21, 2022
@neersighted neersighted deleted the branch python-poetry:develop August 23, 2022 01:19
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/build-system Related to PEP 517 packaging (see poetry-core) kind/feature Feature requests/implementations status/waiting-on-response Waiting on response from author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants