python环境变量解析器库

envio的Python项目详细描述


环境

python环境变量解析器库。

主要是作为基本包创建工作方式的参考创建的。许多 类似的项目存在;这个项目的目标是最基本的。 实现可能,并确定样板文件的最小数量 创建要提交的包。

安装

运行pip install envio

用法

基本用法

importenvio# Fetch the envirnment variable MYARG and use value 'yay' if not foundMYARG=envio.get_var('MYARG',default='yay')# If a default is not specified, then an exception will be raised if the# environment variable does not exist. This is how we can specify required# variables.MYARG=envio.get_var('MYARG')# MYARG is required

环境变量也可以强制为多种不同类型

# coerce required variable MYINT into an integerMYINT=envio.get_var('MYINT',var_type=int)MYFLOAT=envio.get_var('MYFLOAT',var_type=float)# Acceptable inputs for boolean values include:# case insensitive versions of 'true' and 'false'# case insensitive words 'on' and 'off'# '1' and '0'# case insensitive letters 't' and 'f'MYBOOL=envio.get_var('MYBOOL',var_type=bool)# Dictionaries are also supported but require the environment variable to be# a valid json string. Below is an example of how to specify a simple dict# through a json string.MYDICT=envio.get_var('MYDICT',var_type='json',default='{"hello": "world"}')

还可以使用many=true参数将变量强制到列表中。

# e.g MYLIST <-- '1,hello, 7, 12.0'# the following will parse as# MYLIST = ['1', 'hello', '7', '12.0']MYLIST=envio.get_var('MYLIST',many=True)# list parsing can be combined with type coercion. This will enforce that# every member of the list be parsed as 'var_type'.MYINTS=envio.get_var('MYINTS',var_type=int,many=True)# The delimmiter used for parsing lists defaults to a comma, but it can be# changed with an optional 'delimmiter' param.MYINTS=envio.get_var('MYINTS',var_type=int,many=True,delimmiter='||',default='1||2||3')# using 'var_type'=json also allows the parsing of integers, lists of integers# and the like. It allows mixed types in lists and should be used carefully.# the example below will produce [1, 2, '3']MYLIST=envio.get_var('MYLIST',var_type='json',default='[1, 2, "3"]')

默认值只能是string值。这样做是为了 我们选择的默认值必须经过相同的解析器 作为环境变量。这避免了一类错误,其中 可以选择不兼容的默认值。例如,期望整数,但默认值为 一个布尔值。

# this is the correct way to specify a default for a list of integersMYINTS=envio.get_var('MYINTS',var_type=int,many=True,default='1,2,3')

开发

您将希望在某个地方克隆包,并在您的环境中提供pipenv或virtualenv。

此项目中包含一个pipfile。主要是用包裹 要运行tween-用于向pypi提交包的实用程序。也可以是 用于在本地安装此项目的发行版。

所有命令都假定工作目录是repo根目录。

# install a virtual env and the pipfile requirements.
pipenv install
# activate the virtualenv in the shell. All commands should be run after this# activation
pipenv shell

# builds can be generated like so:
python setup.py sdist bdist_wheel

# builds can then be submitted to pypi using twine like so:# upload to test pypi
twine upload --repository-url  https://test.pypi.org/legacy/ dist/*

# upload to the actual pypi servers.
twine upload --repository-url  https://upload.pypi.org/legacy/ dist/*

# tests can be run using setup.py as well
python setup.py test

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Spring、JPA和hibernate的java问题   如何将JMC(Java任务控制)连接到ubuntu中的远程JVM?   java如何将eventListener的结果存储为对象?   java在安卓中,点击一个按钮,我如何停止发送循环中发送的消息   java打开活动中的电子邮件   使用velocity模板打印JasperReports   java无法在自定义信息窗口上拨号   java如何在jsonb postgresql中查询并转换为谓词JPA   java更好地理解J2EE环境中的异常和日志记录   java打印多个文件   java无法使用API v2 Foreman 1.7.1创建主机   HTML单一提交类型按钮在java中不起作用   java调用静态方法的实例   ViewPage中替换片段的java问题   C++在java中创建数组(2D)而不初始化内部数组   java如何在NetBeans中同时更改变量名称的多个实例?   如何完成这个关于集合的java程序   java如何选择使用selenium从下拉菜单动态生成的元素?