<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/9694e263ef7df77f812e60272880438ef541f2bb">https://github.com/macports/upt-macports/commit/9694e263ef7df77f812e60272880438ef541f2bb</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 9694e26 Add output function
</span>9694e26 is described below
<span style='display:block; white-space:pre;color:#808000;'>commit 9694e263ef7df77f812e60272880438ef541f2bb
</span>Author: Karan Sheth <karan.sheth@somaiya.edu>
AuthorDate: Thu Jun 13 08:51:47 2019 +0530
<span style='display:block; white-space:pre;color:#404040;'> Add output function
</span>---
upt_macports/tests/test_macports_package.py | 50 ++++++++++++++++++++++++++
upt_macports/upt_macports.py | 54 ++++++++++++++++++++++++++++-
2 files changed, 103 insertions(+), 1 deletion(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/upt_macports/tests/test_macports_package.py b/upt_macports/tests/test_macports_package.py
</span><span style='display:block; white-space:pre;color:#808080;'>index 0938a31..3a92086 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/upt_macports/tests/test_macports_package.py
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/upt_macports/tests/test_macports_package.py
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -73,6 +73,56 @@ class TestMacPortsPackageLicenses(unittest.TestCase):
</span> self.assertEqual(m_stderr.getvalue(), err)
<span style='display:block; white-space:pre;background:#e0ffe0;'>+class TestDirectoryCreation(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.package = MacPortsPackage()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.upt_pkg = upt.Package('foo', '42')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.upt_pkg.frontend = 'pypi'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_create_directories_output_invalid_frontend(self):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.upt_pkg.frontend = 'frontend'
</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.package._create_output_directories(self.package.upt_pkg,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ '/ports/')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('os.makedirs')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch.object(MacPortsPackage, '_normalized_macports_folder',
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ create=True, return_value='py-foo')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_create_directories_output(self, folder_name, m_mkdir):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package._create_output_directories(self.package.upt_pkg,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ '/ports/')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ m_mkdir.assert_called_with('/ports/python/py-foo', exist_ok=True)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('os.makedirs', side_effect=PermissionError)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch.object(MacPortsPackage, '_normalized_macports_folder',
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ create=True, return_value='py-foo')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_create_directories_permission_error(self, folder_name, m_mkdir):
</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.package._create_output_directories(self.package.upt_pkg,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ '/ports/')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+class TestFileCreation(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.package = MacPortsPackage()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.output_dir = '/outdir'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package.upt_pkg = upt.Package('foo', '42')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('builtins.open', new_callable=mock.mock_open)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_portfile_creation(self, m_open):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fn = 'upt_macports.upt_macports.MacPortsPackage._render_makefile_template' # noqa
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ with mock.patch(fn, return_value='Portfile content'):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.package._create_portfile()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ m_open.assert_called_once_with('/outdir/Portfile', 'x',
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ encoding='utf-8')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ m_open().write.assert_called_once_with('Portfile content')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ @mock.patch('builtins.open', side_effect=FileExistsError)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def test_portfile_file_exists(self, m_open):
</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.package._create_portfile()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> class TestMacPortsPackageArchiveType(unittest.TestCase):
def setUp(self):
self.package = MacPortsPackage()
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/upt_macports/upt_macports.py b/upt_macports/upt_macports.py
</span><span style='display:block; white-space:pre;color:#808080;'>index b1c0903..a605727 100644
</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;'>@@ -4,6 +4,8 @@ import jinja2
</span> import pkg_resources
import json
import requests
<span style='display:block; white-space:pre;background:#e0ffe0;'>+import os
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+import sys
</span>
class MacPortsPackage(object):
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -13,7 +15,42 @@ class MacPortsPackage(object):
</span> def create_package(self, upt_pkg, output):
self.upt_pkg = upt_pkg
self.logger.info(f'Hello, creating the package')
<span style='display:block; white-space:pre;background:#ffe0e0;'>- print(self._render_makefile_template())
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if output is None:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ print(self._render_makefile_template())
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ else:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self._create_output_directories(upt_pkg, output)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self._create_portfile()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def _create_output_directories(self, upt_pkg, output_dir):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ """Creates the directory layout required"""
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info(f'Creating the directory structure in {output_dir}')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ upt2macports = {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'cpan': 'perl',
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'pypi': 'python',
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ 'rubygems': 'ruby',
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ try:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port_category = upt2macports[self.upt_pkg.frontend]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ except KeyError:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sys.exit(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ f'Unknown port category for frontend {self.upt_pkg.frontend}')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ folder_name = self._normalized_macports_folder(upt_pkg.name)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.output_dir = os.path.join(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ output_dir, port_category, folder_name)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ try:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ os.makedirs(self.output_dir, exist_ok=True)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info(f'Created {self.output_dir}')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ except PermissionError:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sys.exit(f'Cannot create {self.output_dir}: permission denied.')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def _create_portfile(self):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ self.logger.info('Creating the Portfile')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ try:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ with open(os.path.join(self.output_dir, 'Portfile'), 'x',
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ encoding='utf-8') as f:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ f.write(self._render_makefile_template())
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ except FileExistsError:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sys.exit(f'Cannot create {self.output_dir}/Portfile: already exists.') # noqa
</span>
def _render_makefile_template(self):
env = jinja2.Environment(
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -107,6 +144,11 @@ class MacPortsPythonPackage(MacPortsPackage):
</span> if pypi_name != self.upt_pkg.name.lower():
return pypi_name
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ @staticmethod
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def _normalized_macports_folder(name):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ name = name.lower()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return f'py-{name}'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span>
class MacPortsNpmPackage(MacPortsPackage):
template = 'npm.Portfile'
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -133,6 +175,11 @@ class MacPortsPerlPackage(MacPortsPackage):
</span> def _normalized_macports_name(name):
return name.replace('::', '-')
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ @staticmethod
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def _normalized_macports_folder(name):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ name = name.lower().replace('::', '-')
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return f'p5-{name}'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> def _cpandir(self):
pkg = self.upt_pkg
# If no archives detected then we cannot locate dist file
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -170,6 +217,11 @@ class MacPortsRubyPackage(MacPortsPackage):
</span> def _normalized_macports_name(name):
return name
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ @staticmethod
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ def _normalized_macports_folder(name):
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ name = name.lower()
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return f'rb-{name}'
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span>
class MacPortsBackend(upt.Backend):
name = 'macports'
</pre><pre style='margin:0'>
</pre>