<pre style='margin:0'>
Renee Otten (reneeotten) pushed a commit to branch master
in repository upt-macports.
</pre>
<p><a href="https://github.com/macports/upt-macports/commit/5847f0f628e37720ba2eceda8974e6a63f37f1ae">https://github.com/macports/upt-macports/commit/5847f0f628e37720ba2eceda8974e6a63f37f1ae</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/master by this push:
<span style='display:block; white-space:pre;color:#404040;'> new 5847f0f Recursive Packaging
</span>5847f0f is described below
<span style='display:block; white-space:pre;color:#808000;'>commit 5847f0f628e37720ba2eceda8974e6a63f37f1ae
</span>Author: Korusuke <karan.sheth@somaiya.edu>
AuthorDate: Thu Jun 20 01:40:37 2019 +0530
<span style='display:block; white-space:pre;color:#404040;'> Recursive Packaging
</span>---
upt_macports/tests/test_macports_backend.py | 35 +++++++++++++++++++
upt_macports/upt_macports.py | 54 +++++++++++++++++++++++------
2 files changed, 79 insertions(+), 10 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/upt_macports/tests/test_macports_backend.py b/upt_macports/tests/test_macports_backend.py
</span><span style='display:block; white-space:pre;color:#808080;'>index 134a9f8..7a6b3fa 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/upt_macports/tests/test_macports_backend.py
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/upt_macports/tests/test_macports_backend.py
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1,4 +1,5 @@
</span> import unittest
<span style='display:block; white-space:pre;background:#e0ffe0;'>+from unittest import mock
</span> import upt
from upt_macports.upt_macports import MacPortsBackend
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -14,5 +15,39 @@ class TestMacPortsBackend(unittest.TestCase):
</span> self.macports_backend.create_package(upt_pkg)
<span style='display:block; white-space:pre;background:#e0ffe0;'>+class TestMacPortsPackageExist(unittest.TestCase):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def setUp(self):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.macports_backend = MacPortsBackend()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.macports_backend.upt_pkg = upt.Package('foo', '42')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.macports_backend.frontend = 'pypi'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('subprocess.getoutput')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_port_found(self, mock_sub):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ expected = ['0.123']
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ mock_sub.return_value = 'version: 0.123'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.assertEqual(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.macports_backend.package_versions('foo'), expected)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('subprocess.getoutput')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_port_not_found(self, mock_sub):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ expected = []
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ mock_sub.return_value = 'Error: fake-error'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.assertEqual(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.macports_backend.package_versions('foo'), expected)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('subprocess.getoutput')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_port_outdated(self, mock_sub):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ expected = ['0.123']
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ mock_sub.return_value = 'Warning: fake-warning \nversion: 0.123'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.assertEqual(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.macports_backend.package_versions('foo'), expected)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('subprocess.getoutput')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_port_error(self, mock_sub):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ mock_sub.return_value = 'bash: port: command not found'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ with self.assertRaises(SystemExit):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.macports_backend.package_versions('foo')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> if __name__ == '__main__':
unittest.main()
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/upt_macports/upt_macports.py b/upt_macports/upt_macports.py
</span>old mode 100644
new mode 100755
<span style='display:block; white-space:pre;color:#808080;'>index 523b567..055b455
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/upt_macports/upt_macports.py
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/upt_macports/upt_macports.py
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -5,6 +5,7 @@ import pkg_resources
</span> import json
import requests
import os
<span style='display:block; white-space:pre;background:#e0ffe0;'>+import subprocess
</span> import sys
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -14,7 +15,7 @@ class MacPortsPackage(object):
</span>
def create_package(self, upt_pkg, output):
self.upt_pkg = upt_pkg
<span style='display:block; white-space:pre;background:#ffe0e0;'>- self.logger.info(f'Hello, creating the package')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info(f'Creating MacPorts package for {self.upt_pkg.name}')
</span> if output is None:
print(self._render_makefile_template())
else:
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -227,20 +228,53 @@ class MacPortsRubyPackage(MacPortsPackage):
</span>
class MacPortsBackend(upt.Backend):
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ def __init__(self):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger = logging.getLogger('upt')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> name = 'macports'
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ pkg_classes = {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'pypi': MacPortsPythonPackage,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'cpan': MacPortsPerlPackage,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'rubygems': MacPortsRubyPackage,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'npm': MacPortsNpmPackage
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span>
def create_package(self, upt_pkg, output=None):
<span style='display:block; white-space:pre;background:#ffe0e0;'>- pkg_classes = {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- 'pypi': MacPortsPythonPackage,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- 'cpan': MacPortsPerlPackage,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- 'rubygems': MacPortsRubyPackage,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- 'npm': MacPortsNpmPackage
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- }
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> try:
<span style='display:block; white-space:pre;background:#ffe0e0;'>- pkg_cls = pkg_classes[upt_pkg.frontend]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.frontend = upt_pkg.frontend
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ pkg_cls = self.pkg_classes[upt_pkg.frontend]
</span> except KeyError:
raise upt.UnhandledFrontendError(self.name, upt_pkg.frontend)
<span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span> packager = pkg_cls()
packager.create_package(upt_pkg, output)
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def package_versions(self, name):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ try:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port_name = self.pkg_classes[
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.frontend]._normalized_macports_folder(name)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ except KeyError:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ raise upt.UnhandledFrontendError(self.name, self.upt_pkg.frontend)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info(f'Checking MacPorts tree for port {port_name}')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ cmd = f'port info --version {port_name}'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port = subprocess.getoutput(cmd)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if port.startswith('Error'):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info(f'{port_name} not found in MacPorts tree')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return []
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ elif port.startswith('version'):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ curr_ver = port.split()[1]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ f'Current MacPorts Version for {port_name} is {curr_ver}')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return [curr_ver]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ elif port.startswith('Warning'):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.warning(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'port definitions are more than two weeks old, '
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'consider updating them by running \'port selfupdate\'.')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ curr_ver = port.split('version: ')[1]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ f'Current MacPorts Version for {port_name} is {curr_ver}')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return [curr_ver]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ else:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sys.exit(f'The command "{cmd}" failed. '
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'Please make sure you have MacPorts installed '
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'and/or your PATH is set-up correctly.')
</span></pre><pre style='margin:0'>
</pre>