def initialize(self, route): rpath = self.request.path[len(route):].strip('/') parts = rpath.split('/', 1) self.cname = parts[0] + os.sep self.added = '' if len(parts) == 1: with self._plugin_lock: if self._cname_valid( parts[0]) and parts[0] not in self._plugin_map: url = find_docs_url(parts[0], build_if_needed=False) if self.cname.startswith('openmdao.'): if (url.endswith("egg")): # url points to docs in a release version, so use docs packaged with openmdao.main root = os.path.join( os.path.dirname(openmdao.main.__file__), "docs") else: # url points to docs in a developer version, so use locally built docs root = os.path.join( get_ancestor_dir(sys.executable, 3), 'docs', '_build', 'html') if url.startswith('file://'): url = url[7:] self.added = os.path.dirname(url)[len(root) + 1:] else: root = os.path.dirname(url) default = os.path.basename(url) self._plugin_map[parts[0]] = (root, default, self.added) root, default, self.added = self._plugin_map[parts[0]] super(PluginDocsHandler, self).initialize(root, default)
def initialize(self, route): rpath = self.request.path[len(route):].strip('/') parts = rpath.split('/', 1) self.cname = parts[0] + os.sep self.added = '' if len(parts) == 1: with self._plugin_lock: if self._cname_valid( parts[0]) and parts[0] not in self._plugin_map: url = find_docs_url(parts[0], build_if_needed=False) if self.cname.startswith('openmdao.'): root = os.path.join( get_ancestor_dir(sys.executable, 3), 'docs', '_build', 'html') if url.startswith('file://'): url = url[7:] self.added = os.path.dirname(url)[len(root) + 1:] else: root = os.path.dirname(url) default = os.path.basename(url) self._plugin_map[parts[0]] = (root, default, self.added) root, default, self.added = self._plugin_map[parts[0]] super(PluginDocsHandler, self).initialize(root, default)
def initialize(self, route): rpath = self.request.path[len(route) :].strip("/") parts = rpath.split("/", 1) self.cname = parts[0] + os.sep self.added = "" if len(parts) == 1: with self._plugin_lock: if self._cname_valid(parts[0]) and parts[0] not in self._plugin_map: url = find_docs_url(parts[0], build_if_needed=False) # Remove "file://" from URL url = url[7:] if self.cname.startswith("openmdao."): if self.regex.search(url): # url points to docs in a release version, so use docs packaged with openmdao.main root = os.path.join(os.path.dirname(openmdao.main.__file__), "docs") else: # url points to docs in a developer version, so use locally built docs root = os.path.join(get_ancestor_dir(sys.executable, 3), "docs", "_build", "html") self.added = os.path.dirname(url)[len(root) + 1 :] else: root = os.path.dirname(url) default = os.path.basename(url) self._plugin_map[parts[0]] = (root, default, self.added) root, default, self.added = self._plugin_map[parts[0]] super(PluginDocsHandler, self).initialize(root, default)
def initialize(self, route): rpath = self.request.path[len(route):].strip('/') parts = rpath.split('/', 1) self.cname = parts[0] + os.sep self.added = '' if len(parts) == 1: with self._plugin_lock: if self._cname_valid(parts[0]) and parts[0] not in self._plugin_map: url = find_docs_url(parts[0], build_if_needed=False) if self.cname.startswith('openmdao.'): if(url.endswith("egg")): # url points to docs in a release version, so use docs packaged with openmdao.main root = os.path.join(os.path.dirname(openmdao.main.__file__), "docs") else: # url points to docs in a developer version, so use locally built docs root = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs', '_build', 'html') if url.startswith('file://'): url = url[7:] self.added = os.path.dirname(url)[len(root) + 1:] else: root = os.path.dirname(url) default = os.path.basename(url) self._plugin_map[parts[0]] = (root, default, self.added) root, default, self.added = self._plugin_map[parts[0]] super(PluginDocsHandler, self).initialize(root, default)
def test_docs(self): argv = ['docs', 'no-such-plugin'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) code = 'find_docs_url(options.plugin_dist_name)' assert_raises(self, code, globals(), locals(), RuntimeError, "Can't locate package/module 'no-such-plugin'") argv = ['docs', 'subprocess'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) url = find_docs_url(options.plugin_dist_name) expected = os.path.join(os.path.dirname(sys.modules['subprocess'].__file__), 'sphinx_build', 'html', 'index.html') self.assertEqual(url, expected)
def test_docs(self): argv = ['docs', 'no-such-plugin'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) code = 'find_docs_url(options.plugin_dist_name)' assert_raises(self, code, globals(), locals(), RuntimeError, "Can't locate package/module 'no-such-plugin'") argv = ['docs', 'subprocess'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) url = find_docs_url(options.plugin_dist_name) expected = os.path.join( os.path.dirname(sys.modules['subprocess'].__file__), 'sphinx_build', 'html', 'index.html') self.assertEqual(url, expected)
def initialize(self, route): rpath = self.request.path[len(route):].strip('/') parts = rpath.split('/',1) self.cname = parts[0] + os.sep self.added = '' if len(parts) == 1: with self._plugin_lock: if self._cname_valid(parts[0]) and parts[0] not in self._plugin_map: url = find_docs_url(parts[0], build_if_needed=False) if self.cname.startswith('openmdao.'): root = os.path.join(get_ancestor_dir(sys.executable, 3), 'docs', '_build', 'html') if url.startswith('file://'): url = url[7:] self.added = os.path.dirname(url)[len(root)+1:] else: root = os.path.dirname(url) default = os.path.basename(url) self._plugin_map[parts[0]] = (root, default, self.added) root, default, self.added = self._plugin_map[parts[0]] super(PluginDocsHandler, self).initialize(root, default)
def test_basic(self): logging.debug('') logging.debug('test_basic') # Just run through a complete cycle. orig_dir = os.getcwd() orig_stdout = sys.stdout orig_stderr = sys.stderr # Quickstart. logging.debug('') logging.debug('quickstart') os.chdir(self.tdir) try: argv = ['quickstart', 'foobar'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_quickstart(parser, options, args) self.assertEqual(retval, 0) fandd = find_files(self.tdir, showdirs=True) self.assertEqual(set([os.path.basename(f) for f in fandd]), set(['foobar', 'src', 'docs', 'setup.cfg', 'setup.py', 'MANIFEST.in', '__init__.py', 'conf.py', 'usage.rst', 'index.rst', 'srcdocs.rst', 'pkgdocs.rst', 'foobar.py', 'README.txt', 'test','test_foobar.py'])) finally: os.chdir(orig_dir) # Makedist. logging.debug('') logging.debug('makedist') sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() logdata = '' os.chdir(os.path.join(self.tdir, 'foobar')) try: argv = ['makedist'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_makedist(parser, options, args, capture='makedist.out') with open('makedist.out', 'r') as inp: logdata = inp.read() self.assertEqual(retval, 0) if sys.platform == 'win32': self.assertTrue(os.path.exists('foobar-0.1.zip')) else: self.assertTrue(os.path.exists('foobar-0.1.tar.gz')) finally: captured_stdout = sys.stdout.getvalue() captured_stderr = sys.stderr.getvalue() sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) logging.debug('captured stdout:') logging.debug(captured_stdout) logging.debug('captured stderr:') logging.debug(captured_stderr) logging.debug('captured subprocess output:') logging.debug(logdata) # Existing distribution error. logging.debug('') logging.debug('makedist error') sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() os.chdir(os.path.join(self.tdir, 'foobar')) try: argv = ['makedist'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_makedist(parser, options, args, capture='makedist.out') with open('makedist.out', 'r') as inp: logdata = inp.read() self.assertEqual(retval, -1) finally: captured_stdout = sys.stdout.getvalue() captured_stderr = sys.stderr.getvalue() sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) logging.debug('captured stdout:') logging.debug(captured_stdout) logging.debug('captured stderr:') logging.debug(captured_stderr) logging.debug('captured subprocess output:') logging.debug(logdata) self.assertTrue('already exists' in captured_stderr) # Install logging.debug('') logging.debug('install') sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() logdata = '' os.chdir(self.tdir) try: argv = ['install', 'foobar'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_install(parser, options, args, capture='install.out') with open('install.out', 'r') as inp: logdata = inp.read() self.assertEqual(retval, 0) finally: captured_stdout = sys.stdout.getvalue() captured_stderr = sys.stderr.getvalue() sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) logging.debug('captured stdout:') logging.debug(captured_stdout) logging.debug('captured stderr:') logging.debug(captured_stderr) logging.debug('captured subprocess output:') logging.debug(logdata) try: # List in subprocess to grab updated package environment. logging.debug('') logging.debug('list') os.chdir(self.tdir) stdout = open('list.out', 'w') try: check_call(('plugin', 'list', '-g', 'driver', '-g', 'component', '--external'), stdout=stdout, stderr=STDOUT) finally: stdout.close() with open('list.out', 'r') as inp: captured_stdout = inp.read() os.remove('list.out') os.chdir(orig_dir) logging.debug('captured subprocess output:') logging.debug(captured_stdout) self.assertTrue('foobar.foobar.Foobar' in captured_stdout) # Docs. logging.debug('') logging.debug('docs') argv = ['docs', 'foobar'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) url = find_docs_url(options.plugin_dist_name) expected = os.path.join(self.tdir, 'foobar', 'src', 'foobar', 'sphinx_build', 'html', 'index.html') self.assertEqual(os.path.realpath(url), os.path.realpath(expected)) finally: # Uninstall logging.debug('') logging.debug('uninstall') with open('pip.in', 'w') as out: out.write('y\n') stdin = open('pip.in', 'r') stdout = open('pip.out', 'w') # On EC2 Windows, 'pip' generates an absurdly long temp directory # name, apparently to allow backing-out of the uninstall. # The name is so long Windows can't handle it. So we try to # avoid that by indirectly influencing mkdtemp(). env = os.environ.copy() env['TMP'] = os.path.expanduser('~') try: check_call(('pip', 'uninstall', 'foobar'), env=env, stdin=stdin, stdout=stdout, stderr=STDOUT) finally: stdin.close() stdout.close() with open('pip.out', 'r') as inp: captured_stdout = inp.read() os.remove('pip.in') os.remove('pip.out') logging.debug('captured stdout:') logging.debug(captured_stdout) # Show removed. logging.debug('') logging.debug('list removed') os.chdir(self.tdir) stdout = open('list.out', 'w') try: check_call(('plugin', 'list', '--external'), stdout=stdout, stderr=STDOUT) finally: stdout.close() with open('list.out', 'r') as inp: captured_stdout = inp.read() os.remove('list.out') os.chdir(orig_dir) logging.debug('captured subprocess output:') logging.debug(captured_stdout) self.assertFalse('foobar.foobar.Foobar' in captured_stdout)
def test_basic(self): logging.debug('') logging.debug('test_basic') # Just run through a complete cycle. orig_dir = os.getcwd() orig_stdout = sys.stdout orig_stderr = sys.stderr # Quickstart. logging.debug('') logging.debug('quickstart') os.chdir(self.tdir) try: argv = ['quickstart', 'foobar'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_quickstart(parser, options, args) self.assertEqual(retval, 0) fandd = find_files(self.tdir, showdirs=True) self.assertEqual( set([os.path.basename(f) for f in fandd]), set([ 'foobar', 'src', 'docs', 'setup.cfg', 'setup.py', 'MANIFEST.in', '__init__.py', 'conf.py', 'usage.rst', 'index.rst', 'srcdocs.rst', 'pkgdocs.rst', 'foobar.py', 'README.txt', 'test', 'test_foobar.py' ])) finally: os.chdir(orig_dir) # Makedist. logging.debug('') logging.debug('makedist') sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() logdata = '' os.chdir(os.path.join(self.tdir, 'foobar')) try: argv = ['makedist'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_makedist(parser, options, args, capture='makedist.out') with open('makedist.out', 'r') as inp: logdata = inp.read() self.assertEqual(retval, 0) if sys.platform == 'win32': self.assertTrue(os.path.exists('foobar-0.1.zip')) else: self.assertTrue(os.path.exists('foobar-0.1.tar.gz')) finally: captured_stdout = sys.stdout.getvalue() captured_stderr = sys.stderr.getvalue() sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) logging.debug('captured stdout:') logging.debug(captured_stdout) logging.debug('captured stderr:') logging.debug(captured_stderr) logging.debug('captured subprocess output:') logging.debug(logdata) # Existing distribution error. logging.debug('') logging.debug('makedist error') sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() os.chdir(os.path.join(self.tdir, 'foobar')) try: argv = ['makedist'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_makedist(parser, options, args, capture='makedist.out') with open('makedist.out', 'r') as inp: logdata = inp.read() self.assertEqual(retval, -1) finally: captured_stdout = sys.stdout.getvalue() captured_stderr = sys.stderr.getvalue() sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) logging.debug('captured stdout:') logging.debug(captured_stdout) logging.debug('captured stderr:') logging.debug(captured_stderr) logging.debug('captured subprocess output:') logging.debug(logdata) self.assertTrue('already exists' in captured_stderr) # Install logging.debug('') logging.debug('install') sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() logdata = '' os.chdir(self.tdir) try: argv = ['install', 'foobar'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_install(parser, options, args, capture='install.out') with open('install.out', 'r') as inp: logdata = inp.read() self.assertEqual(retval, 0) finally: captured_stdout = sys.stdout.getvalue() captured_stderr = sys.stderr.getvalue() sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) logging.debug('captured stdout:') logging.debug(captured_stdout) logging.debug('captured stderr:') logging.debug(captured_stderr) logging.debug('captured subprocess output:') logging.debug(logdata) try: # List in subprocess to grab updated package environment. logging.debug('') logging.debug('list') os.chdir(self.tdir) stdout = open('list.out', 'w') try: check_call(('plugin', 'list', '-g', 'driver', '-g', 'component', '--external'), stdout=stdout, stderr=STDOUT) finally: stdout.close() with open('list.out', 'r') as inp: captured_stdout = inp.read() os.remove('list.out') os.chdir(orig_dir) logging.debug('captured subprocess output:') logging.debug(captured_stdout) self.assertTrue('foobar.foobar.Foobar' in captured_stdout) # Docs. logging.debug('') logging.debug('docs') argv = ['docs', 'foobar'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) url = find_docs_url(options.plugin_dist_name) # Strip off the file protocol header url = url.replace('file://', '') expected = os.path.join(self.tdir, 'foobar', 'src', 'foobar', 'sphinx_build', 'html', 'index.html') self.assertEqual(os.path.realpath(url), os.path.realpath(expected)) finally: # Uninstall logging.debug('') logging.debug('uninstall') pip_in = os.path.join(self.tdir, 'pip.in') pip_out = os.path.join(self.tdir, 'pip.out') with open(pip_in, 'w') as out: out.write('y\n') stdin = open(pip_in, 'r') stdout = open(pip_out, 'w') # On EC2 Windows, 'pip' generates an absurdly long temp directory # name, apparently to allow backing-out of the uninstall. # The name is so long Windows can't handle it. So we try to # avoid that by indirectly influencing mkdtemp(). env = os.environ.copy() env['TMP'] = os.path.expanduser('~') try: # the following few lines are to prevent the system level pip # from being used instead of the local virtualenv version. pipexe = 'pip-%d.%d' % (sys.version_info[0], sys.version_info[1]) pipexe = find_in_path(pipexe) if pipexe is None: pipexe = 'pip' check_call((pipexe, 'uninstall', 'foobar'), env=env, stdin=stdin, stdout=stdout, stderr=STDOUT) finally: stdin.close() stdout.close() with open(pip_out, 'r') as inp: captured_stdout = inp.read() logging.debug('captured stdout:') logging.debug(captured_stdout) # Show removed. logging.debug('') logging.debug('list removed') os.chdir(self.tdir) stdout = open('list.out', 'w') try: check_call(('plugin', 'list', '--external'), stdout=stdout, stderr=STDOUT) finally: stdout.close() with open('list.out', 'r') as inp: captured_stdout = inp.read() os.remove('list.out') os.chdir(orig_dir) logging.debug('captured subprocess output:') logging.debug(captured_stdout) self.assertFalse('foobar.foobar.Foobar' in captured_stdout)
def test_basic(self): #Testing in pythonxy fails due to the pip version if sys.platform == 'win32': pipvers = pip.__version__ if pipvers.__contains__("xy"): raise nose.SkipTest("PythonXY's pip name is non-standard 'pip-2.7xy' and causes test failure when 'pip-2.7' is searched for and not found.") logging.debug('') logging.debug('test_basic') # Just run through a complete cycle. orig_dir = os.getcwd() orig_stdout = sys.stdout orig_stderr = sys.stderr # Quickstart. logging.debug('') logging.debug('quickstart') os.chdir(self.tdir) try: argv = ['quickstart', 'foobar'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_quickstart(parser, options, args) self.assertEqual(retval, 0) fandd = find_files(self.tdir, showdirs=True) self.assertEqual(set([os.path.basename(f) for f in fandd]), set(['foobar', 'src', 'docs', 'setup.cfg', 'setup.py', 'MANIFEST.in', '__init__.py', 'conf.py', 'usage.rst', 'index.rst', 'srcdocs.rst', 'pkgdocs.rst', 'foobar.py', 'README.txt', '_static', 'test', 'test_foobar.py'])) finally: os.chdir(orig_dir) # Makedist. logging.debug('') logging.debug('makedist') sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() logdata = '' os.chdir(os.path.join(self.tdir, 'foobar')) try: argv = ['makedist'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_makedist(parser, options, args, capture='makedist.out') with open('makedist.out', 'r') as inp: logdata = inp.read() self.assertEqual(retval, 0) if sys.platform == 'win32': self.assertTrue(os.path.exists('foobar-0.1.zip')) else: self.assertTrue(os.path.exists('foobar-0.1.tar.gz')) finally: captured_stdout = sys.stdout.getvalue() captured_stderr = sys.stderr.getvalue() sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) logging.debug('captured stdout:') logging.debug(captured_stdout) logging.debug('captured stderr:') logging.debug(captured_stderr) logging.debug('captured subprocess output:') logging.debug(logdata) # Overwrite existing distribution. logging.debug('') logging.debug('makedist overwrite') sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() os.chdir(os.path.join(self.tdir, 'foobar')) try: argv = ['makedist'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_makedist(parser, options, args, capture='makedist.out') with open('makedist.out', 'r') as inp: logdata = inp.read() self.assertEqual(retval, 0) finally: captured_stdout = sys.stdout.getvalue() captured_stderr = sys.stderr.getvalue() sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) logging.debug('captured stdout:') logging.debug(captured_stdout) logging.debug('captured stderr:') logging.debug(captured_stderr) logging.debug('captured subprocess output:') logging.debug(logdata) # Install logging.debug('') logging.debug('install') sys.stdout = cStringIO.StringIO() sys.stderr = cStringIO.StringIO() logdata = '' os.chdir(self.tdir) try: argv = ['install', 'foobar'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) retval = plugin_install(parser, options, args, capture='install.out') with open('install.out', 'r') as inp: logdata = inp.read() self.assertEqual(retval, 0) finally: captured_stdout = sys.stdout.getvalue() captured_stderr = sys.stderr.getvalue() sys.stdout = orig_stdout sys.stderr = orig_stderr os.chdir(orig_dir) logging.debug('captured stdout:') logging.debug(captured_stdout) logging.debug('captured stderr:') logging.debug(captured_stderr) logging.debug('captured subprocess output:') logging.debug(logdata) try: # List in subprocess to grab updated package environment. logging.debug('') logging.debug('list') os.chdir(self.tdir) stdout = open('list.out', 'w') try: check_call(('plugin', 'list', '-g', 'driver', '-g', 'component', '--external'), stdout=stdout, stderr=STDOUT) finally: stdout.close() with open('list.out', 'r') as inp: captured_stdout = inp.read() os.remove('list.out') os.chdir(orig_dir) logging.debug('captured subprocess output:') logging.debug(captured_stdout) self.assertTrue('foobar.foobar.Foobar' in captured_stdout) # Docs. logging.debug('') logging.debug('docs') argv = ['docs', 'foobar'] parser = _get_plugin_parser() options, args = parser.parse_known_args(argv) url = find_docs_url(options.plugin_dist_name) # Strip off the file protocol header url = url.replace('file://', '') expected = os.path.join(self.tdir, 'foobar', 'src', 'foobar', 'sphinx_build', 'html', 'index.html') self.assertEqual(os.path.realpath(url), os.path.realpath(expected)) finally: # Uninstall logging.debug('') logging.debug('uninstall') pip_in = os.path.join(self.tdir, 'pip.in') pip_out = os.path.join(self.tdir, 'pip.out') with open(pip_in, 'w') as out: out.write('y\n') stdin = open(pip_in, 'r') stdout = open(pip_out, 'w') # On EC2 Windows, 'pip' generates an absurdly long temp directory # name, apparently to allow backing-out of the uninstall. # The name is so long Windows can't handle it. So we try to # avoid that by indirectly influencing mkdtemp(). env = os.environ.copy() env['TMP'] = os.path.expanduser('~') try: # the following few lines are to prevent the system level pip # from being used instead of the local virtualenv version. pipexe = 'pip' pipexe = find_in_path(pipexe) if pipexe is None: pipexe = 'pip' check_call((pipexe, 'uninstall', 'foobar'), env=env, stdin=stdin, stdout=stdout, stderr=STDOUT) finally: stdin.close() stdout.close() with open(pip_out, 'r') as inp: captured_stdout = inp.read() logging.debug('captured stdout:') logging.debug(captured_stdout) # Show removed. logging.debug('') logging.debug('list removed') os.chdir(self.tdir) stdout = open('list.out', 'w') try: check_call(('plugin', 'list', '--external'), stdout=stdout, stderr=STDOUT) finally: stdout.close() with open('list.out', 'r') as inp: captured_stdout = inp.read() os.remove('list.out') os.chdir(orig_dir) logging.debug('captured subprocess output:') logging.debug(captured_stdout) self.assertFalse('foobar.foobar.Foobar' in captured_stdout)