def _get_license(name: str) -> Union[License, str]: license = licenses.get_by_id(name) if license is not None: return license license = licenses.get_by_name(name) if license is not None: return license return name
def __call__(self) -> bool: # get license object name = ' '.join(self.args.name).strip() if not name: name = 'MIT' license = licenses.get_by_id(name) if license is None: license = licenses.get_by_name(name) if license is None: self.logger.error('cannot find license with given name') return False # generate license text text = license.make_text(copyright='{year} {name}'.format( year=datetime.now().year, name=getuser().title(), )) (Path(self.config['project']) / 'LICENSE').write_text(text) self.logger.info('license generated', extra=dict(license=license.name)) return True
def __call__(self) -> bool: # get license object name = ' '.join(self.args.name).strip() if not name: name = 'MIT' license = licenses.get_by_id(name) if license is None: license = licenses.get_by_name(name) if license is None: self.logger.error('cannot find license with given name') return False # author name from --owner author = self.config.get('owner') # get author from `from` if not author and 'from' in self.config: loader = CONVERTERS[self.config['from']['format']] loader = loader.copy(project_path=Path(self.config['project'])) root = loader.load(self.config['from']['path']) if root.authors: author = root.authors[0] # author from project config file if not author: metainfo = PackageRoot(Path(self.config['project'])).metainfo if metainfo and metainfo.authors: author = metainfo.authors[0] # author from getuser().title if not author: author = getuser().title() # generate license text text = license.make_text(copyright='{year} {name}'.format( year=datetime.now().year, name=author, )) (Path(self.config['project']) / 'LICENSE').write_text(text) self.logger.info('license generated', extra=dict(license=license.name)) return True
def _get_license(data: dict) -> Union[str, License, None]: license_classifier = None for classifier in data['classifiers']: if classifier.startswith('License :: '): license_classifier = classifier.split(' :: ')[-1].strip() license = licenses.get_by_classifier(classifier) if license is not None: return license if data['license'] in ('UNKNOWN', '', None): return license_classifier license = licenses.get_by_id(data['license']) if license is not None: return license license = licenses.get_by_name(data['license']) if license is not None: return license if license_classifier: return license_classifier return data['license']