PK!$licencia/__init__.py__version__ = "0.1.1" PK!Tlicencia/app.py#!/usr/bin/env python from cleo import Application from . import __version__ from .commands import ListCommand application = Application("licencia", __version__, complete=True) application.add(ListCommand()) PK!Yg;QQlicencia/commands.pyimport sys from cleo import Command from .core import create_table from .core import get_package_names from .core import get_packages_metadata from .core import load_toml class ListCommand(Command): """ List the licenses for external packages used in your repository. list {--o|order=name : Control display order by "name" or "license".} {--f|format=compact : Select the output format among: "compact", "markdown", or "rst"} """ def handle(self): try: pyproject = load_toml("poetry.lock") except FileNotFoundError: self.line_error("ERROR: The lock file not found.", style="error") sys.exit(1) package_names = get_package_names(pyproject) if not package_names: self.line("No data") sys.exit(1) results = get_packages_metadata(package_names) rows = [(p["name"], p["license"]) for p in results] order = self.option("order") style = self.option("format") table = create_table(rows, order=order, style=style) print(table) PK!licencia/core.pyimport importlib_metadata import tomlkit from beautifultable import BeautifulTable def load_toml(filename): """ Load toml file. :param filename: filename :return: toml body :rtype: dict """ with open(filename) as f: return tomlkit.parse(f.read()) def get_package_names(pyproject): """ Get package names :param dict pyproject: pyproject.toml body. :return: Package names :rtype: list """ package_names = [] for pkg in pyproject["package"]: if pkg["category"] == "main": package_names.append(pkg["name"]) return package_names def get_packages_metadata(package_names): """ Get list of installed package's metadata :param list package_names: Install package names. :return: list of dict. Dict contains package name and license. :rtype: list """ results = [] for name in package_names: d = {"name": name} try: metadata = importlib_metadata.metadata(name) except importlib_metadata.api.PackageNotFoundError: continue else: d["version"] = metadata["Version"] d["license"] = metadata["License"] results.append(d) return results def create_table(rows, order, style): """ Create table for display :param list rows: table rows :param str order: table sorted order :param str style: table style :return: table for display :rtype: BeautifulTable """ table = BeautifulTable() table.column_headers = ["name", "license"] table.column_alignments["name"] = BeautifulTable.ALIGN_LEFT table.column_alignments["license"] = BeautifulTable.ALIGN_LEFT if style == "markdown": table.set_style(BeautifulTable.STYLE_MARKDOWN) elif style == "rst": table.set_style(BeautifulTable.STYLE_RESTRUCTURED_TEXT) else: table.set_style(BeautifulTable.STYLE_COMPACT) for row in rows: table.append_row(row) if order == "license": table.sort("license") return table PK!Hh ^29)licencia-0.1.1.dist-info/entry_points.txtN+I/N.,()LNKL1 O,+*PK!c+$$ licencia-0.1.1.dist-info/LICENSEMIT License Copyright (c) 2019 kk6 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!HڽTUlicencia-0.1.1.dist-info/WHEEL A н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK!HN!licencia-0.1.1.dist-info/METADATAN0 {"GV+[a6(8%k&HCߞN]YQIt``*Uqa/h{e:xz/M _7 ֶCJk@ЀulAet,?{ҥ!pt ,/' ɰokMmQkj3Xzߑ{O^y,dg9ɒC/4#a"7+*S}1^xUK~tE7 PK!H Qlicencia-0.1.1.dist-info/RECORD}˒0y? AAP*p8㤻[UNIӐJjGlફWI`kfjׅmRE6k:ͽa~/n.{ShPxG{վO%Ғ8Hs@3ae>7؃t|[Ĝc"UssM ]8Qwߠʡx7[ B֟ױ4eZ ⅑T5OOӺ0ը±loΰK5;,F<fT{o6pN߮V_zo~#p,D|A=ꂵf{D&QS8юbb4_R+=LEB 'Gu,t7d<H[ԷHfK