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

Order of glob depends on environment #69

Closed
adriangonz opened this issue Jun 23, 2020 · 3 comments
Closed

Order of glob depends on environment #69

adriangonz opened this issue Jun 23, 2020 · 3 comments

Comments

@adriangonz
Copy link

The way that pip-licenses finds license objects in a repo, is by globbing LICENSE*, LICENCE* and COPYING*. However, the output of glob.glob in Python seems to be dependant on the environment.

pip-licenses/piplicenses.py

Lines 131 to 151 in 9c83259

def get_pkg_included_file(pkg, file_names):
"""
Attempt to find the package's included file on disk and return the
tuple (included_file_path, included_file_contents).
"""
included_file = LICENSE_UNKNOWN
included_text = LICENSE_UNKNOWN
pkg_dirname = "{}-{}.dist-info".format(
pkg.project_name.replace("-", "_"), pkg.version)
patterns = []
[patterns.extend(glob.glob(os.path.join(pkg.location,
pkg_dirname,
f))) for f in file_names]
for test_file in patterns:
if os.path.exists(test_file):
included_file = test_file
with open(test_file, encoding='utf-8',
errors='backslashreplace') as included_file_handle:
included_text = included_file_handle.read()
break
return (included_file, included_text)

This becomes an issue in repositories like cryptography, where you have 3 different license files: LICENSE.APACHE, LICENSE.BSD and LICENSE.PSF. Therefore, depending on the environment, pip-licenses will choose one or another.

Suggested solution

One way to fix this would be to sort the output of glob.glob(), so that it's consistent regardless of the environment.

@raimon49
Copy link
Owner

@adamchainz Thanks for the report and suggestions.

I will be using the glob.glob() results sorted in the next release to provide consistent output.

raimon49 added a commit that referenced this issue Jun 24, 2020
The 'LICENSE' is always selected when the following four LICENSE files exist:

LICENSE
LICENSE.APACHE
LICENSE.BSD
LICENSE.PSF
@raimon49 raimon49 mentioned this issue Jun 24, 2020
5 tasks
@raimon49
Copy link
Owner

This issue is addressed in version 2.2.1.
https://pypi.org/project/pip-licenses/2.2.1/

If your problem is resolved, please close this issue.

@adriangonz
Copy link
Author

@raimon49 thanks for the fix! That was really quick!!

I can confirm that the issue is now resolved in 2.2.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants