summaryrefslogtreecommitdiff
path: root/lib/license/management/python.rb
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-03-31 13:28:27 -0600
committermo khan <mo.khan@gmail.com>2020-04-01 10:05:54 -0600
commit4e4462a6f2052fc7cc5ffe1b4b677ef1af1749b9 (patch)
treee52b1d2e83000aa5d4cb050fa8d2f0cc647b94be /lib/license/management/python.rb
parentd6b721605bfe75d735abe80f365822075f49fa23 (diff)
Pull package info from sources in Pipfile.lock
* Exclude dependencies in "develop" group" * Install pipenv by default * Use .venv to match the default location as pipenv * Use pip-licenses to detect licenses in Pipfile project * Add variation of the MIT License * Redirect asdf install stdout to /dev/null * Add CHANGELOG entry and bump version
Diffstat (limited to 'lib/license/management/python.rb')
-rw-r--r--lib/license/management/python.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/license/management/python.rb b/lib/license/management/python.rb
new file mode 100644
index 0000000..37771ba
--- /dev/null
+++ b/lib/license/management/python.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+module License
+ module Management
+ class Python
+ attr_reader :shell
+
+ def initialize(shell: Shell.new)
+ @shell = shell
+ end
+
+ def major_version
+ version.split('.')[0]
+ end
+
+ def version
+ ENV.fetch('LM_PYTHON_VERSION', '3')
+ end
+
+ def pip_index_url
+ ENV.fetch('PIP_INDEX_URL', 'https://pypi.org/simple/')
+ end
+
+ def pip_licenses(venv: '.venv')
+ _stdout, _stderr, status = shell.sh([
+ ". #{venv}/bin/activate &&",
+ :pip, :install,
+ '--no-index',
+ '--find-links $HOME/.config/virtualenv/app-data', 'pip-licenses', '&&',
+ 'pip-licenses',
+ '--ignore-packages prettytable',
+ '--with-description',
+ '--with-urls',
+ '--from=meta',
+ '--format=json',
+ '--output-file pip-licenses.json'
+ ], env: { 'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin' })
+ return [] unless status.success?
+
+ JSON.parse(IO.read('pip-licenses.json')).map do |dependency|
+ ::LicenseFinder::Package.new(
+ dependency['Name'],
+ dependency['Version'],
+ description: dependency['Description'],
+ homepage: dependency['URL'],
+ spec_licenses: [dependency['License']]
+ )
+ end
+ end
+ end
+ end
+end