├── .coveragerc ├── .editorconfig ├── .gitattributes ├── .gitignore ├── .travis.yml ├── LICENSE ├── MANIFEST.in ├── README.rst ├── docs ├── Makefile ├── make.bat └── source │ ├── _static │ └── logo.png │ ├── api.rst │ ├── conf.py │ ├── features.rst │ ├── index.rst │ ├── install.rst │ └── usage.rst ├── requirements.in ├── requirements.txt ├── requirements ├── build │ ├── main.txt │ ├── qa.txt │ └── test.txt └── src │ ├── main.in │ ├── qa.in │ └── test.in ├── setup.cfg ├── setup.py ├── src └── biome │ └── __init__.py ├── tests └── test_biome.py └── tox.ini /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | source = src/biome 3 | 4 | [report] 5 | exclude_lines = 6 | pragma: no cover 7 | def __repr__ 8 | raise AssertionError 9 | raise NotImplementedError 10 | if __name__ == .__main__.: 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | end_of_line = lf 5 | indent_style = space 6 | insert_final_newline = true 7 | 8 | [*.py] 9 | charset = utf-8 10 | indent_size = 4 11 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | _version.py export-subst 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .reqwire.lock 2 | .python-version 3 | 4 | # Byte-compiled / optimized / DLL files 5 | __pycache__/ 6 | *.py[cod] 7 | *$py.class 8 | 9 | # C extensions 10 | *.so 11 | 12 | # Distribution / packaging 13 | .Python 14 | env/ 15 | ./build/ 16 | docs/build/ 17 | develop-eggs/ 18 | dist/ 19 | downloads/ 20 | eggs/ 21 | .eggs/ 22 | lib/ 23 | lib64/ 24 | parts/ 25 | sdist/ 26 | var/ 27 | *.egg-info/ 28 | .installed.cfg 29 | *.egg 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *,cover 50 | .hypothesis/ 51 | 52 | # Translations 53 | *.mo 54 | *.pot 55 | 56 | # Django stuff: 57 | *.log 58 | 59 | # Sphinx documentation 60 | docs/_build/ 61 | 62 | # PyBuilder 63 | target/ 64 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: python 3 | after_success: 4 | - coveralls 5 | python: 6 | - "2.7" 7 | - "3.3" 8 | - "3.4" 9 | - "3.5" 10 | install: pip install python-coveralls tox-travis 11 | script: tox 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, David Gidwani 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include versioneer.py 2 | include _version.py 3 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | biome 2 | ~~~~~ 3 | 4 | .. image:: https://travis-ci.org/darvid/biome.svg?branch=master 5 | :target: https://travis-ci.org/darvid/biome 6 | 7 | .. image:: https://img.shields.io/pypi/v/biome.svg 8 | :target: https://pypi.python.org/pypi/biome/ 9 | 10 | .. image:: https://img.shields.io/pypi/pyversions/biome.svg 11 | :target: https://pypi.python.org/pypi/biome/ 12 | 13 | .. image:: https://img.shields.io/pypi/status/biome.svg 14 | :target: https://pypi.python.org/pypi/biome/ 15 | 16 | Provides painless access to namespaced environment variables. 17 | 18 | Links 19 | ----- 20 | 21 | * `Source code `_ 22 | * `Documentation `_ 23 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " applehelp to make an Apple Help Book" 34 | @echo " devhelp to make HTML files and a Devhelp project" 35 | @echo " epub to make an epub" 36 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 37 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 38 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 39 | @echo " text to make text files" 40 | @echo " man to make manual pages" 41 | @echo " texinfo to make Texinfo files" 42 | @echo " info to make Texinfo files and run them through makeinfo" 43 | @echo " gettext to make PO message catalogs" 44 | @echo " changes to make an overview of all changed/added/deprecated items" 45 | @echo " xml to make Docutils-native XML files" 46 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 47 | @echo " linkcheck to check all external links for integrity" 48 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 49 | @echo " coverage to run coverage check of the documentation (if enabled)" 50 | 51 | clean: 52 | rm -rf $(BUILDDIR)/* 53 | 54 | html: 55 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 56 | @echo 57 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 58 | 59 | dirhtml: 60 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 61 | @echo 62 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 63 | 64 | singlehtml: 65 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 66 | @echo 67 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 68 | 69 | pickle: 70 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 71 | @echo 72 | @echo "Build finished; now you can process the pickle files." 73 | 74 | json: 75 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 76 | @echo 77 | @echo "Build finished; now you can process the JSON files." 78 | 79 | htmlhelp: 80 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 81 | @echo 82 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 83 | ".hhp project file in $(BUILDDIR)/htmlhelp." 84 | 85 | qthelp: 86 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 87 | @echo 88 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 89 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 90 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/biome.qhcp" 91 | @echo "To view the help file:" 92 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/biome.qhc" 93 | 94 | applehelp: 95 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp 96 | @echo 97 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp." 98 | @echo "N.B. You won't be able to view it unless you put it in" \ 99 | "~/Library/Documentation/Help or install it in your application" \ 100 | "bundle." 101 | 102 | devhelp: 103 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 104 | @echo 105 | @echo "Build finished." 106 | @echo "To view the help file:" 107 | @echo "# mkdir -p $$HOME/.local/share/devhelp/biome" 108 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/biome" 109 | @echo "# devhelp" 110 | 111 | epub: 112 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 113 | @echo 114 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 115 | 116 | latex: 117 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 118 | @echo 119 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 120 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 121 | "(use \`make latexpdf' here to do that automatically)." 122 | 123 | latexpdf: 124 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 125 | @echo "Running LaTeX files through pdflatex..." 126 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 127 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 128 | 129 | latexpdfja: 130 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 131 | @echo "Running LaTeX files through platex and dvipdfmx..." 132 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 133 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 134 | 135 | text: 136 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 137 | @echo 138 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 139 | 140 | man: 141 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 142 | @echo 143 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 144 | 145 | texinfo: 146 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 147 | @echo 148 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 149 | @echo "Run \`make' in that directory to run these through makeinfo" \ 150 | "(use \`make info' here to do that automatically)." 151 | 152 | info: 153 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 154 | @echo "Running Texinfo files through makeinfo..." 155 | make -C $(BUILDDIR)/texinfo info 156 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 157 | 158 | gettext: 159 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 160 | @echo 161 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 162 | 163 | changes: 164 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 165 | @echo 166 | @echo "The overview file is in $(BUILDDIR)/changes." 167 | 168 | linkcheck: 169 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 170 | @echo 171 | @echo "Link check complete; look for any errors in the above output " \ 172 | "or in $(BUILDDIR)/linkcheck/output.txt." 173 | 174 | doctest: 175 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 176 | @echo "Testing of doctests in the sources finished, look at the " \ 177 | "results in $(BUILDDIR)/doctest/output.txt." 178 | 179 | coverage: 180 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage 181 | @echo "Testing of coverage in the sources finished, look at the " \ 182 | "results in $(BUILDDIR)/coverage/python.txt." 183 | 184 | xml: 185 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 186 | @echo 187 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 188 | 189 | pseudoxml: 190 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 191 | @echo 192 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 193 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source 10 | set I18NSPHINXOPTS=%SPHINXOPTS% source 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | echo. coverage to run coverage check of the documentation if enabled 41 | goto end 42 | ) 43 | 44 | if "%1" == "clean" ( 45 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 46 | del /q /s %BUILDDIR%\* 47 | goto end 48 | ) 49 | 50 | 51 | REM Check if sphinx-build is available and fallback to Python version if any 52 | %SPHINXBUILD% 2> nul 53 | if errorlevel 9009 goto sphinx_python 54 | goto sphinx_ok 55 | 56 | :sphinx_python 57 | 58 | set SPHINXBUILD=python -m sphinx.__init__ 59 | %SPHINXBUILD% 2> nul 60 | if errorlevel 9009 ( 61 | echo. 62 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 63 | echo.installed, then set the SPHINXBUILD environment variable to point 64 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 65 | echo.may add the Sphinx directory to PATH. 66 | echo. 67 | echo.If you don't have Sphinx installed, grab it from 68 | echo.http://sphinx-doc.org/ 69 | exit /b 1 70 | ) 71 | 72 | :sphinx_ok 73 | 74 | 75 | if "%1" == "html" ( 76 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 77 | if errorlevel 1 exit /b 1 78 | echo. 79 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 80 | goto end 81 | ) 82 | 83 | if "%1" == "dirhtml" ( 84 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 85 | if errorlevel 1 exit /b 1 86 | echo. 87 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 88 | goto end 89 | ) 90 | 91 | if "%1" == "singlehtml" ( 92 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 93 | if errorlevel 1 exit /b 1 94 | echo. 95 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 96 | goto end 97 | ) 98 | 99 | if "%1" == "pickle" ( 100 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 101 | if errorlevel 1 exit /b 1 102 | echo. 103 | echo.Build finished; now you can process the pickle files. 104 | goto end 105 | ) 106 | 107 | if "%1" == "json" ( 108 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 109 | if errorlevel 1 exit /b 1 110 | echo. 111 | echo.Build finished; now you can process the JSON files. 112 | goto end 113 | ) 114 | 115 | if "%1" == "htmlhelp" ( 116 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 117 | if errorlevel 1 exit /b 1 118 | echo. 119 | echo.Build finished; now you can run HTML Help Workshop with the ^ 120 | .hhp project file in %BUILDDIR%/htmlhelp. 121 | goto end 122 | ) 123 | 124 | if "%1" == "qthelp" ( 125 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 129 | .qhcp project file in %BUILDDIR%/qthelp, like this: 130 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\biome.qhcp 131 | echo.To view the help file: 132 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\biome.ghc 133 | goto end 134 | ) 135 | 136 | if "%1" == "devhelp" ( 137 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 138 | if errorlevel 1 exit /b 1 139 | echo. 140 | echo.Build finished. 141 | goto end 142 | ) 143 | 144 | if "%1" == "epub" ( 145 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 146 | if errorlevel 1 exit /b 1 147 | echo. 148 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 149 | goto end 150 | ) 151 | 152 | if "%1" == "latex" ( 153 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 154 | if errorlevel 1 exit /b 1 155 | echo. 156 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 157 | goto end 158 | ) 159 | 160 | if "%1" == "latexpdf" ( 161 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 162 | cd %BUILDDIR%/latex 163 | make all-pdf 164 | cd %~dp0 165 | echo. 166 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 167 | goto end 168 | ) 169 | 170 | if "%1" == "latexpdfja" ( 171 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 172 | cd %BUILDDIR%/latex 173 | make all-pdf-ja 174 | cd %~dp0 175 | echo. 176 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 177 | goto end 178 | ) 179 | 180 | if "%1" == "text" ( 181 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 182 | if errorlevel 1 exit /b 1 183 | echo. 184 | echo.Build finished. The text files are in %BUILDDIR%/text. 185 | goto end 186 | ) 187 | 188 | if "%1" == "man" ( 189 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 190 | if errorlevel 1 exit /b 1 191 | echo. 192 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 193 | goto end 194 | ) 195 | 196 | if "%1" == "texinfo" ( 197 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 198 | if errorlevel 1 exit /b 1 199 | echo. 200 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 201 | goto end 202 | ) 203 | 204 | if "%1" == "gettext" ( 205 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 206 | if errorlevel 1 exit /b 1 207 | echo. 208 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 209 | goto end 210 | ) 211 | 212 | if "%1" == "changes" ( 213 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 214 | if errorlevel 1 exit /b 1 215 | echo. 216 | echo.The overview file is in %BUILDDIR%/changes. 217 | goto end 218 | ) 219 | 220 | if "%1" == "linkcheck" ( 221 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 222 | if errorlevel 1 exit /b 1 223 | echo. 224 | echo.Link check complete; look for any errors in the above output ^ 225 | or in %BUILDDIR%/linkcheck/output.txt. 226 | goto end 227 | ) 228 | 229 | if "%1" == "doctest" ( 230 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 231 | if errorlevel 1 exit /b 1 232 | echo. 233 | echo.Testing of doctests in the sources finished, look at the ^ 234 | results in %BUILDDIR%/doctest/output.txt. 235 | goto end 236 | ) 237 | 238 | if "%1" == "coverage" ( 239 | %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage 240 | if errorlevel 1 exit /b 1 241 | echo. 242 | echo.Testing of coverage in the sources finished, look at the ^ 243 | results in %BUILDDIR%/coverage/python.txt. 244 | goto end 245 | ) 246 | 247 | if "%1" == "xml" ( 248 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 249 | if errorlevel 1 exit /b 1 250 | echo. 251 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 252 | goto end 253 | ) 254 | 255 | if "%1" == "pseudoxml" ( 256 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 257 | if errorlevel 1 exit /b 1 258 | echo. 259 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 260 | goto end 261 | ) 262 | 263 | :end 264 | -------------------------------------------------------------------------------- /docs/source/_static/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darvid/biome/e1f1945165df9def31af42e5e13b623e1de97f01/docs/source/_static/logo.png -------------------------------------------------------------------------------- /docs/source/api.rst: -------------------------------------------------------------------------------- 1 | API 2 | === 3 | 4 | .. automodule:: biome._lib 5 | :members: 6 | 7 | -------------------------------------------------------------------------------- /docs/source/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # biome documentation build configuration file, created by 5 | # sphinx-quickstart on Sat Dec 5 18:45:36 2015. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | import sys 17 | import os 18 | # import shlex 19 | import alabaster 20 | 21 | # If extensions (or modules to document with autodoc) are in another directory, 22 | # add these directories to sys.path here. If the directory is relative to the 23 | # documentation root, use os.path.abspath to make it absolute, like shown here. 24 | sys.path.insert(0, os.path.abspath("../..")) 25 | 26 | # -- General configuration ------------------------------------------------ 27 | 28 | # If your documentation needs a minimal Sphinx version, state it here. 29 | #needs_sphinx = "1.0" 30 | 31 | # Add any Sphinx extension module names here, as strings. They can be 32 | # extensions coming with Sphinx (named "sphinx.ext.*") or your custom 33 | # ones. 34 | extensions = [ 35 | "alabaster", 36 | "sphinx.ext.autodoc", 37 | "sphinx.ext.intersphinx", 38 | "sphinx.ext.todo", 39 | "sphinx.ext.coverage", 40 | "sphinx.ext.viewcode", 41 | "sphinx.ext.napoleon", 42 | ] 43 | 44 | # Add any paths that contain templates here, relative to this directory. 45 | templates_path = ["_templates"] 46 | 47 | # The suffix(es) of source filenames. 48 | # You can specify multiple suffix as a list of string: 49 | # source_suffix = [".rst", ".md"] 50 | source_suffix = ".rst" 51 | 52 | # The encoding of source files. 53 | #source_encoding = "utf-8-sig" 54 | 55 | # The master toctree document. 56 | master_doc = "index" 57 | 58 | # General information about the project. 59 | project = "biome" 60 | copyright = "2015, David Gidwani" 61 | author = "David Gidwani" 62 | 63 | # The version info for the project you"re documenting, acts as replacement for 64 | # |version| and |release|, also used in various other places throughout the 65 | # built documents. 66 | # 67 | # The short X.Y version. 68 | version = "0.1" 69 | # The full version, including alpha/beta/rc tags. 70 | release = "0.1" 71 | 72 | # The language for content autogenerated by Sphinx. Refer to documentation 73 | # for a list of supported languages. 74 | # 75 | # This is also used if you do content translation via gettext catalogs. 76 | # Usually you set "language" from the command line for these cases. 77 | language = None 78 | 79 | # There are two options for replacing |today|: either, you set today to some 80 | # non-false value, then it is used: 81 | #today = " 82 | # Else, today_fmt is used as the format for a strftime call. 83 | #today_fmt = "%B %d, %Y" 84 | 85 | # List of patterns, relative to source directory, that match files and 86 | # directories to ignore when looking for source files. 87 | exclude_patterns = [] 88 | 89 | # The reST default role (used for this markup: `text`) to use for all 90 | # documents. 91 | #default_role = None 92 | 93 | # If true, "()" will be appended to :func: etc. cross-reference text. 94 | #add_function_parentheses = True 95 | 96 | # If true, the current module name will be prepended to all description 97 | # unit titles (such as .. function::). 98 | #add_module_names = True 99 | 100 | # If true, sectionauthor and moduleauthor directives will be shown in the 101 | # output. They are ignored by default. 102 | #show_authors = False 103 | 104 | # The name of the Pygments (syntax highlighting) style to use. 105 | pygments_style = "sphinx" 106 | 107 | # A list of ignored prefixes for module index sorting. 108 | #modindex_common_prefix = [] 109 | 110 | # If true, keep warnings as "system message" paragraphs in the built documents. 111 | #keep_warnings = False 112 | 113 | # If true, `todo` and `todoList` produce output, else they produce nothing. 114 | todo_include_todos = True 115 | 116 | 117 | # -- Options for HTML output ---------------------------------------------- 118 | 119 | # The theme to use for HTML and HTML Help pages. See the documentation for 120 | # a list of builtin themes. 121 | html_theme = "alabaster" 122 | 123 | # Theme options are theme-specific and customize the look and feel of a theme 124 | # further. For a list of options available for each theme, see the 125 | # documentation. 126 | html_theme_options = { 127 | "logo": "logo.png", 128 | "github_user": "darvid", 129 | "github_repo": "biome", 130 | "travis_button": True, 131 | } 132 | 133 | # Add any paths that contain custom themes here, relative to this directory. 134 | html_theme_path = [alabaster.get_path()] 135 | 136 | # The name for this set of Sphinx documents. If None, it defaults to 137 | # " v documentation". 138 | #html_title = None 139 | 140 | # A shorter title for the navigation bar. Default is the same as html_title. 141 | #html_short_title = None 142 | 143 | # The name of an image file (relative to this directory) to place at the top 144 | # of the sidebar. 145 | #html_logo = None 146 | 147 | # The name of an image file (within the static path) to use as favicon of the 148 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 149 | # pixels large. 150 | #html_favicon = None 151 | 152 | # Add any paths that contain custom static files (such as style sheets) here, 153 | # relative to this directory. They are copied after the builtin static files, 154 | # so a file named "default.css" will overwrite the builtin "default.css". 155 | html_static_path = ["_static"] 156 | 157 | # Add any extra paths that contain custom files (such as robots.txt or 158 | # .htaccess) here, relative to this directory. These files are copied 159 | # directly to the root of the documentation. 160 | #html_extra_path = [] 161 | 162 | # If not ", a "Last updated on:" timestamp is inserted at every page bottom, 163 | # using the given strftime format. 164 | #html_last_updated_fmt = "%b %d, %Y" 165 | 166 | # If true, SmartyPants will be used to convert quotes and dashes to 167 | # typographically correct entities. 168 | #html_use_smartypants = True 169 | 170 | # Custom sidebar templates, maps document names to template names. 171 | html_sidebars = { 172 | "**": [ 173 | "about.html", 174 | "navigation.html", 175 | "relations.html", 176 | ], 177 | } 178 | 179 | # Additional templates that should be rendered to pages, maps page names to 180 | # template names. 181 | #html_additional_pages = {} 182 | 183 | # If false, no module index is generated. 184 | #html_domain_indices = True 185 | 186 | # If false, no index is generated. 187 | #html_use_index = True 188 | 189 | # If true, the index is split into individual pages for each letter. 190 | #html_split_index = False 191 | 192 | # If true, links to the reST sources are added to the pages. 193 | #html_show_sourcelink = True 194 | 195 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. 196 | #html_show_sphinx = True 197 | 198 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. 199 | #html_show_copyright = True 200 | 201 | # If true, an OpenSearch description file will be output, and all pages will 202 | # contain a tag referring to it. The value of this option must be the 203 | # base URL from which the finished HTML is served. 204 | #html_use_opensearch = " 205 | 206 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 207 | #html_file_suffix = None 208 | 209 | # Language to be used for generating the HTML full-text search index. 210 | # Sphinx supports the following languages: 211 | # "da", "de", "en", "es", "fi", "fr", "h", "it", "ja" 212 | # "nl", "no", "pt", "ro", "r", "sv", "tr" 213 | #html_search_language = "en" 214 | 215 | # A dictionary with options for the search language support, empty by default. 216 | # Now only "ja" uses this config value 217 | #html_search_options = {"type": "default"} 218 | 219 | # The name of a javascript file (relative to the configuration directory) that 220 | # implements a search results scorer. If empty, the default will be used. 221 | #html_search_scorer = "scorer.js" 222 | 223 | # Output file base name for HTML help builder. 224 | htmlhelp_basename = "biomedoc" 225 | 226 | # -- Options for LaTeX output --------------------------------------------- 227 | 228 | latex_elements = { 229 | # The paper size ("letterpaper" or "a4paper"). 230 | #"papersize": "letterpaper", 231 | 232 | # The font size ("10pt", "11pt" or "12pt"). 233 | #"pointsize": "10pt", 234 | 235 | # Additional stuff for the LaTeX preamble. 236 | #"preamble": ", 237 | 238 | # Latex figure (float) alignment 239 | #"figure_align": "htbp", 240 | } 241 | 242 | # Grouping the document tree into LaTeX files. List of tuples 243 | # (source start file, target name, title, 244 | # author, documentclass [howto, manual, or own class]). 245 | latex_documents = [ 246 | (master_doc, "biome.tex", "biome Documentation", 247 | "David Gidwani", "manual"), 248 | ] 249 | 250 | # The name of an image file (relative to this directory) to place at the top of 251 | # the title page. 252 | #latex_logo = None 253 | 254 | # For "manual" documents, if this is true, then toplevel headings are parts, 255 | # not chapters. 256 | #latex_use_parts = False 257 | 258 | # If true, show page references after internal links. 259 | #latex_show_pagerefs = False 260 | 261 | # If true, show URL addresses after external links. 262 | #latex_show_urls = False 263 | 264 | # Documents to append as an appendix to all manuals. 265 | #latex_appendices = [] 266 | 267 | # If false, no module index is generated. 268 | #latex_domain_indices = True 269 | 270 | 271 | # -- Options for manual page output --------------------------------------- 272 | 273 | # One entry per manual page. List of tuples 274 | # (source start file, name, description, authors, manual section). 275 | man_pages = [ 276 | (master_doc, "biome", "biome Documentation", 277 | [author], 1) 278 | ] 279 | 280 | # If true, show URL addresses after external links. 281 | #man_show_urls = False 282 | 283 | 284 | # -- Options for Texinfo output ------------------------------------------- 285 | 286 | # Grouping the document tree into Texinfo files. List of tuples 287 | # (source start file, target name, title, author, 288 | # dir menu entry, description, category) 289 | texinfo_documents = [ 290 | (master_doc, "biome", "biome Documentation", 291 | author, "biome", "Painless access to namespaced environment variables", 292 | "Miscellaneous"), 293 | ] 294 | 295 | # Documents to append as an appendix to all manuals. 296 | #texinfo_appendices = [] 297 | 298 | # If false, no module index is generated. 299 | #texinfo_domain_indices = True 300 | 301 | # How to display URL addresses: "footnote", "no", or "inline". 302 | #texinfo_show_urls = "footnote" 303 | 304 | # If true, do not generate a @detailmenu in the "Top" node"s menu. 305 | #texinfo_no_detailmenu = False 306 | 307 | 308 | # Example configuration for intersphinx: refer to the Python standard library. 309 | intersphinx_mapping = {"https://docs.python.org/": None} 310 | -------------------------------------------------------------------------------- /docs/source/features.rst: -------------------------------------------------------------------------------- 1 | Features 2 | ======== 3 | 4 | - **Zero-setup, global access to environment variable namespaces.** 5 | No instantiation needed. 6 | 7 | .. code-block:: python 8 | 9 | # lib/database.py 10 | import biome 11 | print(biome.database.driver) 12 | 13 | # lib/logging.py 14 | import biome 15 | print(biome.logging.rsyslog) 16 | 17 | - **Implicit type coercion.** Or explicit, whatever floats your 18 | boat. 19 | 20 | .. code-block:: pycon 21 | 22 | >>> biome.myapp.host 23 | "0.0.0.0" 24 | >>> biome.myapp.port 25 | 8000 26 | >>> biome.myapp.debug 27 | True 28 | >>> biome.myapp.static_path 29 | PosixPath("/var/www/static") 30 | >>> biome.myapp.get_int("port") 31 | 8000 32 | -------------------------------------------------------------------------------- /docs/source/index.rst: -------------------------------------------------------------------------------- 1 | .. biome documentation master file, created by 2 | sphinx-quickstart on Sat Dec 5 18:45:36 2015. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to biome 7 | ================ 8 | 9 | **biome** is a tiny library that enables developers to configure their 10 | applications from the environment cleanly, quickly, and unobtrusively. 11 | 12 | Storing application configuration in environment variables is in many 13 | cases considered a `best practice`_, but loading configuration values 14 | from the environment is not particularly :abbr:`DRY (Don't Repeat Yourself)`. 15 | 16 | .. code-block:: python 17 | 18 | import os 19 | server_host = os.environ["MYAPP_HOST"] 20 | server_port = int(os.environ["MYAPP_PORT"]) 21 | debug = os.environ["MYAPP_DEBUG"].lower() in ("true", "1") 22 | 23 | With **biome**, you can effectively namespace your application 24 | configuration with environment variable prefixes, and access config 25 | values through either attributes or items, whichever you prefer. 26 | 27 | .. code-block:: python 28 | 29 | import biome 30 | config = biome.myapp # or biome.MYAPP, or biome.MyApp 31 | debug = config.debug # or config.DEBUG -- this returns a boolean 32 | bind = "%s:%d" % (config.host, config.port) 33 | 34 | 35 | .. _best practice: 36 | http://12factor.net/config 37 | 38 | .. toctree:: 39 | :maxdepth: 1 40 | :hidden: 41 | 42 | features 43 | usage 44 | install 45 | api 46 | -------------------------------------------------------------------------------- /docs/source/install.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | **biome** was `tested`_ on Python 2.7, 3.2, 3.3, 3.4, and 3.5. Python 5 | 2.6 and PyPy are not currently supported. 6 | 7 | As `pathlib`_ was introduced in Python 3.4, you will need the 8 | `backport`_ if you wish to install **biome** on prior versions of 9 | Python. 10 | 11 | **biome** can be installed with `pip`_ or `easy_install`_, although 12 | pip is recommended. 13 | 14 | .. code-block:: shell 15 | 16 | $ pip install biome 17 | 18 | .. _tested: 19 | https://travis-ci.org/darvid/biome 20 | 21 | .. _pathlib: 22 | https://docs.python.org/3/library/pathlib.html 23 | 24 | .. _backport: 25 | https://pypi.python.org/pypi/pathlib2/ 26 | 27 | .. _pip: 28 | https://pip.pypa.io/en/stable/ 29 | 30 | .. _easy_install: 31 | https://pythonhosted.org/setuptools/easy_install.html 32 | -------------------------------------------------------------------------------- /docs/source/usage.rst: -------------------------------------------------------------------------------- 1 | Usage 2 | ===== 3 | 4 | Accessing namespaces 5 | -------------------- 6 | 7 | Environment *namespaces*, or sets of environment variables that share 8 | a common prefix, are grouped into :class:`~._lib.Habitat` objects. 9 | For example, the following environment variables are part of the 10 | ``YOURAPP`` namespace:: 11 | 12 | YOURAPP_HOST="server.com" 13 | YOURAPP_PORT=8000 14 | YOURAPP_DEBUG="true" 15 | 16 | **biome** dynamically populates namespaces on attribute access to the 17 | ``biome`` *"module"*, which is actually a class injected into 18 | :data:`sys.modules`. This results in a slightly magical, but extremely 19 | convenient drop-in configuration provider for your application. 20 | 21 | .. code-block:: pycon 22 | 23 | >>> import biome 24 | >>> biome.YOURAPP.host 25 | "server.com" 26 | 27 | .. note:: 28 | **biome** expects that your environment variable prefixes always 29 | carry a trailing underscore, separating them from the suffix, or 30 | variable name. For instance, the variable ``YOURAPPDEBUG`` must be 31 | changed to ``YOURAPP_DEBUG`` if you want it included in the 32 | ``YOURAPP`` namespace. 33 | 34 | 35 | Accessing variables 36 | ------------------- 37 | 38 | Namespaced environment variables can be accessed in the way you'd 39 | expect (via attributes), and are automatically converted to ``int``, 40 | ``bool``, and :class:`pathlib.Path` objects whenever possible. 41 | 42 | .. code-block:: python 43 | 44 | # YOURAPP_SECRET_KEY='~/.secret_key' 45 | secret_key = biome.YOURAPP.secret_key.read_text() 46 | 47 | You can also use any of the getters in the :class:`~._lib.Habitat` class 48 | to explicitly coerce types, or if you want to provide default values. 49 | 50 | .. code-block:: python 51 | 52 | debug = biome.YOURAPP.get_bool("debug", False) 53 | -------------------------------------------------------------------------------- /requirements.in: -------------------------------------------------------------------------------- 1 | attrdict 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile 3 | # Make changes in requirements.in, then run this to update: 4 | # 5 | # pip-compile requirements.in 6 | # 7 | attrdict==2.0.0 8 | -------------------------------------------------------------------------------- /requirements/build/main.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile 3 | # To update, run: 4 | # 5 | # pip-compile --output-file requirements/build/main.txt requirements/src/qa.in requirements/src/main.in 6 | # 7 | attrdict==2.0.0 8 | configparser==3.5.0 # via flake8 9 | enum34==1.1.6 # via flake8 10 | flake8-blind-except==0.1.1 11 | flake8-commas==0.1.6 12 | flake8-comprehensions==1.2.1 13 | flake8-docstrings==1.0.2 14 | flake8-future-import==0.4.3 15 | flake8-import-order==0.11 16 | flake8-print==2.0.2 17 | flake8-quotes==0.8.1 18 | flake8==3.2.1 19 | mccabe==0.5.2 # via flake8 20 | pep8==1.7.0 # via flake8-commas 21 | pycodestyle==2.2.0 # via flake8, flake8-import-order 22 | pydocstyle==1.1.1 # via flake8-docstrings 23 | pyflakes==1.3.0 # via flake8 24 | six==1.10.0 # via attrdict 25 | 26 | # The following packages are considered to be unsafe in a requirements file: 27 | # setuptools # via flake8-blind-except 28 | -------------------------------------------------------------------------------- /requirements/build/qa.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile 3 | # To update, run: 4 | # 5 | # pip-compile --output-file requirements/build/qa.txt requirements/src/qa.in 6 | # 7 | configparser==3.5.0 # via flake8 8 | enum34==1.1.6 # via flake8 9 | flake8-blind-except==0.1.1 10 | flake8-commas==0.1.6 11 | flake8-comprehensions==1.2.1 12 | flake8-docstrings==1.0.2 13 | flake8-future-import==0.4.3 14 | flake8-import-order==0.11 15 | flake8-print==2.0.2 16 | flake8-quotes==0.8.1 17 | flake8==3.2.1 18 | mccabe==0.5.2 # via flake8 19 | pep8==1.7.0 # via flake8-commas 20 | pycodestyle==2.2.0 # via flake8, flake8-import-order 21 | pydocstyle==1.1.1 # via flake8-docstrings 22 | pyflakes==1.3.0 # via flake8 23 | 24 | # The following packages are considered to be unsafe in a requirements file: 25 | # setuptools # via flake8-blind-except 26 | -------------------------------------------------------------------------------- /requirements/build/test.txt: -------------------------------------------------------------------------------- 1 | # 2 | # This file is autogenerated by pip-compile 3 | # To update, run: 4 | # 5 | # pip-compile --output-file requirements/build/test.txt requirements/src/qa.in requirements/src/main.in requirements/src/test.in 6 | # 7 | attrdict==2.0.0 8 | configparser==3.5.0 # via flake8 9 | coverage==4.2 # via pytest-cov 10 | enum34==1.1.6 # via flake8 11 | flake8-blind-except==0.1.1 12 | flake8-commas==0.1.6 13 | flake8-comprehensions==1.2.1 14 | flake8-docstrings==1.0.2 15 | flake8-future-import==0.4.3 16 | flake8-import-order==0.11 17 | flake8-print==2.0.2 18 | flake8-quotes==0.8.1 19 | flake8==3.2.1 20 | mccabe==0.5.2 # via flake8 21 | pep8==1.7.0 # via flake8-commas 22 | py==1.4.31 # via pytest 23 | pycodestyle==2.2.0 # via flake8, flake8-import-order 24 | pydocstyle==1.1.1 # via flake8-docstrings 25 | pyflakes==1.3.0 # via flake8 26 | pytest-cov==2.4.0 27 | pytest==3.0.5 # via pytest-cov 28 | six==1.10.0 # via attrdict 29 | 30 | # The following packages are considered to be unsafe in a requirements file: 31 | # setuptools # via flake8-blind-except 32 | -------------------------------------------------------------------------------- /requirements/src/main.in: -------------------------------------------------------------------------------- 1 | # Generated by reqwire on Sun Dec 11 03:17:59 2016 2 | --index-url https://pypi.python.org/simple 3 | attrdict==2.0.0 4 | -------------------------------------------------------------------------------- /requirements/src/qa.in: -------------------------------------------------------------------------------- 1 | # Generated by reqwire on Sun Dec 11 13:08:22 2016 2 | --index-url https://pypi.python.org/simple 3 | flake8-blind-except==0.1.1 4 | flake8-commas==0.1.6 5 | flake8-comprehensions==1.2.1 6 | flake8-docstrings==1.0.2 7 | flake8-future-import==0.4.3 8 | flake8-import-order==0.11 9 | flake8-print==2.0.2 10 | flake8-quotes==0.8.1 11 | flake8==3.2.1 12 | -------------------------------------------------------------------------------- /requirements/src/test.in: -------------------------------------------------------------------------------- 1 | # Generated by reqwire on Sun Dec 11 12:46:42 2016 2 | --index-url https://pypi.python.org/simple 3 | pytest-cov==2.4.0 4 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 3 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Provides painless access to namespaced environment variables. 3 | 4 | Links 5 | ----- 6 | 7 | * `Source code `_ 8 | * `Documentation `_ 9 | 10 | """ 11 | import io 12 | import sys 13 | 14 | import setuptools 15 | 16 | 17 | __all__ = ('setup',) 18 | 19 | 20 | def readme(): 21 | with io.open('README.rst') as fp: 22 | return fp.read() 23 | 24 | 25 | def setup(): 26 | """Package setup entrypoint.""" 27 | install_requirements = ["attrdict"] 28 | if sys.version_info[:2] < (3, 4): 29 | install_requirements.append("pathlib") 30 | setup_requirements = ['six', 'setuptools>=17.1', 'setuptools_scm'] 31 | needs_sphinx = { 32 | 'build_sphinx', 33 | 'docs', 34 | 'upload_docs', 35 | }.intersection(sys.argv) 36 | if needs_sphinx: 37 | setup_requirements.append('sphinx') 38 | setuptools.setup( 39 | author="David Gidwani", 40 | author_email="david.gidwani@gmail.com", 41 | classifiers=[ 42 | "Development Status :: 4 - Beta", 43 | "Intended Audience :: Developers", 44 | "License :: OSI Approved :: BSD License", 45 | "Operating System :: OS Independent", 46 | "Programming Language :: Python", 47 | "Programming Language :: Python :: 2", 48 | "Programming Language :: Python :: 2.7", 49 | "Programming Language :: Python :: 3", 50 | "Programming Language :: Python :: 3.3", 51 | "Programming Language :: Python :: 3.4", 52 | "Topic :: Software Development", 53 | "Topic :: Software Development :: Libraries :: Python Modules", 54 | ], 55 | description="Painless access to namespaced environment variables", 56 | download_url="https://github.com/darvid/biome/tarball/0.1", 57 | install_requires=install_requirements, 58 | keywords="conf config configuration environment", 59 | license="BSD", 60 | long_description=readme(), 61 | name="biome", 62 | package_dir={'': 'src'}, 63 | packages=setuptools.find_packages('./src'), 64 | setup_requires=setup_requirements, 65 | tests_require=["pytest"], 66 | url="https://github.com/darvid/biome", 67 | use_scm_version=True, 68 | ) 69 | 70 | 71 | if __name__ == '__main__': 72 | setup() 73 | -------------------------------------------------------------------------------- /src/biome/__init__.py: -------------------------------------------------------------------------------- 1 | """Provides painless access to namespaced environment variables.""" 2 | from __future__ import absolute_import 3 | 4 | import ast 5 | import os 6 | import pathlib 7 | import sys 8 | 9 | import attrdict 10 | 11 | 12 | __all__ = ('EnvironmentError', 'Habitat') 13 | 14 | 15 | package_name = 'biome' 16 | 17 | # Create a reference to the module so it doesn't get deleted 18 | # See http://stackoverflow.com/a/5365733/211772 19 | _module_ref = sys.modules[package_name] 20 | 21 | 22 | def _sanitize_prefix(prefix): 23 | return prefix.upper().rstrip('_') 24 | 25 | 26 | class EnvironmentError(KeyError): 27 | """Raised when something went wrong accessing the environment. 28 | 29 | This exception subclasses ``KeyError`` for compatibility with 30 | ``os.environ`` in tests. 31 | 32 | """ 33 | 34 | @classmethod 35 | def not_found(cls, prefix, name): # noqa: D102 36 | return cls('"%s_%s" does not exist in the environment' % 37 | (prefix, name.upper())) 38 | 39 | 40 | class Habitat(attrdict.AttrDict): # noqa: D205,D400 41 | """Provides attribute/map style access to a set of namespaced 42 | environment variables. 43 | 44 | Environment variable values are implicitly converted to Python 45 | literals when possible, and can also be explicitly accessed through 46 | the ``get``, ``get_bool``, ``get_int``, and ``get_path`` methods. 47 | 48 | Args: 49 | prefix (str): The prefix to use, sans trailing underscore. 50 | 51 | """ 52 | 53 | def __new__(cls, prefix): # noqa: D102 54 | if isinstance(prefix, attrdict.AttrDict): 55 | return prefix 56 | return super(Habitat, cls).__new__(cls, prefix) 57 | 58 | def __init__(self, prefix): # noqa: D102 59 | self._setattr('_prefix', _sanitize_prefix(prefix)) 60 | super(Habitat, self).__init__(self.get_environ(self._prefix)) 61 | 62 | @classmethod 63 | def get_environ(cls, prefix): 64 | """Retrieves environment variables from a namespace. 65 | 66 | Args: 67 | prefix (str): The prefix, without a trailing underscore. 68 | 69 | Returns: 70 | list: A list of environment variable keys and values. 71 | 72 | """ 73 | return ((key[len(prefix) + 1:], value) 74 | for key, value in os.environ.items() 75 | if key.startswith('%s_' % prefix)) 76 | 77 | def get(self, name, default=None): 78 | """A more explicit alternative to attribute or item access. 79 | 80 | Args: 81 | name (str): The case-insensitive, unprefixed variable name. 82 | default: If provided, a default value will be returned 83 | instead of throwing ``EnvironmentError``. 84 | 85 | Returns: 86 | The value of the environment variable. The value is 87 | implicitly converted to a Python literal (such as ``int`` 88 | or ``bool``) when possible. 89 | 90 | Raises: 91 | EnvironmentError: If the environment variable does not 92 | exist, and ``default`` was not provided. 93 | 94 | """ 95 | try: 96 | return self[name] 97 | except EnvironmentError: 98 | if default is not None: 99 | return default 100 | raise 101 | 102 | def get_bool(self, name, default=None): 103 | """Retrieves an environment variable value as ``bool``. 104 | 105 | Integer values are converted as expected: zero evaluates to 106 | ``False``, and non-zero to ``True``. String values of ``'true'`` 107 | and ``'false'`` are evaluated case insensitive. 108 | 109 | Args: 110 | name (str): The case-insensitive, unprefixed variable name. 111 | default: If provided, a default value will be returned 112 | instead of throwing ``EnvironmentError``. 113 | 114 | Returns: 115 | bool: The environment variable's value as a ``bool``. 116 | 117 | Raises: 118 | EnvironmentError: If the environment variable does not 119 | exist, and ``default`` was not provided. 120 | ValueError: If the environment variable value could not be 121 | interpreted as a ``bool``. 122 | 123 | """ 124 | if name not in self: 125 | if default is not None: 126 | return default 127 | raise EnvironmentError.not_found(self._prefix, name) 128 | return bool(self.get_int(name)) 129 | 130 | def get_dict(self, name, default=None): 131 | """Retrieves an environment variable value as a dictionary. 132 | 133 | Args: 134 | name (str): The case-insensitive, unprefixed variable name. 135 | default: If provided, a default value will be returned 136 | instead of throwing ``EnvironmentError``. 137 | 138 | Returns: 139 | dict: The environment variable's value as a ``dict``. 140 | 141 | Raises: 142 | EnvironmentError: If the environment variable does not 143 | exist, and ``default`` was not provided. 144 | 145 | """ 146 | if name not in self: 147 | if default is not None: 148 | return default 149 | raise EnvironmentError.not_found(self._prefix, name) 150 | return dict(**self.get(name)) 151 | 152 | def get_int(self, name, default=None): 153 | """Retrieves an environment variable as an integer. 154 | 155 | Args: 156 | name (str): The case-insensitive, unprefixed variable name. 157 | default: If provided, a default value will be returned 158 | instead of throwing ``EnvironmentError``. 159 | 160 | Returns: 161 | int: The environment variable's value as an integer. 162 | 163 | Raises: 164 | EnvironmentError: If the environment variable does not 165 | exist, and ``default`` was not provided. 166 | ValueError: If the environment variable value is not an 167 | integer with base 10. 168 | 169 | """ 170 | if name not in self: 171 | if default is not None: 172 | return default 173 | raise EnvironmentError.not_found(self._prefix, name) 174 | return int(self[name]) 175 | 176 | def get_list(self, name, default=None): 177 | """Retrieves an environment variable as a list. 178 | 179 | Note that while implicit access of environment variables 180 | containing tuples will return tuples, using this method will 181 | coerce tuples to lists. 182 | 183 | Args: 184 | name (str): The case-insensitive, unprefixed variable name. 185 | default: If provided, a default value will be returned 186 | instead of throwing ``EnvironmentError``. 187 | 188 | Returns: 189 | list: The environment variable's value as a list. 190 | 191 | Raises: 192 | EnvironmentError: If the environment variable does not 193 | exist, and ``default`` was not provided. 194 | ValueError: If the environment variable value is not an 195 | integer with base 10. 196 | 197 | """ 198 | if name not in self: 199 | if default is not None: 200 | return default 201 | raise EnvironmentError.not_found(self._prefix, name) 202 | return list(self[name]) 203 | 204 | def get_path(self, name, default=None): 205 | """Retrieves an environment variable as a filesystem path. 206 | 207 | Requires the `pathlib`_ library if using Python <= 3.4. 208 | 209 | Args: 210 | name (str): The case-insensitive, unprefixed variable name. 211 | default: If provided, a default value will be returned 212 | instead of throwing ``EnvironmentError``. 213 | 214 | Returns: 215 | pathlib.Path: The environment variable as a ``pathlib.Path`` 216 | object. 217 | 218 | Raises: 219 | EnvironmentError: If the environment variable does not 220 | exist, and ``default`` was not provided. 221 | 222 | .. _pathlib: 223 | https://pypi.python.org/pypi/pathlib/ 224 | 225 | """ 226 | if name not in self: 227 | if default is not None: 228 | return default 229 | raise EnvironmentError.not_found(self._prefix, name) 230 | return pathlib.Path(self[name]) 231 | 232 | def refresh(self): 233 | """Update all environment variables from ``os.environ``. 234 | 235 | Use if ``os.environ`` was modified dynamically *after* you 236 | accessed an environment namespace with ``biome``. 237 | 238 | """ 239 | super(Habitat, self).update(self.get_environ(self._prefix)) 240 | 241 | def __contains__(self, name): # noqa: D105 242 | return super(Habitat, self).__contains__(name.upper()) 243 | 244 | def __getitem__(self, name): # noqa: D105 245 | name = name.upper() 246 | try: 247 | value = super(Habitat, self).__getitem__(name) 248 | except KeyError: 249 | raise EnvironmentError.not_found(self._prefix, name) 250 | try: 251 | # Attempt to parse value as a Python literal 252 | if value.lower() in ('true', 'false'): 253 | value = value.title() 254 | value = ast.literal_eval(value) 255 | if isinstance(value, dict): 256 | return attrdict.AttrDict(**value) 257 | except (SyntaxError, ValueError): 258 | name_upper = name.upper() 259 | # Return a ``pathlib.Path`` object iff: 260 | # * value contains the default OS path separator 261 | # * the substring 'PATH', 'DIR', or 'FILE' in the var name 262 | if (os.path.sep in value and 263 | 'PATH' in name_upper or 264 | 'DIR' in name_upper or 265 | 'FILE' in name_upper): 266 | value = pathlib.Path(value) 267 | return value 268 | 269 | def __repr__(self): # noqa: D105 270 | return '<{}({!r})>'.format(self.__class__.__name__, self._prefix) 271 | 272 | 273 | class Biome(attrdict.AttrDict): 274 | """Provides utilities for accessing environment variables.""" 275 | 276 | def __getattr__(self, name): 277 | if name in ('_lib', '__package__'): 278 | return _module_ref 279 | elif name in '__loader__': 280 | return __loader__ 281 | try: 282 | return self[name.upper()] 283 | except KeyError: 284 | if name.startswith('_'): 285 | raise 286 | name = _sanitize_prefix(name) 287 | if name not in self and not name.startswith('_'): 288 | self[name] = _module_ref.Habitat(name) 289 | return self[name] 290 | 291 | def __repr__(self): # pragma: no cover 292 | return '<{}({})>'.format( 293 | self.__class__.__name__, 294 | dict.__repr__(self)) 295 | 296 | 297 | sys.modules[package_name] = Biome() 298 | for prop in ('file', 'name'): 299 | object.__setattr__(sys.modules[package_name], '__%s__' % prop, 300 | locals()['__%s__' % prop]) 301 | sys.modules['%s._lib' % package_name] = _module_ref 302 | -------------------------------------------------------------------------------- /tests/test_biome.py: -------------------------------------------------------------------------------- 1 | """Biome unit tests.""" 2 | import os 3 | import pathlib 4 | 5 | import biome 6 | 7 | import pytest 8 | 9 | 10 | def str2bool(string): 11 | """Convert a string to bool. 12 | 13 | Args: 14 | string (str): Must be 'true' or 'false', case insensitive. 15 | 16 | Raises: 17 | ValueError: If the string cannot be parsed as bool 18 | 19 | """ 20 | lower = string.lower() 21 | if lower not in ("true", "false"): 22 | raise ValueError("cannot interpret %r as boolean") 23 | return lower == "true" 24 | 25 | 26 | def setup_module(module): 27 | """Setup test environment.""" 28 | os.environ["YOURAPP_HOST"] = "dev.yourapp" 29 | os.environ["YOURAPP_PORT"] = "5000" 30 | os.environ["YOURAPP_BOOL_TITLE"] = "True" 31 | os.environ["YOURAPP_BOOL_LOWER"] = "true" 32 | os.environ["YOURAPP_BOOL_UPPER"] = "TRUE" 33 | os.environ["YOURAPP_DICT"] = "{'host': '127.0.0.1', 'port': 5000}" 34 | os.environ["YOURAPP_LIST"] = "[1, 2, 3]" 35 | os.environ["YOURAPP_TUPLE"] = "(1, 2, 3)" 36 | os.environ["YOURAPP_PATH"] = str(pathlib.Path("foo") / "bar") 37 | 38 | 39 | def test_access_case_sensitivity(): 40 | expected_host = os.environ["YOURAPP_HOST"] 41 | assert biome.YOURAPP.HOST == expected_host 42 | assert biome.YOURAPP.host == expected_host 43 | assert biome.yourapp.HOST == expected_host 44 | assert biome.yourapp.host == expected_host 45 | 46 | 47 | def test_access_defaults(): 48 | assert biome.YOURAPP.get("host", "default") != "default" 49 | assert biome.YOURAPP.get("driver", "sqlite") == "sqlite" 50 | assert biome.YOURAPP.get_bool("production", False) is False 51 | assert biome.YOURAPP.get_int("throttle_seconds", 60) == 60 52 | assert biome.YOURAPP.get_path("config", "dev.conf") == "dev.conf" 53 | assert not biome.YOURAPP.get_list("plugins", []) 54 | assert not biome.YOURAPP.get_dict("options", {}) 55 | 56 | 57 | def test_access_missing(): 58 | getters = ( 59 | "get", 60 | "get_bool", 61 | "get_dict", 62 | "get_int", 63 | "get_list", 64 | "get_path", 65 | ) 66 | for getter in getters: 67 | with pytest.raises(biome._lib.EnvironmentError): 68 | getattr(biome.YOURAPP, getter)("foo") 69 | 70 | 71 | def test_access_trailing_underscore(): 72 | assert biome.YOURAPP == biome.YOURAPP_ 73 | 74 | 75 | def test_explicit_access_literals(): 76 | assert biome.YOURAPP.get("host") == biome.YOURAPP["host"] 77 | 78 | assert biome.YOURAPP.get_int("port") == int(os.environ["YOURAPP_PORT"]) 79 | 80 | # Title case boolean ('True' or 'False') 81 | bool_title = os.environ["YOURAPP_BOOL_TITLE"] 82 | assert biome.YOURAPP.get_bool("bool_title") == str2bool(bool_title) 83 | 84 | # Lower case boolean ('true' or 'false') 85 | bool_lower = os.environ["YOURAPP_BOOL_LOWER"] 86 | assert biome.YOURAPP.get_bool("bool_lower") == str2bool(bool_lower) 87 | 88 | # Upper case boolean ('TRUE' or 'FALSE') 89 | bool_upper = os.environ["YOURAPP_BOOL_UPPER"] 90 | assert biome.YOURAPP.get_bool("bool_upper") == str2bool(bool_upper) 91 | 92 | assert isinstance(biome.YOURAPP.get_dict("dict"), dict) 93 | assert isinstance(biome.YOURAPP.get_list("list"), list) 94 | assert isinstance(biome.YOURAPP.get_list("tuple"), list) 95 | 96 | with pytest.raises(ValueError): 97 | assert biome.YOURAPP.get_bool("host") 98 | 99 | assert biome.YOURAPP.get_path("path") == \ 100 | pathlib.Path(os.environ["YOURAPP_PATH"]) 101 | 102 | 103 | def test_implicit_access_literals(): 104 | assert biome.YOURAPP.port == int(os.environ["YOURAPP_PORT"]) 105 | 106 | bool_title = os.environ["YOURAPP_BOOL_TITLE"] 107 | assert biome.YOURAPP.bool_title == str2bool(bool_title) 108 | 109 | bool_lower = os.environ["YOURAPP_BOOL_LOWER"] 110 | assert biome.YOURAPP.bool_lower == str2bool(bool_lower) 111 | 112 | assert biome.YOURAPP.path == pathlib.Path(os.environ["YOURAPP_PATH"]) 113 | 114 | assert isinstance(biome.YOURAPP.dict, dict) 115 | assert isinstance(biome.YOURAPP.list, tuple) 116 | assert isinstance(biome.YOURAPP.tuple, tuple) 117 | 118 | 119 | def test_refresh(): 120 | os.environ["YOURAPP_DEBUG"] = "True" 121 | assert "debug" not in biome.YOURAPP 122 | biome.YOURAPP.refresh() 123 | assert "debug" in biome.YOURAPP 124 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = cov-init,py{27,33,34,35},py35-{lint,mypy},cov-report 3 | 4 | [flake8] 5 | application-import-names = biome 6 | exclude = 7 | .tox, 8 | .git, 9 | __pycache__, 10 | docs/source/conf.py, 11 | ./build, 12 | dist, 13 | src/stubs, 14 | tests/fixtures/*, 15 | *.pyc, 16 | *.egg-info, 17 | .cache, 18 | .eggs 19 | ignore = 20 | D401, 21 | D403, 22 | FI10, 23 | FI12, 24 | FI13, 25 | FI14, 26 | FI15, 27 | FI16, 28 | FI17, 29 | FI51, 30 | H301 31 | import-order-style = google 32 | max-complexity = 11 33 | 34 | [testenv] 35 | passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH 36 | usedevelop = true 37 | commands = py.test --cov --cov-report= {posargs} 38 | basepython = 39 | cov-{init,report}: python3.5 40 | py27: python2.7 41 | py33: python3.3 42 | py34: python3.4 43 | py35: python3.5 44 | deps = 45 | -rrequirements/build/test.txt 46 | py{27,33,34}: typing 47 | setenv = 48 | COVERAGE_FILE = .coverage.{envname} 49 | 50 | [testenv:docs] 51 | basepython = python3.5 52 | changedir = docs 53 | deps = sphinx 54 | commands = 55 | sphinx-build -W -b html -d {envtmpdir}/doctrees source {envtmpdir}/html 56 | 57 | [testenv:cov-init] 58 | commands = coverage erase 59 | setenv = 60 | COVERAGE_FILE = .coverage 61 | 62 | [testenv:cov-report] 63 | commands = 64 | coverage combine 65 | coverage report -m 66 | setenv = 67 | COVERAGE_FILE = .coverage 68 | 69 | [testenv:py35-lint] 70 | commands = flake8 src/biome 71 | deps = 72 | -rrequirements/build/qa.txt 73 | # hacking 74 | 75 | [testenv:py35-mypy] 76 | commands = 77 | mypy -s --fast-parser src/biome 78 | deps = 79 | mypy-lang>=0.4 80 | typed-ast 81 | setenv = 82 | MYPYPATH = src/stubs 83 | 84 | [tox:travis] 85 | 2.7 = py27 86 | 3.3 = py33 87 | 3.4 = py34 88 | 3.5 = cov-init, py35, py35-lint, py35-mypy, docs, cov-report 89 | --------------------------------------------------------------------------------