简体   繁体   English

如何使用Travis CI测试Pl / Python PostgreSQL程序?

[英]How to test Pl/Python PostgreSQL procedures with Travis CI?

I'm trying to set up CI for some PL/Python PostgreSQL procedures in Travis CI. 我正在尝试为Travis CI中的一些PL / Python PostgreSQL程序设置CI。

I've tried several ways: 我尝试了几种方法:
1) With the legacy infrastructure I've tried to just assume, that PL/Python is already installed, but it had not succeed: 1)对于我曾试图假设的遗留基础设施,已经安装了PL / Python,但它没有成功:

The command "psql -U postgres -c 'CREATE EXTENSION plpythonu;'" exited with 1.
0.01s$ psql -U postgres -d test -c 'CREATE LANGUAGE plpythonu;'
ERROR:  could not access file "$libdir/plpython2": No such file or directory  

2) Have tried to add sudo apt-get update && sudo apt-get -y install postgresql-plpython-9.4 commands in the beginning. 2)尝试在开头添加sudo apt-get update && sudo apt-get -y install postgresql-plpython-9.4命令。 And it was also failed, because this command initiated replacement of PostgresSQL 9.4, that comes already installed in the Travis environment. 它也失败了,因为这个命令开始替换已经安装在Travis环境中的PostgresSQL 9.4。

Travis build. Travis构建。

3) Also tried to use container-based infrastructure with this lines in the config: 3)还试图在配置中使用基于容器的基础设施:

addons:
  postgresql: "9.4"
  apt:
    packages:
      - postgresql-plpython-9.4

No success too. 也没有成功。

What is the good way to test PL/Python procedure in Travis CI? 在Travis CI中测试PL / Python过程的好方法是什么?

I was able to get the python-tempo build working with the following .travis.yml : 我能够使用以下.travis.yml获得python-tempo构建

sudo: required
language: python
before_install:
  - sudo apt-get -qq update
  - sudo /etc/init.d/postgresql stop
  - sudo apt-get install -y postgresql-9.4
  - sudo apt-get install -y postgresql-contrib-9.4 postgresql-plpython-9.4
  - sudo -u postgres createdb test
  - sudo -u postgres createlang plpython2u test
  - sudo pip install jinja2
script:
  - >
      sudo -u postgres psql -d test -c 'CREATE OR REPLACE FUNCTION py_test()
                                   RETURNS void LANGUAGE plpython2u AS $$
                                     import jinja2
                                   $$;'
  - sudo -u postgres psql -d test -c 'SELECT py_test();'

Your legacy configuration attempts had a variety of issues including not stopping the existing PostgreSQL 9.1 instance before installing 9.4 and not specifying the plpython language properly. 您的旧配置尝试存在各种问题,包括在安装9.4之前不停止现有的PostgreSQL 9.1实例,并且未正确指定plpython语言。 I believe some commands were also not being run as the correct user. 我相信一些命令也没有作为正确的用户运行。 All of the issues are resolved by the above configuration. 所有问题都通过上述配置解决。 There may be ways in which this configuration can be improved, but I stopped once I got it working. 可能有一些方法可以改进这种配置,但是一旦我开始工作,我就停止了。

The container-based configuration won't work because postgresql-plpython-9.4 is not currently in the whitelist of pre-approved packages . 基于容器的配置将不起作用,因为postgresql-plpython-9.4当前不在预先批准的软件包白名单中 However, postgresql-plpython-9.5 is, so if you want to migrate to a container-based configuration, you can either try following the package approval process for postgresql-plpython-9.4 or wait for the GA release of PostgreSQL 9.5 and try migrating then. 但是, postgresql-plpython-9.5是,所以如果你想迁移到基于容器的配置,你可以尝试遵循 postgresql-plpython-9.4 的包批准过程或者等待PostgreSQL 9.5GA版本并尝试迁移然后。

Converting my previous comments to an answer now that it has been confirmed... 现在已经确认已将我之前的评论转换为答案...

As documented in the Travis docs , the right way to install this is to update your dependencies at the before_install stage (much like option 2 in your list). 正如Travis文档中所述,正确的安装方法是在before_install阶段更新依赖关系(很像列表中的选项2)。

The only problem appears to be that you did not stop Postgres before the upgrade. 唯一的问题似乎是您在升级之前没有停止Postgres。

I don't know the details exactly, but, if you put the files in the right place, you can call it from the procedure itself 我不完全知道细节,但是,如果你把文件放在正确的位置,你可以从程序本身调用它

import fileName.className

or 要么

import methodName from fileName.className

Edit: I looked it up, just put it in the same directory as the program you're running (cmd, idle, ect.) and call it, or put it in a folder and add the folder name to the code 编辑:我查了一下,只是把它放在你正在运行的程序所在的目录(cmd,idle,ect。)中并调用它,或者将它放在一个文件夹中并将文件夹名称添加到代码中

eg. 例如。

import folder/fileName.ClassName

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM