Skip to content

Commit

Permalink
Updates after review
Browse files Browse the repository at this point in the history
  • Loading branch information
agoncharov-reef committed Oct 6, 2022
1 parent 78dcb8e commit 879cb06
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
23 changes: 10 additions & 13 deletions b2/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,12 @@ class License(Command): # pragma: no cover

REQUIRES_AUTH = False
IGNORE_MODULES = {'b2', 'distlib', 'patchelf-wrapper', 'platformdirs'}
REQUEST_TIMEOUT = 5
REQUEST_TIMEOUT_S = 5

# In case of some modules, we provide manual
# overrides to the license text extracted by piplicenses.
# Thanks to this set, we make sure the module is still used
MODULES_TO_OVERRIDE_LICENSE_TEXT = {'rst2ansi', 'b2sdk', 'PTable'}

LICENSES = {
'atomicwrites':
Expand All @@ -2843,11 +2848,6 @@ def write(self, text, *args, **kwargs):
def __init__(self, console_tool):
super().__init__(console_tool)
self.request_session = requests.session()
self._modules_to_override_license_text = {
'rst2ansi', 'b2sdk', 'PTable'
} # in case of some modules, we provide manual
# overrides to the license text extracted by piplicenses. Thanks to this set, we make sure the module is
# still used

@classmethod
def _setup_parser(cls, parser):
Expand Down Expand Up @@ -2909,6 +2909,7 @@ def _put_license_text_for_packages(self, stream: io.StringIO):
)

licenses = self._get_license_dict()
modules_added = set()
for module_info in licenses:
if module_info['Name'] in self.IGNORE_MODULES:
continue
Expand All @@ -2922,10 +2923,9 @@ def _put_license_text_for_packages(self, stream: io.StringIO):
]
)
license_table.add_row([module_info['Name'], self._get_single_license(module_info)])
modules_added.add(module_info['Name'])

assert not self._modules_to_override_license_text, str(
self._modules_to_override_license_text
)
assert not (self.MODULES_TO_OVERRIDE_LICENSE_TEXT - modules_added)
stream.write(
'Licenses of all modules used by %s, shipped with it in binary form:\n' % (NAME,)
)
Expand Down Expand Up @@ -2954,7 +2954,7 @@ def _get_license_dict(cls) -> dict:
return licenses

def _fetch_license_from_url(self, url: str) -> str:
response = self.request_session.get(url, timeout=self.REQUEST_TIMEOUT)
response = self.request_session.get(url, timeout=self.REQUEST_TIMEOUT_S)
response.raise_for_status()
return response.text

Expand All @@ -2971,9 +2971,6 @@ def _get_single_license(self, module_dict: dict):
elif module_name in self.LICENSES:
license_ = self._fetch_license_from_url(self.LICENSES[module_name])

with suppress(KeyError):
self._modules_to_override_license_text.remove(module_name)

assert license_ != piplicenses.LICENSE_UNKNOWN, module_name

return license_
Expand Down
1 change: 0 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ def integration(session):
'pytest',
'-s',
'-n',
#TODO: revert to str(min(cpu_count(), 8) * 5),
'auto',
'-W',
'ignore::DeprecationWarning:rst2ansi.visitor:',
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def read_requirements(extra=None):
# $ pip install -e .[dev,test]
extras_require={
'doc': read_requirements('doc'),
'license': read_requirements('license')
'license': read_requirements('license'),
},
setup_requires=['setuptools_scm<6.0'],
use_scm_version=True,
Expand Down
2 changes: 1 addition & 1 deletion test/integration/test_b2_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ def test_license(b2_tool, with_packages):
assert license_summary_text
assert len(
license_summary_text.group(0)
) > 15000 # we should know if the length of this block changes dramatically
) > 15_000 # we should know if the length of this block changes dramatically

assert """b2 license:
Backblaze wants developers and organization to copy and re-use our
Expand Down

0 comments on commit 879cb06

Please sign in to comment.