pax_global_header00006660000000000000000000000064137442643220014521gustar00rootroot0000000000000052 comment=96963cff2e569bf0a15933f773a8bea7a762e2c4 .dockerignore000066400000000000000000000004001374426432200135330ustar00rootroot00000000000000# Dockerignore for package building container .git/ .tox/ .venv/ build/ dist/ *~ *.egg-info/ *.py[co] .pip-cache/ debian/debhelper-build-stamp debian/files debian/*.debhelper debian/*.substvars debian/sdist/ debian/dh-virtualenv/ debian/dh-virtualenv-*.*/ .env000066400000000000000000000222141374426432200116570ustar00rootroot00000000000000# /bin/bash - help gedit syntax highlight do the right thing # autoenv script (https://github.com/kennethreitz/autoenv) # Use ". .env -h" for help. # # This script is an autoenev script that either activates or creates # a local virtualenv in '.venv' for (almost) any project. Typical # project assets like 'setup.py' and requirements files are used to # populate the virtualenv. # # This script is tested with bash, report problems with other shells to # # https://github.com/Springerle/py-generic-project/issues # # It should work on any Linux, and Mac OSX. # _venv_virtualenv=/usr/bin/virtualenv _venv_py3=false _venv_pip_req='pip>8' _venv_master_url="https://raw.githubusercontent.com/Springerle/py-generic-project/master/.env" _venv_temp=/usr/local/bin/virtualenv if test -x $_venv_temp; then _venv_virtualenv=$_venv_temp fi test "${_venv_py3:0:2}" != '{''{' || _venv_py3=false if $_venv_py3; then # Python 3 mode? # /opt/pyenv, see https://github.com/jhermann/priscilla/tree/master/pyenv _venv_temp=/opt/pyenv/bin/pyvenv-3 if test -x $_venv_temp; then _venv_virtualenv=$_venv_temp fi # python3 venv in recent Debian / Ubuntu # prefer a version that has Tkinter installed, if available _venv_py_tk=$(dpkg-query --show -f '${Version}' python3-tk 2>/dev/null | cut -f-2 -d.) for _venv_temp in $_venv_py_tk 3 3.6 3.5 3.4 3.3; do _venv_temp=/usr/bin/pyvenv-$_venv_temp if test -x $_venv_temp; then _venv_virtualenv=$_venv_temp break fi done unset _venv_py_tk fi _venv_readlink=readlink case "$(uname -s)" in # See http://en.wikipedia.org/wiki/Uname#Examples Darwin) _venv_temp="/usr/local/opt/coreutils/libexec/gnubin/readlink" if test -x $_venv_temp; then _venv_readlink=$_venv_temp else echo "*** No readlink command, do a 'brew install coreutils'..." return 1 fi ;; CYGWIN*) ;; Linux|*) ;; esac test -z "$JENKINS_URL" || echo '***' "\$0=$0" "\$BASH_SOURCE=${BASH_SOURCE[0]}" if test "$0" = "-bash" -o "$(basename -- "$0")" = "bash" -o "$(basename -- "${BASH_SOURCE[0]}")" = ".env"; then _venv_script=$($_venv_readlink -f ${BASH_SOURCE[0]}) elif test "$(basename -- "$0")" = ".env"; then _venv_script=$($_venv_readlink -f "$0") fi _venv_script="${_venv_script:-/dont-know-really/.env}" _venv_xtrace=$(set +o | grep xtrace) set +x _venv_name="$(basename $(pwd))" _venv_pip_log() { if $_venv_verbose; then cat else egrep "Found.existing.installation|Collecting|Installing.collected.packages|Searching.for|Installed|Finished" fi } # command line flags, mostly for CI server usage _venv_create=false _venv_develop=false _venv_verbose=false while test "${1:0:1}" = "-"; do case "$1" in --yes) _venv_create=true ;; --develop) _venv_develop=true ;; --verbose | -v) _venv_verbose=true; set -x ;; --virtualenv) shift; _venv_virtualenv="$1" ;; --help | -h) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ echo "usage: . $_venv_script " echo echo "Create and/or activate a Python virtual environment. Updates pip and other" echo "system packages, and recognizes 'dev-requirements.txt' and 'setup.py' or" echo "'requirements.txt'." echo echo "This is an autoenv script (see https://github.com/kennethreitz/autoenv)." echo echo "Options:" echo " --yes create missing venv without prompting" echo " --develop call 'develop -U' on activation" echo " -v | --verbose don't filter install logs on terminal" echo " (full logs in '.venv/pip-install.log')" echo " -h | --help this help message" echo " --virtualenv PATH set explicit path of virtualenv binary to use" echo " --update update to the newest master copy" return 1 ;; --update) python </dev/null || return 1 sed -r -e "s/^_venv_py3=.*/_venv_py3=$_venv_py3/" <"/tmp/$USER-py-env-update.py" >.env git diff .env || : echo ".env script update OK" return 0 ;; *) echo "WARNING: Ignored unknown option '$1'" ;; esac shift done # Outside the tree of the .env script? if pwd -P | egrep -v '^'$(dirname "$_venv_script")'($|/)' >/dev/null; then : echo Outside "[$0 $1 ; $_venv_script]" # Inside the tree of the .env script, but have another local '.env'? elif test \! -f .env -o "$_venv_script" != "$(pwd -P)/.env"; then : echo Inside "[$0 $1 ; $_venv_script]" # Only try virtualenv creation outside of template dirs; the egrep pattern is escaped for hiding it from Jinja2 elif pwd -P | egrep -v '/{''{''.*''}''}(/|$)' >/dev/null || $_venv_create; then test -f ".env" && _venv_ask=true || _venv_ask=false # Look for existing venv at common locations for _venv_base in .venv venv . ..; do if test -f "$_venv_base/$_venv_name/bin/activate"; then deactivate 2>/dev/null || : . "$_venv_base/$_venv_name/bin/activate" if test -f setup.py; then $_venv_develop && python setup.py -q develop -U || : python setup.py --name --version --url | tr \\n \\0 \ | xargs -0 printf "*** Activated %s %s @ %s\\n" || : else echo "*** Activated $_venv_base/$_venv_name" fi _venv_ask=false break fi done if $_venv_ask && test \! -d .venv; then $_venv_create || { read -p "No virtualenv found, shall I create one for you? [Y/n] " -n 1 -r || REPLY='n'; echo; } if $_venv_create || echo "$REPLY" | egrep '^[Yy]?$' >/dev/null; then # Create, activate, and update virtualenv $_venv_virtualenv ".venv/$_venv_name" . ".venv/$_venv_name/bin/activate" ".venv/$_venv_name/bin/pip" --log ".venv/install-pip.log" install -U "$_venv_pip_req" 2>&1 | _venv_pip_log \ || echo >&2 "!!! WARN: pip -U pip failed (RC=$?), see .venv/install-pip.log for details" ".venv/$_venv_name/bin/pip" --log ".venv/install-tools.log" install -U "setuptools>=14.3,<36" "wheel>=0.24.0" 2>&1 | _venv_pip_log \ || echo >&2 "!!! WARN: pip -U setuptools wheel failed (RC=$?), see .venv/install-tools.log for details" # Get rid of cruft some older systems produce ".venv/$_venv_name/bin/pip" --log ".venv/uninstall-distribute.log" uninstall --yes distribute >/dev/null 2>&1 || : # pypandoc fails when the base package is missing, so we install it here, if possible if which pandoc >/dev/null ; then ".venv/$_venv_name/bin/pip" --log ".venv/install-pandoc.log" install pypandoc 2>&1 | _venv_pip_log \ || echo >&2 "!!! WARN: pip install pypandoc failed (RC=$?), see .venv/install-pandoc.log for details" fi # Install development + project dependencies if test -f dev-requirements.txt; then ".venv/$_venv_name/bin/pip" --log ".venv/pip-install-dev.log" install -r dev-requirements.txt 2>&1 | _venv_pip_log \ || echo >&2 "!!! WARN: pip install dev-requirements failed (RC=$?), see .venv/pip-install-dev.log for details" fi if test -f setup.py; then if grep "^# mkvenv: no-deps" "setup.py" >/dev/null; then echo "*** Not installing setup.py packages as requested" else ".venv/$_venv_name/bin/python" setup.py develop -U 2>&1 | _venv_pip_log fi echo ".venv/$_venv_name/bin/python" setup.py --name --version --author --author-email --license --description --url \ | tr \\n \\0 | xargs -0 printf "%s %s by %s <%s> [%s]\\n%s\\n%s\\n" || : else echo if test -f requirements.txt; then echo "*** No 'setup.py' found, installing requirements..." ".venv/$_venv_name/bin/pip" --log ".venv/pip-install-req.log" install -r requirements.txt 2>&1 | _venv_pip_log else echo "*** No 'setup.py' or 'requirements.txt' found, all done." fi fi else # prevent constant prompting mkdir -p .venv fi fi fi unset _venv_script _venv_name _venv_ask _venv_create _venv_develop _venv_pip_log _venv_base _venv_py_tk unset _venv_readlink _venv_temp _venv_virtualenv _venv_verbose _venv_py3 _venv_pip_req _venv_master_url eval $_venv_xtrace # restore xtrace state unset _venv_xtrace .gitignore000066400000000000000000000005031374426432200130530ustar00rootroot00000000000000*.py[oc] # Temp files *~ ~* .*~ \#* .#* *# # Build files build/ dist/ dh_virtualenv.egg-info/ .tox # Sphinx build doc/_build # Generated man page doc/dh_virtualenv.1 # virtualenv local/ include/ man/ # buildpackage debian/*.debhelper debian/*.substvars debian/dh-virtualenv/ debian/files debian/debhelper-build-stamp .travis.yml000066400000000000000000000002171374426432200131760ustar00rootroot00000000000000language: python python: - "2.7" - "3.5" - "3.6" - "3.7" - "3.8" install: "pip install -r travis-requirements.txt" script: nosetests Dockerfile000066400000000000000000000031311374426432200130550ustar00rootroot00000000000000# Build dh-virtualenv's Debian package within a container for any platform # # docker build --tag dh-venv-builder --build-arg distro=debian:10 . # docker build --tag dh-venv-builder --build-arg distro=ubuntu:bionic . # # mkdir -p dist && command docker run --rm dh-venv-builder tar -C ../dpkg -c . | tar -C dist -xv # # Add '--build-arg opts=nodoc' to remove dependencies on Sphinx packages not available in older releases. ARG distro="debian:stable" ARG opts="" FROM ${distro} AS dpkg-build ENV DEB_BUILD_OPTIONS=${opts} RUN apt-get update -qq -o Acquire::Languages=none \ && env DEBIAN_FRONTEND=noninteractive apt-get install \ -yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \ build-essential debhelper devscripts equivs lsb-release libparse-debianchangelog-perl \ python3 python3-setuptools python3-pip python3-dev \ python3-sphinx python3-mock dh-exec dh-python python3-sphinx-rtd-theme \ && if test "$(lsb_release -cs)" = 'bionic' ; then \ apt-get install -yqq --no-install-recommends -o Dpkg::Options::=--force-unsafe-io \ -t bionic-backports debhelper; fi \ && apt-get clean && rm -rf "/var/lib/apt/lists"/* WORKDIR /dpkg-build COPY ./ ./ # The "chmod" call fixes '-rwxr-xr-x' permission problems you get when running this builder from Windows. RUN sed -i -re "1s/..unstable/~$(lsb_release -cs)) $(lsb_release -cs)/" debian/changelog \ && chmod a-x debian/dh-virtualenv.* \ && dpkg-buildpackage -us -uc -b && mkdir -p /dpkg && cp -pl /dh-virtualenv[-_]* /dpkg \ && dpkg-deb -I /dpkg/dh-virtualenv_*.deb LICENSE000066400000000000000000000432541374426432200121020ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. README.md000066400000000000000000000136571374426432200123600ustar00rootroot00000000000000# dh-virtualenv [![Build Status](https://travis-ci.org/spotify/dh-virtualenv.png)](https://travis-ci.org/spotify/dh-virtualenv) [![Docs](https://readthedocs.org/projects/dh-virtualenv/badge/)](http://dh-virtualenv.readthedocs.io/en/latest/) **Contents** * [Overview](#overview) * [Presentations, Blogs & Other Resources](#presentations-blogs--other-resources) * [Using dh-virtualenv](#using-dh-virtualenv) * [How does it work?](#how-does-it-work) * [Running tests](#running-tests) * [Building the package in a Docker container](#building-the-package-in-a-docker-container) * [Building the documentation locally](#building-the-documentation-locally) * [Releasing a new version](#releasing-a-new-version) * [Code of conduct](#code-of-conduct) * [License](#license) ## Overview dh-virtualenv is a tool that aims to combine Debian packaging with self-contained virtualenv based Python deployments. The idea behind dh-virtualenv is to be able to combine the power of Debian packaging with the sandboxed nature of virtualenvs. In addition to this, using virtualenv enables installing requirements via [Python Package Index](https://pypi.org) instead of relying on the operating system provided Python packages. The only limiting factor is that you have to run the same Python interpreter as the operating system. For complete online documentation including installation instructions, see [the online documentation](https://dh-virtualenv.readthedocs.io/en/latest/). ## Presentations, Blogs & Other Resources Here are a few external resources that can help you to get a more detailed first impression of dh-virtualenv, or advocate its use in your company or project team. * [How We Deploy Python Code](https://www.nylas.com/blog/packaging-deploying-python/) – Building, packaging & deploying Python using versioned artifacts in Debian packages at Nylas. * [DevOps Tool Bazaar](https://speakerdeck.com/jhermann/devops-karlsruhe-meetup-2018-02-20) – Slide deck presented at the DevOps Karlsruhe Meetup in February 2018, regarding Python software deployment for Debian with a practical example. * [The Architecture of Open Source Applications: Python Packaging](http://aosabook.org/en/packaging.html) – This provides a lot of background (and possibly things you didn't know) about the Python side of packaging. ## Using dh-virtualenv Using dh-virtualenv is fairly straightforward. First, you need to define the requirements of your package in `requirements.txt` file, in [the format defined by pip](https://pip.pypa.io/en/latest/user_guide.html#requirements-files). To build a package using dh-virtualenv, you need to add dh-virtualenv in to your build dependencies and write following `debian/rules` file: %: dh $@ --with python-virtualenv Note that you might need to provide additional build dependencies too, if your requirements require them. Also, you are able to define the root path for your source directory using `--sourcedirectory` or `-D` argument: %: dh $@ --with python-virtualenv --sourcedirectory=root/srv/application NOTE: Be aware that the configuration in debian/rules expects tabs instead of spaces! Once the package is built, you have a virtualenv contained in a Debian package and upon installation it gets placed, by default, under `/opt/venvs/`. For more information and usage documentation, check the accompanying documentation in the `doc` folder, also available at [Read the Docs](https://dh-virtualenv.readthedocs.io/en/latest/). ## How does it work? To do the packaging, *dh-virtualenv* extends debhelper's sequence by inserting a new `dh_virtualenv` command, which effectively replaces the following commands in the original sequence: * `dh_auto_clean` * `dh_auto_build` * `dh_auto_test` * `dh_auto_install` * `dh_python2` * `dh_pycentral` * `dh_pysupport` In the new sequence, `dh_virtualenv` is inserted right before `dh_installinit`. ## Running tests $ nosetests ./test/test_deployment.py ## Building the package in a Docker container To build ``dh-virtualenv`` itself in a Docker container, call ``docker build --tag dh-venv-builder .``. This will build the DEB package for Debian stable by default. Add e.g. ``--build-arg distro=ubuntu:bionic`` to build for Ubuntu LTS instead. The resulting files must be copied out of the build container, using these commands: ```sh mkdir -p dist && docker run --rm dh-venv-builder tar -C /dpkg -c . | tar -C dist -xv ``` There is also a short-cut for all this, in the form of ``invoke bdist_deb [--distro=‹id›:‹codename›]``. ## Building the documentation locally If you execute the following commands in your clone of the repository, a virtualenv with all necessary tools is created. ``invoke docs`` then builds the documentation into ``doc/_build/``. ```sh command . .env --yes --develop invoke docs ``` To **start a watchdog that auto-rebuilds documentation** and reloads the opened browser tab on any change, call ``invoke docs -w -b`` (stop the watchdog using the ``-k`` option). ## Releasing a new version Follow these steps when creating a new release: 1. Check version in `dh_virtualenv/_version.py` and `debian/changelog`. 1. Make sure `doc/changes.rst` is complete. 1. Bump release date in `debian/changelog` (`dch -r`). 1. Tag the release and `git push --tags`. 1. Edit release entry on GitHub (add changes). 1. Update the *Ubuntu PPA*. 1. Bump to next release version in `dh_virtualenv/_version.py`. 1. Open new section in `debian/changelog` (with `…-0.1+dev` added). 1. Open a new section in `doc/changes.rst`, so it can be maintained as features are added! ## Code of conduct This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code. ## License Copyright (c) 2013-2017 Spotify AB dh-virtualenv is licensed under GPL v2 or later. Full license is available in the `LICENSE` file. [code-of-conduct]: https://github.com/spotify/code-of-conduct/blob/master/code-of-conduct.md autoscripts/000077500000000000000000000000001374426432200134455ustar00rootroot00000000000000autoscripts/postinst-dh-virtualenv000066400000000000000000000051771374426432200200530ustar00rootroot00000000000000# dh-virtualenv postinst autoscript set -e #ARGS# # set to empty to enable verbose output test "${DH_VERBOSE:-0}" = "1" && DH_VENV_DEBUG="" || DH_VENV_DEBUG=: $DH_VENV_DEBUG set -x dh_venv_safe_interpreter_update() { # get Python version used local pythonX_Y=$(cd "$dh_venv_install_dir/lib" && ls -1d python[2-9].*[0-9] | tail -n1) local i for i in python ${pythonX_Y%.*} ${pythonX_Y}; do local interpreter_path="$dh_venv_install_dir/bin/$i" # skip any symlinks, and make sure we have an existing target test ! -L "$interpreter_path" || continue test -x "$interpreter_path" || continue # skip if already identical if cmp "/usr/bin/$pythonX_Y" "$interpreter_path" >/dev/null 2>&1; then continue fi # hardlink or copy new interpreter cp -fpl "/usr/bin/$pythonX_Y" "$interpreter_path,new" \ || cp -fp "/usr/bin/$pythonX_Y" "$interpreter_path,new" \ || rm -f "$interpreter_path,new" \ || true # make a backup (once) test -f "$interpreter_path,orig" || ln "$interpreter_path" "$interpreter_path,orig" # atomic move if test -x "$interpreter_path,new" && mv "$interpreter_path,new" "$interpreter_path"; then echo "Successfully updated $interpreter_path" else echo >&2 "WARNING: Some error occured while updating $interpreter_path" fi done } case "$1" in configure|reconfigure) $DH_VENV_DEBUG echo "$0 $1 called with $# args:" "$@" dh_venv_safe_interpreter_update ;; triggered) $DH_VENV_DEBUG echo "$0 $1 called with $# args:" "$@" for trigger in $2; do case "$trigger" in /usr/bin/python?.*) # this trigger might be for the "wrong" interpreter (other version), # but the "cmp" in "dh_venv_safe_interpreter_update" and the fact we only # ever look at our own Python version catches that dh_venv_safe_interpreter_update ;; dh-virtualenv-interpreter-update) dh_venv_safe_interpreter_update ;; *) #echo >&2 "ERROR:" $(basename "$0") "called with unknown trigger '$2'" #exit 1 ;; esac done ;; abort-upgrade|abort-remove|abort-deconfigure) ;; *) #echo >&2 "ERROR:" $(basename "$0") "called with unknown argument '$1'" #exit 1 ;; esac $DH_VENV_DEBUG set +x # END dh-virtualenv postinst autoscript autoscripts/prerm-dh-virtualenv000066400000000000000000000014111374426432200173000ustar00rootroot00000000000000# dh-virtualenv prerm autoscript set -e #ARGS# # set to empty to enable verbose output test "${DH_VERBOSE:-0}" = "1" && DH_VENV_DEBUG="" || DH_VENV_DEBUG=: $DH_VENV_DEBUG set -x case "$1" in remove|deconfigure) $DH_VENV_DEBUG echo "$0 $1 called with $# args:" "$@" rm -f "${dh_venv_install_dir:-/should_be_an_arg}/bin"/*,orig >/dev/null 2>&1 || true rm -f "${dh_venv_install_dir:-/should_be_an_arg}/lib"/python*/__pycache__/*.pyc >/dev/null 2>&1 || true ;; upgrade|failed-upgrade) $DH_VENV_DEBUG echo "$0 $1 called with $# args:" "$@" ;; *) #echo >&2 "ERROR:" $(basename "$0") "called with unknown argument '$1'" #exit 1 ;; esac $DH_VENV_DEBUG set +x # END dh-virtualenv prerm autoscript bin/000077500000000000000000000000001374426432200116355ustar00rootroot00000000000000bin/dh_virtualenv000077500000000000000000000071201374426432200144350ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2013-2014 Spotify AB # This file is part of dh-virtualenv. # dh-virtualenv is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 2 of the # License, or (at your option) any later version. # dh-virtualenv is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with dh-virtualenv. If not, see # . import inspect import logging import os import sys from dh_virtualenv import Deployment from dh_virtualenv.cmdline import get_default_parser from dh_virtualenv.debhelper import DebHelper logging.basicConfig(format='%(levelname).1s: %(module)s:%(lineno)d: ' '%(message)s') log = logging.getLogger(__name__) def _shell_vars(**kwargs): """Convert the given values into the equivalent shell snippet defining them.""" return '\n'.join("dh_venv_{0}='{1}'".format(k, v.replace("'", r"'\''")) for k, v in sorted(kwargs.items())) def main(): parser = get_default_parser() options, args = parser.parse_args() options.compile_all = False # for DebHelper.save() # TODO: Reduce redundancy with this and the Deployment.from_options verbose = options.verbose or os.environ.get('DH_VERBOSE') == '1' if verbose: log.setLevel(logging.DEBUG) if 'nocheck' in os.environ.get('DEB_BUILD_OPTIONS', ''): do_test = False else: do_test = options.setuptools_test # Older DebHelpers, like the one on Debian Squeeze, expect to be # passed the packages keyword argument. Newer (like Ubuntu # Precise) expect the whole options to be passed. arguments = inspect.getargspec(DebHelper.__init__).args if 'packages' in arguments: dh = DebHelper(packages=options.package or None) else: dh = DebHelper(options) if hasattr(sys, 'real_prefix'): log.error('Already in a virtualenv. This is likely to generate an ' 'invalid package (run "deactivate" first?)') return 1 for package, details in dh.packages.items(): def _info(msg): log.info('{0}: {1}'.format(package, msg)) _info('Processing package...') deploy = Deployment.from_options(package, options) if options.autoscripts: _info('Adding autoscripts...') dh.autoscript(package, 'postinst', 'postinst-dh-virtualenv', _shell_vars( package=package, install_dir=deploy.virtualenv_install_dir, )) dh.autoscript(package, 'prerm', 'prerm-dh-virtualenv', _shell_vars( package=package, install_dir=deploy.virtualenv_install_dir, )) _info('Creating virtualenv') deploy.create_virtualenv() _info('Installing dependencies') deploy.install_dependencies() _info('Installing package') deploy.install_package() if do_test: _info('Running tests') deploy.run_tests() else: _info('Skipped tests') _info('Fixing paths') deploy.fix_activate_path() deploy.fix_shebangs() deploy.fix_local_symlinks() _info('dh-virtualenv: All done!') dh.save() if __name__ == '__main__': sys.exit(main() or 0) debian/000077500000000000000000000000001374426432200123075ustar00rootroot00000000000000debian/changelog000066400000000000000000000035601374426432200141650ustar00rootroot00000000000000dh-virtualenv (1.2.2-1) unstable; urgency=medium * New upstream release (Closes: #970810) -- Jyrki Pulliainen Thu, 22 Oct 2020 13:39:46 +0300 dh-virtualenv (1.2.1-1) unstable; urgency=medium * New upstream release (Closes: #936392) -- Jyrki Pulliainen Sun, 19 Jul 2020 22:36:19 +0300 dh-virtualenv (1.2-1) unstable; urgency=medium * New upstream release (Closes: #936392) -- Jyrki Pulliainen Thu, 02 Jul 2020 21:26:02 +0300 dh-virtualenv (1.1-1) unstable; urgency=medium * New upstream release -- Jyrki Pulliainen Sun, 23 Sep 2018 12:50:10 +0200 dh-virtualenv (1.0-1) unstable; urgency=medium * New upstream release -- Jyrki Pulliainen Tue, 11 Oct 2016 10:36:35 +0200 dh-virtualenv (0.11-1) unstable; urgency=low * New upstream release -- Jyrki Pulliainen Tue, 29 Dec 2015 14:20:14 +0200 dh-virtualenv (0.10-1) unstable; urgency=low * New upstream release -- Jyrki Pulliainen Thu, 20 Aug 2015 13:00:55 +0200 dh-virtualenv (0.9-1) experimental; urgency=low * New upstream release -- Jyrki Pulliainen Mon, 09 Mar 2015 09:59:26 +0100 dh-virtualenv (0.8-1) experimental; urgency=low * New upstream release -- Jyrki Pulliainen Thu, 02 Oct 2014 10:06:32 +0200 dh-virtualenv (0.7-2) unstable; urgency=low * Fix virtualenv dependency. Closes: #751192 * Fix cleaning with dh_auto_clean -- Jyrki Pulliainen Wed, 11 Jun 2014 16:54:10 +0200 dh-virtualenv (0.7-1) unstable; urgency=low * New upstream release * Closes: #738964 -- Jyrki Pulliainen Sun, 18 May 2014 19:29:13 +0200 dh-virtualenv (0.6-1) unstable; urgency=low * Closes: #727620 -- Jyrki Pulliainen Fri, 10 Jan 2014 16:33:30 +0100 debian/control000066400000000000000000000021461374426432200137150ustar00rootroot00000000000000Source: dh-virtualenv Section: python Priority: optional Maintainer: Jyrki Pulliainen Build-Depends: debhelper-compat (= 12), python3, python3-setuptools, python3-sphinx, python3-mock, dh-exec, dh-python, libjs-jquery, libjs-underscore, # python-sphinx-rtd-theme doesn't exist in distributions # predating Debian Jessie and Ubuntu Xenial. On these legacy # systems: # 1. Comment the dependency below. # 2. pip install sphinx_rtd_theme. # 3. Proceed with your build process (typically dpkg-build). # See https://github.com/spotify/dh-virtualenv/issues/230 python3-sphinx-rtd-theme Standards-Version: 4.5.0 Homepage: https://www.github.com/spotify/dh-virtualenv Rules-Requires-Root: no Package: dh-virtualenv Architecture: all Depends: ${python3:Depends}, ${perl:Depends}, ${misc:Depends}, ${sphinxdoc:Depends}, virtualenv | python3-virtualenv (>= 1.7) | python${pyversion}-venv Built-Using: ${sphinxdoc:Built-Using} Description: wrap and build Python packages using virtualenv This package provides a dh sequencer that helps you to deploy your virtualenv wrapped installation inside a Debian package. debian/copyright000066400000000000000000000021441374426432200142430ustar00rootroot00000000000000Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: dh-virtualenv Upstream-Contact: Jyrki Pulliainen Source: https://www.github.com/spotify/dh-virtualenv Files: * Copyright: 2013 Spotify AB License: GPL-2+ Copyright (C) 2013 Spotify AB . This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. . Comment: . On a Debian system you can find a copy of this license in /usr/share/common-licenses/GPL-2. debian/dh-virtualenv.doc-base000066400000000000000000000004231374426432200164750ustar00rootroot00000000000000Document: dh-virtualenv Title: dh-virtualenv documentation Author: Spotify Abstract: This manual describes dh-virtualenv and how to use it. Section: Programming Format: HTML Index: /usr/share/doc/dh-virtualenv/html/index.html Files: /usr/share/doc/dh-virtualenv/html/*.html debian/dh-virtualenv.install000066400000000000000000000001231374426432200164630ustar00rootroot00000000000000lib/* usr/share/perl5 autoscripts/*-dh-virtualenv /usr/share/debhelper/autoscripts debian/dh-virtualenv.manpages000066400000000000000000000000241374426432200166100ustar00rootroot00000000000000doc/dh_virtualenv.1 debian/rules000077500000000000000000000012671374426432200133750ustar00rootroot00000000000000#!/usr/bin/make -f DH_ARGS ?= ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS))) DH_ARGS += --with sphinxdoc endif PYTHON_VERSION := $(shell python3 -c 'import sys; print("%s.%s" % sys.version_info[:2])') %: dh $@ --buildsystem=pybuild --with python3 $(DH_ARGS) override_dh_auto_clean: rm -rf doc/_build rm -f doc/dh_virtualenv.1 rm -rf dh_virtualenv.egg-info dh_auto_clean override_dh_auto_build: rst2man doc/dh_virtualenv.1.rst >doc/dh_virtualenv.1 dh_auto_build override_dh_gencontrol: dh_gencontrol -- -Vpyversion=$(PYTHON_VERSION) ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS))) override_dh_installdocs: python3 setup.py build_sphinx dh_installdocs doc/_build/html endif debian/source/000077500000000000000000000000001374426432200136075ustar00rootroot00000000000000debian/source/format000066400000000000000000000000131374426432200150140ustar00rootroot000000000000003.0 (quilt)debian/watch000066400000000000000000000002341374426432200133370ustar00rootroot00000000000000version=3 opts=filenamemangle=s/.+\/v?(\d\S*)\.tar\.gz/dh-virtualenv-$1.tar.gz/ \ https://github.com/spotify/dh-virtualenv/releases .*/v?(\d\S*)\.tar\.gz dev-requirements.txt000066400000000000000000000004631374426432200151300ustar00rootroot00000000000000# # Development requirements (tools) # # Developer tooling pip-upgrader invoke==0.13.0 rituals==0.4.1 #https://github.com/jhermann/rituals/archive/master.zip#egg=rituals # CI tooling -r travis-requirements.txt # Sphinx basics are in Travis requirements sphinx-autobuild==0.7.1 # Add project itself -e . dh_virtualenv/000077500000000000000000000000001374426432200137375ustar00rootroot00000000000000dh_virtualenv/__init__.py000066400000000000000000000014461374426432200160550ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2014 Spotify AB # This file is part of dh-virtualenv. # dh-virtualenv is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 2 of the # License, or (at your option) any later version. # dh-virtualenv is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with dh-virtualenv. If not, see # . from .deployment import Deployment # Make Flake8 happy assert Deployment dh_virtualenv/_version.py000066400000000000000000000005401374426432200161340ustar00rootroot00000000000000# -*- coding: utf-8 -*- """ Major Project Metadata. This file should be used to get the version and other metadata whenever technically possible, to reduce locations where this data has to be maintained redundantly. """ version = '1.2.2' author = u'Jyrki Pulliainen' author_email = 'jyrki@dywypi.org' url = 'https://github.com/spotify/dh-virtualenv' dh_virtualenv/cmdline.py000066400000000000000000000223621374426432200157310ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2014 Spotify AB # This file is part of dh-virtualenv. # dh-virtualenv is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 2 of the # License, or (at your option) any later version. # dh-virtualenv is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with dh-virtualenv. If not, see # . """Helpers to handle debhelper command line options.""" from __future__ import absolute_import import os import warnings from optparse import OptionParser, SUPPRESS_HELP, OptionValueError from ._version import version class DebhelperOptionParser(OptionParser): """Special OptionParser for handling Debhelper options. Basically this means converting -O--option to --option before parsing. """ def parse_args(self, args=None, values=None): args = [o[2:] if o.startswith('-O-') else o for o in self._get_args(args)] args.extend(os.environ.get('DH_OPTIONS', '').split()) # Unfortunately OptionParser is an old style class :( return OptionParser.parse_args(self, args, values) def _check_for_deprecated_options( option, opt_str, value, parser, *args, **kwargs): # TODO: If more deprectaed options pop up, refactor this method to # handle them in more generic way (or actually remove the # deprecated options) if opt_str in ('--pypi-url', '--index-url'): if opt_str == '--pypi-url': # Work around 2.7 hiding the DeprecationWarning with warnings.catch_warnings(): warnings.simplefilter('default') warnings.warn('Use of --pypi-url is deprecated. Use ' '--index-url instead', DeprecationWarning) if parser.values.index_url: # We've already set the index_url, which means that we have both # --index-url and --pypi-url passed in. raise OptionValueError('Deprecated --pypi-url and the new ' '--index-url are mutually exclusive') parser.values.index_url = value elif opt_str in ('--no-test', '--setuptools-test'): if opt_str == '--no-test': with warnings.catch_warnings(): warnings.simplefilter('default') warnings.warn('Use of --no-test is deprecated and has no ' 'effect. Use --setuptools-test if you want to ' 'execute `setup.py test` during package build.', DeprecationWarning) if getattr(parser.values, '_test_flag_seen', None): raise OptionValueError('Deprecated --no-test and the new ' '--setuptools-test are mutually exclusive') parser.values.setuptools_test = opt_str != '--no-test' setattr(parser.values, '_test_flag_seen', True) def get_default_parser(): usage = '%prog [options]' parser = DebhelperOptionParser(usage, version='%prog ' + version) parser.add_option('-p', '--package', action='append', metavar='PACKAGE', help='Act on the package(s) named PACKAGE') parser.add_option('-N', '--no-package', action='append', metavar='PACKAGE', help='Do not act on the specified package(s)') parser.add_option('-v', '--verbose', action='store_true', default=False, help='Turn on verbose mode') parser.add_option('-s', '--setuptools', action='store_true', default=False, help='Use Setuptools instead of Distribute') parser.add_option('--extra-index-url', action='append', metavar='URL', help='Extra index URL(s) to pass to pip.', default=[]) parser.add_option('--preinstall', action='append', metavar='PACKAGE', help=('Package(s) to install before processing ' 'requirements.txt.'), default=[]) parser.add_option('--extras', action='append', metavar='NAME', help=('Activate one or more extras of the main package.'), default=[]) parser.add_option('--pip-tool', default='pip', metavar='EXECUTABLE', help="Executable that will be used to install " "requirements after the preinstall stage. Usually " "you'll install this program by using the --preinstall " "argument. The replacement is expected to be found in " "the virtualenv's bin/ directory.") parser.add_option('--upgrade-pip', action='store_true', default=False, help='Upgrade pip to the latest available version') parser.add_option('--upgrade-pip-to', default='', metavar='VERSION', help='Upgrade pip to a specific version') parser.add_option('--extra-pip-arg', action='append', metavar='ARG', help='One or more extra args for the pip binary.' 'You can use this flag multiple times to pass in' ' parameters to pip.', default=[]) parser.add_option('--extra-virtualenv-arg', action='append', metavar='ARG', help='One or more extra args for the virtualenv binary.' 'You can use this flag multiple times to pass in' ' parameters to the virtualenv binary.', default=[]) parser.add_option('--index-url', metavar='URL', help='Base URL of the PyPI server', action='callback', type='string', dest='index_url', callback=_check_for_deprecated_options) parser.add_option('--python', metavar='EXECUTABLE', help='The Python command to use') parser.add_option('--builtin-venv', action='store_true', help='Use the built-in venv module. Only works on ' 'Python 3.4 and later.') parser.add_option('-D', '--sourcedirectory', dest='sourcedirectory', help='The source directory') parser.add_option('-n', '--noscripts', action='store_false', dest='autoscripts', help="Do not modify postinst and similar scripts.", default=True) parser.add_option('-S', '--use-system-packages', action='store_true', dest='use_system_packages', help="Set the --system-site-packages flag in virtualenv " "creation, allowing you to use system packages.", default=False) parser.add_option('--skip-install', action='store_true', default=False, dest='skip_install', help="Skip running pip install within the source directory.") parser.add_option('--install-suffix', metavar='DIRNAME', dest='install_suffix', help="Override installation path suffix") parser.add_option('--requirements', metavar='FILEPATH', dest='requirements_filename', help='Specify the filename for requirements.txt', default='requirements.txt') parser.add_option('--setuptools-test', dest='setuptools_test', default=False, action='callback', help='Run `setup.py test` when building the package', callback=_check_for_deprecated_options) # Ignore user-specified option bundles parser.add_option('-O', help=SUPPRESS_HELP) parser.add_option('-a', '--arch', dest="arch", help=("Act on architecture dependent packages that " "should be built for the build architecture. " "This option is ignored"), action="store", type="string") parser.add_option('-i', '--indep', dest="indep", help=("Act on all architecture independent packages. " "This option is ignored"), action="store_true") # Deprecated options parser.add_option('--pypi-url', metavar='URL', help=('!!DEPRECATED, use --index-url instead!! ' 'Base URL of the PyPI server'), action='callback', dest='index_url', type='string', callback=_check_for_deprecated_options) parser.add_option('--no-test', help="!!DEPRECATED, this command has no effect. " "See --setuptools-test!! " "Don't run tests for the package. Useful " "for example when you have packaged with distutils.", action='callback', callback=_check_for_deprecated_options) return parser dh_virtualenv/debhelper.py000066400000000000000000000211551374426432200162470ustar00rootroot00000000000000# -*- coding: UTF-8 -*- # Copyright © 2010-2012 Piotr Ożarowski # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. import logging from os import makedirs, chmod from os.path import exists, join, dirname log = logging.getLogger(__name__) class DebHelper(object): """Reinvents the wheel / some dh functionality (Perl is ugly ;-P)""" def __init__(self, options): self.options = options self.packages = {} self.python_version = None source_section = True binary_package = None pkgs = options.package skip_pkgs = options.no_package try: fp = open('debian/control', 'r') except IOError: raise Exception('cannot find debian/control file') xspv = xpv = False for line in fp: if not line.strip(): source_section = False binary_package = None continue if binary_package: if binary_package.startswith('python3'): continue if pkgs and binary_package not in pkgs: continue if skip_pkgs and binary_package in skip_pkgs: continue if line.startswith('Architecture:'): arch = line[13:].strip() # TODO: if arch doesn't match current architecture: #del self.packages[binary_package] self.packages[binary_package]['arch'] = arch continue elif line.startswith('Package:'): binary_package = line[8:].strip() if binary_package.startswith('python3'): log.debug('skipping Python 3.X package: %s', binary_package) continue if pkgs and binary_package not in pkgs: continue if skip_pkgs and binary_package in skip_pkgs: continue self.packages[binary_package] = {'substvars': {}, 'autoscripts': {}, 'rtupdates': [], 'arch': 'any'} elif line.startswith('Source:'): self.source_name = line[7:].strip() elif source_section: if line.lower().startswith('xs-python-version:'): xspv = True if not self.python_version: self.python_version = line[18:].strip() if line.lower().startswith('x-python-version:'): xpv = True self.python_version = line[17:].strip() if xspv and xpv: log.error('Please remove XS-Python-Version from debian/control') log.debug('source=%s, binary packages=%s', self.source_name, \ list(self.packages.keys())) def addsubstvar(self, package, name, value): """debhelper's addsubstvar""" self.packages[package]['substvars'].setdefault(name, []).append(value) def autoscript(self, package, when, template, args): """debhelper's autoscript""" self.packages[package]['autoscripts'].setdefault(when, {})\ .setdefault(template, []).append(args) def add_rtupdate(self, package, value): self.packages[package]['rtupdates'].append(value) def save_autoscripts(self): for package, settings in self.packages.items(): autoscripts = settings.get('autoscripts') if not autoscripts: continue for when, templates in autoscripts.items(): fn = "debian/%s.%s.debhelper" % (package, when) if exists(fn): data = open(fn, 'r').read() else: data = '' new_data = '' for tpl_name, args in templates.items(): for i in args: # try local one first (useful while testing dh_python2) fpath = join(dirname(__file__), '..', "autoscripts/%s" % tpl_name) if not exists(fpath): fpath = "/usr/share/debhelper/autoscripts/%s" % tpl_name tpl = open(fpath, 'r').read() if self.options.compile_all and args: # TODO: should args be checked to contain dir name? tpl = tpl.replace('#PACKAGE#', '') else: tpl = tpl.replace('#PACKAGE#', package) tpl = tpl.replace('#ARGS#', i) if tpl not in data and tpl not in new_data: new_data += "\n%s" % tpl if new_data: data += "\n# Automatically added by dh_python2:" +\ "%s\n# End automatically added section\n" % new_data fp = open(fn, 'w') fp.write(data) fp.close() def save_substvars(self): for package, settings in self.packages.items(): substvars = settings.get('substvars') if not substvars: continue fn = "debian/%s.substvars" % package if exists(fn): data = open(fn, 'r').read() else: data = '' for name, values in substvars.items(): p = data.find("%s=" % name) if p > -1: # parse the line and remove it from data e = data[p:].find('\n') line = data[p + len("%s=" % name):\ p + e if e > -1 else None] items = [i.strip() for i in line.split(',') if i] if e > -1 and data[p + e:].strip(): data = "%s\n%s" % (data[:p], data[p + e:]) else: data = data[:p] else: items = [] for j in values: if j not in items: items.append(j) if items: if data: data += '\n' data += "%s=%s\n" % (name, ', '.join(items)) data = data.replace('\n\n', '\n') if data: fp = open(fn, 'w') fp.write(data) fp.close() def save_rtupdate(self): for package, settings in self.packages.items(): pkg_arg = '' if self.options.compile_all else "-p %s" % package values = settings.get('rtupdates') if not values: continue d = "debian/%s/usr/share/python/runtime.d" % package if not exists(d): makedirs(d) fn = "%s/%s.rtupdate" % (d, package) if exists(fn): data = open(fn, 'r').read() else: data = "#! /bin/sh\nset -e" for dname, args in values: cmd = 'if [ "$1" = rtupdate ]; then' +\ "\n\tpyclean %s %s" % (pkg_arg, dname) +\ "\n\tpycompile %s %s %s\nfi" % (pkg_arg, args, dname) if cmd not in data: data += "\n%s" % cmd if data: fp = open(fn, 'w') fp.write(data) fp.close() chmod(fn, 0o755) def save(self): self.save_substvars() self.save_autoscripts() self.save_rtupdate() dh_virtualenv/deployment.py000066400000000000000000000275771374426432200165130ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2013 - 2014 Spotify AB # This file is part of dh-virtualenv. # dh-virtualenv is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 2 of the # License, or (at your option) any later version. # dh-virtualenv is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with dh-virtualenv. If not, see # . import os import re import shutil import subprocess import tempfile ROOT_ENV_KEY = 'DH_VIRTUALENV_INSTALL_ROOT' DEFAULT_INSTALL_DIR = '/opt/venvs/' PYTHON_INTERPRETERS = ['python', 'pypy', 'ipy', 'jython'] _PYTHON_INTERPRETERS_REGEX = r'\(' + r'\|'.join(PYTHON_INTERPRETERS) + r'\)' class Deployment(object): def __init__(self, package, extra_urls=[], preinstall=[], extras=[], pip_tool='pip', upgrade_pip=False, index_url=None, setuptools=False, python=None, builtin_venv=False, sourcedirectory=None, verbose=False, extra_pip_arg=[], extra_virtualenv_arg=[], use_system_packages=False, skip_install=False, install_suffix=None, requirements_filename='requirements.txt', upgrade_pip_to='', ): self.package = package install_root = os.environ.get(ROOT_ENV_KEY, DEFAULT_INSTALL_DIR) self.install_suffix = install_suffix self.debian_root = os.path.join( 'debian', package, install_root.lstrip('/')) if install_suffix is None: self.virtualenv_install_dir = os.path.join(install_root, self.package) self.package_dir = os.path.join(self.debian_root, package) else: self.virtualenv_install_dir = os.path.join(install_root, install_suffix) self.package_dir = os.path.join(self.debian_root, install_suffix) self.bin_dir = os.path.join(self.package_dir, 'bin') self.local_bin_dir = os.path.join(self.package_dir, 'local', 'bin') self.preinstall = preinstall self.extras = extras self.upgrade_pip = upgrade_pip self.upgrade_pip_to = upgrade_pip_to self.extra_virtualenv_arg = extra_virtualenv_arg self.log_file = tempfile.NamedTemporaryFile() self.verbose = verbose self.setuptools = setuptools self.python = python self.builtin_venv = builtin_venv self.sourcedirectory = '.' if sourcedirectory is None else sourcedirectory self.use_system_packages = use_system_packages self.skip_install = skip_install self.requirements_filename = requirements_filename # We need to prefix the pip run with the location of python # executable. Otherwise it would just blow up due to too long # shebang-line. python = self.venv_bin('python') self.pip_preinstall_prefix = [python, self.venv_bin('pip')] self.pip_prefix = [python, self.venv_bin(pip_tool)] self.pip_args = ['install'] if self.verbose: self.pip_args.append('-v') if index_url: self.pip_args.append('--index-url={0}'.format(index_url)) self.pip_args.extend([ '--extra-index-url={0}'.format(url) for url in extra_urls ]) self.pip_args.append('--log={0}'.format(os.path.abspath(self.log_file.name))) # Keep a copy with well-suported options only (for upgrading pip itself) self.pip_upgrade_args = self.pip_args[:] # Add in any user supplied pip args self.pip_args.extend(extra_pip_arg) @classmethod def from_options(cls, package, options): verbose = options.verbose or os.environ.get('DH_VERBOSE') == '1' return cls(package, extra_urls=options.extra_index_url, preinstall=options.preinstall, extras=options.extras, pip_tool=options.pip_tool, upgrade_pip=options.upgrade_pip, index_url=options.index_url, setuptools=options.setuptools, python=options.python, builtin_venv=options.builtin_venv, sourcedirectory=options.sourcedirectory, verbose=verbose, extra_pip_arg=options.extra_pip_arg, extra_virtualenv_arg=options.extra_virtualenv_arg, use_system_packages=options.use_system_packages, skip_install=options.skip_install, install_suffix=options.install_suffix, requirements_filename=options.requirements_filename, upgrade_pip_to=options.upgrade_pip_to, ) def clean(self): shutil.rmtree(self.debian_root) def create_virtualenv(self): # Specify interpreter and virtual environment options if self.builtin_venv: virtualenv = [self.python, '-m', 'venv'] if self.use_system_packages: virtualenv.append('--system-site-packages') else: virtualenv = ['virtualenv'] if self.use_system_packages: virtualenv.append('--system-site-packages') if self.python: virtualenv.extend(('--python', self.python)) if self.setuptools: virtualenv.append('--setuptools') if self.verbose: virtualenv.append('--verbose') # Add in any user supplied virtualenv args if self.extra_virtualenv_arg: virtualenv.extend(self.extra_virtualenv_arg) virtualenv.append(self.package_dir) subprocess.check_call(virtualenv) # Due to Python bug https://bugs.python.org/issue24875 # venv doesn't bootstrap pip/setuptools in the virtual # environment with --system-site-packages . # The workaround is to reconfigure it with this option # after it has been created. if self.builtin_venv and self.use_system_packages: virtualenv.append('--system-site-packages') subprocess.check_call(virtualenv) def venv_bin(self, binary_name): return os.path.abspath(os.path.join(self.bin_dir, binary_name)) def pip_preinstall(self, *args): return self.pip_preinstall_prefix + self.pip_args + list(args) def pip(self, *args): return self.pip_prefix + self.pip_args + list(args) def install_dependencies(self): # Install preinstall stage packages. This is handy if you need # a custom package to install dependencies (think something # along lines of setuptools), but that does not get installed # by default virtualenv. if self.upgrade_pip or self.upgrade_pip_to: # First, bootstrap pip with a reduced option set (well-supported options) cmd = self.pip_preinstall_prefix + self.pip_upgrade_args if not self.upgrade_pip_to or self.upgrade_pip_to == 'latest': cmd += ['-U', 'pip'] else: cmd += ['pip==' + self.upgrade_pip_to] subprocess.check_call(cmd) if self.preinstall: subprocess.check_call(self.pip_preinstall(*self.preinstall)) requirements_path = os.path.join(self.sourcedirectory, self.requirements_filename) if os.path.exists(requirements_path): subprocess.check_call(self.pip('-r', requirements_path)) def run_tests(self): python = self.venv_bin('python') setup_py = os.path.join(self.sourcedirectory, 'setup.py') if os.path.exists(setup_py): subprocess.check_call([python, 'setup.py', 'test'], cwd=self.sourcedirectory) def find_script_files(self): """Find list of files containing python shebangs in the bin directory""" command = ['grep', '-l', '-r', '-e', r'^#!.*bin/\(env \)\?{0}'.format(_PYTHON_INTERPRETERS_REGEX), '-e', r"^'''exec.*bin/{0}".format(_PYTHON_INTERPRETERS_REGEX), self.bin_dir] grep_proc = subprocess.Popen(command, stdout=subprocess.PIPE) files, stderr = grep_proc.communicate() return set(f for f in files.decode('utf-8').strip().split('\n') if f) def fix_shebangs(self): """Translate /usr/bin/python and /usr/bin/env python shebang lines to point to our virtualenv python. """ pythonpath = os.path.join(self.virtualenv_install_dir, 'bin/python') for f in self.find_script_files(): regex = (r's-^#!.*bin/\(env \)\?{names}\"\?-#!{pythonpath}-;' r"s-^'''exec'.*bin/{names}-'''exec' {pythonpath}-" ).format(names=_PYTHON_INTERPRETERS_REGEX, pythonpath=re.escape(pythonpath)) p = subprocess.Popen( ['sed', '-i', regex, f], stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) subprocess.check_call(['sed', '-i', regex, f]) def fix_activate_path(self): """Replace the `VIRTUAL_ENV` path in bin/activate to reflect the post-install path of the virtualenv. """ activate_settings = [ [ 'VIRTUAL_ENV="{0}"'.format(self.virtualenv_install_dir), r'^VIRTUAL_ENV=.*$', "activate" ], [ 'setenv VIRTUAL_ENV "{0}"'.format(self.virtualenv_install_dir), r'^setenv VIRTUAL_ENV.*$', "activate.csh" ], [ 'set -gx VIRTUAL_ENV "{0}"'.format(self.virtualenv_install_dir), r'^set -gx VIRTUAL_ENV.*$', "activate.fish" ], ] for activate_args in activate_settings: virtualenv_path = activate_args[0] pattern = re.compile(activate_args[1], flags=re.M) activate_file = activate_args[2] with open(self.venv_bin(activate_file), 'r+') as fh: content = pattern.sub(virtualenv_path, fh.read()) fh.seek(0) fh.truncate() fh.write(content) def install_package(self): if not self.skip_install: package = '.[{}]'.format(','.join(self.extras)) if self.extras else '.' subprocess.check_call(self.pip(package), cwd=os.path.abspath(self.sourcedirectory)) def fix_local_symlinks(self): # The virtualenv might end up with a local folder that points outside the package # Specifically it might point at the build environment that created it! # Make those links relative # See https://github.com/pypa/virtualenv/commit/5cb7cd652953441a6696c15bdac3c4f9746dfaa1 local_dir = os.path.join(self.package_dir, "local") if not os.path.isdir(local_dir): return elif os.path.samefile(self.package_dir, local_dir): # "local" points directly to its containing directory os.unlink(local_dir) os.symlink(".", local_dir) return for d in os.listdir(local_dir): path = os.path.join(local_dir, d) if not os.path.islink(path): continue existing_target = os.readlink(path) if not os.path.isabs(existing_target): # If the symlink is already relative, we don't # want to touch it. continue new_target = os.path.relpath(existing_target, local_dir) os.unlink(path) os.symlink(new_target, path) doc/000077500000000000000000000000001374426432200116325ustar00rootroot00000000000000doc/Makefile000066400000000000000000000127301374426432200132750ustar00rootroot00000000000000# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = _build # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: -rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/dh-virtualenv.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/dh-virtualenv.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/dh-virtualenv" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/dh-virtualenv" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." doc/_static/000077500000000000000000000000001374426432200132605ustar00rootroot00000000000000doc/_static/css/000077500000000000000000000000001374426432200140505ustar00rootroot00000000000000doc/_static/css/custom.css000066400000000000000000000001541374426432200160740ustar00rootroot00000000000000/* Custom styles */ body { color: black; } blockquote.epigraph { transform: skew(-15deg, 0deg); } doc/_static/img/000077500000000000000000000000001374426432200140345ustar00rootroot00000000000000doc/_static/img/logo-180px.png000066400000000000000000000110671374426432200163650ustar00rootroot00000000000000PNG  IHDR=2sBIT|d pHYstEXtSoftwarewww.inkscape.org<IDATx}՝?X|m/ėMvWQTF좒΂Q*mSV]8/}TY٦/iLl * X!Pa8sQy=3gICyޙ/יssFڵ Cy[Qmſεuztg1t9[>%w+ vҦ3%n#YI:U1Dڭ@ F;Jm%K%nS;cG[I\Gڭp p3p^m%_ G$\o%1]` VxxBIz[~U?<;uuVl/y,m0&Vxp0߲Ɋm$Cn!g\a%&E1n3ZKo%RW@SZ^X~Ea =v+X8H \ VP-.C[ɈU)gT }ov+<p)b9ݲUQI_  Uk:`Z*E~pj-%ak&+C%t+}L7n >WI/U  ]C Vf ng"H>ZKMx j!e%uEf ]&:\LNLRa ua!b }CU2nI.c|`m)ڄ fR ]DLнa0 h/@ۭ ZؠkYV2 X WBmZمK{nI9 M%G$-xi`eR8ư,3CEVx b,}0C?R+ ^+{JW ۭpp+pdeTJ|}kq43(L۵[ᩈx% eGDi+ko*>x!剪 5[!x_Q+ɺT ;[@|VðVOS\2J`t3'ɝ^Oz$h%l` )L`VΝFx+z})[cZJǁ Fo bBqo;sOuMЮOGw 4>["W}̺a"ǼFj\2Oκ:" Us{|`߽T-/]`_YJ7$ L^Yk:J%j7f({_~~$XCxU-^ĵW\[ygȝ5Q7ϒYJV[6c%|+ J;)ߐZw/Tgp 2 [I 8 qhaxlF\Sk(WBY/CWĜO{{ Fl{̺(b;uRξR¡8׏OYJuVLjkx8J%T{ۭ{Bߺ~|Rҵ`16L3@qm;&w~|jC8gb`3d`SEjT+ I?F"wf ظYCw8K\?>Ffa+ Al`35GC,~AzDUj҂4>. LY,G/;:}JjiKP| ~|Vb%Yy2kׄ7$83إ?<3D] V~|R,8׺>m;9{s rF%SwC|1'׏,l%&+ .&S>kl%ϝiRk@ s\?^ԃ$xqZ5^; 9Y qA]_ -D I{9Rk^ P&5O~,u S9ܞ99lDhRQF{Ѓ\8< V8B]ΆY6@L$J`?ᄀ"2 [I _Y{ L<}a~|Y{͜U6(/9ܹ iN0L 1JmV\XBOe )bJ'JZ b+]?^ksO"mEӤ;'wvk:6Z4>.[DZ$X/ wF#U8Pjr¡81 ~,l%z+ f cz9n5l+ f`fqP4=0 \?>Xfa+ 0f_ԐGL,~}A?睋h&8Gfa+ XI#NznD(J9\ՇQ#/vh$+=m 3Yybijx[6~x)͈|n/ss:)%V*s"t)#@"~)4~gȓ?n`%ȮMLDd/N^[]zl% d s8M#OB% 4\g1K9̝c̱2׏~ˑFki |X/&xivi= wNy4N#RKee5_..sJV=`W۪P !+[)L#4j\2V_ήޭjʗ{)3Y7`vv&vRՃ+r 0x@tbg4F4fSUj1ċl6vQZ{]؎gk`Ԯ]TkwI#FRRy vFz0i&o)c(o!ͤjhh4vwqj=,B݃4t4H#o&UL3J^P-㨵;L`b95-U-f84а D3Jz1Fs)b ` ڞ=ZHiaw3xi&DV*i;h&i&"tN^h;vL3H؉f#@ Cfif image/svg+xml doc/api/000077500000000000000000000000001374426432200124035ustar00rootroot00000000000000doc/api/dh_virtualenv.rst000066400000000000000000000007461374426432200160160ustar00rootroot00000000000000dh\_virtualenv package ====================== .. automodule:: dh_virtualenv :members: :undoc-members: :show-inheritance: Submodules ---------- dh\_virtualenv\.cmdline module ------------------------------ .. automodule:: dh_virtualenv.cmdline :members: :undoc-members: :show-inheritance: dh\_virtualenv\.deployment module --------------------------------- .. automodule:: dh_virtualenv.deployment :members: :undoc-members: :show-inheritance: doc/api/modules.rst000066400000000000000000000001141374426432200146010ustar00rootroot00000000000000dh_virtualenv ============= .. toctree:: :maxdepth: 4 dh_virtualenv doc/changes.rst000066400000000000000000000171271374426432200140040ustar00rootroot00000000000000=========== Changelog =========== Following list contains the most notable changes by version. For a full list, consult the `git history`_ of the project. .. _`git history`: https://github.com/spotify/dh-virtualenv/commits/master 1.2.2 ===== * Bugfix release: Addresses removal of python3-venv on Debian testing/sid 1.2.1 ===== * Bugfix release: Fixes a binary dependency to depend on Python 3 version of virtualenv 1.2 === * Requires Python 3 to build (`#300 `_) [`@richvdh `_] * Removed deprecated / disappeared virtualenv option (`#293 `_) [`@jhermann `_] * Add support for DEB_BUILD_OPTIONS=nodoc (`#289 `_) [`@mgagne `_] * Support venv options for builtin venv (`#276 `_) [`@paulbovbel `_] * New option :option:`--upgrade-pip-to` for increased build stability (#266) [`@jhermann `_] 1.1 === * Support new style shebangs generated by recent pip (`#226 `_) [`@nailor `_] * Add :option:`--extras` option (`#243 `_) [`@jhermann `_] * Python 3.4 and 3.5 added to test environments (`#238 `_) [`@jhermann `_] * New build dependendcies (dh-exec + python-sphinx-rtd-theme) (`#231 `_) [`@labeneator `_] * Disallow building a package whilst within an activated virtualenv (`#224 `_) [`@lamby `_] * Use ``python -m pip`` instead of direct pip calls (`#219 `_) [`@moritz `_] * Ignore :option:`--extra-pip-arg` in call for :option:`--upgrade-pip` (`#197 `_) [`@jhermann `_] * buildsystem: Allow to specify a virtualenv name (`#180 `_) [`@dzen `_] * docs: Improved structure, new chapters [`@jhermann `_] * docs: Fix reference to pbuilder's USENETWORK option (`#246 `_) [`@mkohler `_] * Fix setuptools and pip setup when using built-in virtualenv with `--system-site-packages` (`#247 `_) [`@lucasrangit `_] 1.0 === * **Backwards incompatible** Change the default install root to ``/opt/venvs``. This is due to the old installation root (``/usr/share/python``) clashing with Debian provided Python utilities. To maintain the old install location, use :envvar:`DH_VIRTUALENV_INSTALL_ROOT` and point it to ``/usr/share/python``. * **Backwards incompatible** By default, do not run `setup.py test` upon building. The :option:`--no-test` flag has no longer has any effect. To get the old behaviour, use the :option:`--setuptools-test` flag instead. * **Backwards incompatible** Buildsystem: Move files into build folder in install step instead of build step. Thanks to `Ludwig Hähne `_ for the patch! * Deprecate :option:`--pypi-url` in favour of :option:`--index-url` * Support upgrading pip to the latest release with :option:`--upgrade-pip` flag. * Buildsystem: Add support for :envvar:`DH_UPGRADE_PIP`, :envvar:`DH_UPGRADE_SETUPTOOLS` and :envvar:`DH_UPGRADE_WHEEL`. Thanks to `Kris Kvilekval `_ for the implementation! * Buildsystem: Add support for custom requirements file location using :envvar:`DH_REQUIREMENTS_FILE` and for custom ``pip`` command line arguments using :envvar:`DH_PIP_EXTRA_ARGS`. Thanks to `Einar Forselv `_ for implementing! * Fixing shebangs now supports multiple interpreters. Thanks `Javier Santacruz `_! * Allow a custom pip executable via :option:`--pip-tool` flag. Thanks `Anthony Sottile `_ for the implementation! * Fix handling of shebang lines for cases where interpreter was wrapped in quotes. Thanks to `Kamil Niechajewicz `_ for fixing! * Support extra arguments to be passed at virtualenv using :option:`--extra-virtualenv-arg`. Thanks to `Julien Duponchelle `_ for the fix. 0.11 ==== * Allow passing explicit filename for `requirements.txt` using :option:`--requirements` option. Thanks to `Eric Larson `_ for implementing! * Ensure that venv is configured before starting any daemons. Thanks to `Chris Lamb `_ for fixing this! * Make sure `fix_activate_path` updates all activate scripts. Thanks to `walrusVision `_ for fixing this! 0.10 ==== * **Backwards incompatible** Fix installation using the built-in virtual environment on 3.4. This might break installation on Python versions prior to 3.4 when using :option:`--builtin-venv` flag. Thanks to `Elonen `_ for fixing! * Honor :envvar:`DH_VIRTUALENV_INSTALL_ROOT` in build system. Thanks to `Ludwig Hähne `_ for implementing! * Allow overriding virtualenv arguments by using the :envvar:`DH_VIRTUALENV_ARGUMENTS` environment variable when using the build system. Thanks to `Ludwig Hähne `_ for implementing! * Add option to skip installation of the actual project. In other words using :option:`--skip-install` installs only the dependencies of the project found in requirements.txt. Thanks to `Phillip O'Donnell `_ for implementing! * Support custom installation suffix instead of the package name via :option:`--install-suffix`. Thanks to `Phillip O'Donnell `_ for implementing! 0.9 === * Support using system packages via a command line flag :option:`--use-system-packages`. Thanks to `Wes Mason `_ for implementing this feature! * Introduce a new, experimental, more modular build system. See the :doc:`usage` for documentation. * Respect the :envvar:`DEB_NO_CHECK` environment variable. 0.8 === * Support for running triggers upon host interpreter update. This new feature makes it possible to upgrade the host Python interpreter and avoid breakage of all the virtualenvs installed with dh-virtualenv. For usage, see the the :doc:`tutorial`. Huge thanks to `Jürgen Hermann `_ for implementing this long wanted feature! * Add support for the built-in ``venv`` module. Thanks to `Petri Lehtinen `_! * Allow custom ``pip`` flags to be passed via the :option:`--extra-pip-arg` flag. Thanks to `@labeneator `_ for the feature. 0.7 === * **Backwards incompatible** Support running tests. This change breaks builds that use distutils. For those cases a flag :option:`--no-test` needs to be passed. * Add tutorial to documentation * Don't crash on debbuild parameters ``-i`` and ``-a`` * Support custom source directory (debhelper's flag ``-D``) 0.6 === First public release of *dh-virtualenv* doc/conf.py000066400000000000000000000211771374426432200131410ustar00rootroot00000000000000# -*- coding: utf-8 -*- # # dh-virtualenv documentation build configuration file, created by # sphinx-quickstart on Wed Feb 20 17:29:43 2013. # # This file is execfile()d with the current directory set to its containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import os import re import sys # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. sys.path.insert(0, os.path.abspath("..")) from setup import project as meta on_rtd = os.environ.get('READTHEDOCS', None) == 'True' if not on_rtd: import sphinx_rtd_theme # https://docs.readthedocs.io/en/latest/guides/adding-custom-css.html def setup(app): app.add_stylesheet('css/custom.css') #app.add_javascript('js/custom.js') # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.coverage', 'sphinx.ext.ifconfig', 'sphinx.ext.viewcode', 'sphinx.ext.napoleon', ] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = '.rst' # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = meta["name"] copyright = u'2013-2018 Spotify AB and contributors' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # The full version, including alpha/beta/rc tags. release = meta["version"] # The short X.Y version. version = '.'.join(re.split("[^\d]+", release)[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. today_fmt = '%Y-%m-%d' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = [ '*~', '_build', 'LICENSE.rst', 'README.rst', 'modules.rst', 'dh_virtualenv.1.rst', 'api/modules.rst', ] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # Napoleon settings napoleon_numpy_docstring = False # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'default' if not on_rtd: # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'sphinx_rtd_theme' # Add any paths that contain custom themes here, relative to this directory. html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. ##html_logo = '_static/img/logo-180px.png' # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. html_last_updated_fmt = '%Y-%m-%d' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'dh-virtualenvdoc' # -- Options for LaTeX output -------------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ ('index', 'dh-virtualenv.tex', u'dh-virtualenv Documentation', u'Spotify AB', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output -------------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('index', 'dh-virtualenv', u'dh-virtualenv Documentation', [u'Spotify AB'], 1) ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------------ # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'dh-virtualenv', u'dh-virtualenv Documentation', u'Spotify AB', 'dh-virtualenv', 'Debian packaging sequence for Python virtualenvs.', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' doc/dh_virtualenv.1.rst000066400000000000000000000044031374426432200153760ustar00rootroot00000000000000============= dh-virtualenv ============= ------------------------------------------------------ deploy a Python package in a self-contained virtualenv ------------------------------------------------------ :Author: Jyrki Pulliainen / Spotify AB :Copyright: Copyright (C) 2013, Spotify AB. Licensed under the GNU General Public License version 2 or later :Manual section: 1 :Manual group: DebHelper SYNOPSIS ======== **dh_virtualenv** [*OPTIONS*] DESCRIPTION =========== ``dh-virtualenv`` is a tool that aims to combine Debian packaging with self-contained virtualenv based Python deployments. To do this, the package extends debhelper's sequence by providing a new command in sequence, ``dh_virtualenv``, which effectively replaces following commands from the sequence: * ``dh_auto_install`` * ``dh_python2`` * ``dh_pycentral`` * ``dh_pysupport`` In the sequence the ``dh_virtualenv`` is inserted right after ``dh_perl``. OPTIONS ======= -p PACKAGE, --package=PACKAGE Act on the package named PACKAGE -N PACKAGE, --no-package=PACKAGE Do not act on the specified PACKAGE -v, --verbose Turn on verbose mode. --extra-index-url Pass extra index URL to pip --preinstall=PACKAGE Preinstall a PACKAGE before running pip. --pip-tool=PIP_TOOL Tool used to install requirements. --extra-pip-arg Extra arg for the pip executable. --extra-virtualenv-arg Extra arg for the virtualenv executable. --index-url Base URL for PyPI server. --setuptools Use setuptools instead of distribute. --install-suffix=SUFFIX Override virtualenv installation suffix --upgrade-pip Force upgrade pip in virtualenv --requirements=FILE Use FILE for requirements --setuptools-test Run `setup.py test` upon build. --python=PATH Use Python interpreter at PATH --builtin-venv Use built-in venv of Python 3 --skip-install Don't run ``pip install .`` QUICK GUIDE FOR MAINTAINERS =========================== 1. Build depend on `python` or `python-all` and `dh-virtualenv` 2. Add `${python:Depends}` to Depends 3. Add `python-virtualenv` to dh's `--with` option SEE ALSO ======== Online documentation can be found at https://dh-virtualenv.readthedocs.io/en/latest. This package should also ship with the complete documentation under `/usr/share/doc/dh-virtualenv`. doc/examples.rst000066400000000000000000000035021374426432200142020ustar00rootroot00000000000000=============================== Real-World Projects Show-Case =============================== These complete projects show how to combine the features of dh-virtualenv and Debian packaging in general to deliver actual software in the wild. You'll also see some of the recipes of the :doc:`howtos` applied in a wider context. .. contents:: List of Projects :local: .. _example-debianized-sentry: debianized-sentry ================= :Author: Jürgen Hermann :URL: https://github.com/1and1/debianized-sentry The project packages `Sentry.io`, adding systemd integration and default configuration for the Sentry Django/uWSGI app and related helper services. It also shows how to package 3rd party software as relased on PyPI, keeping the packaging code separate from the packaged project. It is based on the `debianized-pypi-mold`_ cookiecutter, which allows you to set up such projects *from scratch* to the first build in typically under an hour. .. _`debianized-pypi-mold`: https://github.com/Springerle/debianized-pypi-mold .. _example-debianized-jupyterhub: debianized-jupyterhub ===================== :Author: Jürgen Hermann :URL: https://github.com/1and1/debianized-jupyterhub JupyterHub has a Node.js service that implements its *configurable HTTP proxy* component, so this project applies the :ref:`node-env` recipe to install CHP. It also uses Python 3.5 instead of Python 2. Otherwise, it is very similar to the :ref:`example-debianized-sentry` project, which is no surprise since they're based on the same cookiecutter template. .. _example-configsite: configsite ========== :Author: Nadav-Ruskin :URL: https://github.com/Nadav-Ruskin/configsite This project shows how to cross-package a web service for the ARM platform, using `QEMU`_ and `Docker`_. .. _`QEMU`: https://www.qemu.org/ .. _`Docker`: https://www.docker.com/ doc/examples/000077500000000000000000000000001374426432200134505ustar00rootroot00000000000000doc/examples/Dockerfile.build000066400000000000000000000020001374426432200165300ustar00rootroot00000000000000# Build Debian package using dh-virtualenv FROM #DIST_ID#:#CODENAME# AS dpkg-build ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update -qq && apt-get install -yqq \ build-essential debhelper devscripts equivs dh-virtualenv \ curl tar gzip lsb-release apt-utils apt-transport-https libparse-debianchangelog-perl \ python3 python3-setuptools python3-pip python3-dev libffi-dev \ libxml2-dev libxslt1-dev libyaml-dev libjpeg-dev \ libssl-dev libncurses5-dev libncursesw5-dev libzmq3-dev \ && ( curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add - ) \ && echo 'deb https://deb.nodesource.com/#NODEREPO# #CODENAME# main' \ >/etc/apt/sources.list.d/nodesource.list \ && apt-get update -qq && apt-get install -y nodejs \ && rm -rf "/var/lib/apt/lists"/* WORKDIR /dpkg-build COPY ./ ./ RUN dpkg-buildpackage -us -uc -b && mkdir -p /dpkg && cp -pl /#PKGNAME#[-_]* /dpkg # RUN pwd && dh_virtualenv --version && ls -la && du -sch . ##UUID# doc/examples/build.sh000077500000000000000000000021731374426432200151110ustar00rootroot00000000000000#! /usr/bin/env bash # # Build Debian package in a Docker container # set -e NODEREPO="node_8.x" # Get build platform as 1st argument, and collect project metadata image="${1:?You MUST provide a docker image name}"; shift dist_id=${image%%:*} codename=${image#*:} pypi_name="$(./setup.py --name)" pkgname="$(dh_listpackages)" tag=$pypi_name-$dist_id-$codename staging_dir="build/staging" # Prepare staging area rm -rf $staging_dir 2>/dev/null || true mkdir -p $staging_dir git ls-files >build/git-files test ! -f .npmrc || echo .npmrc >>build/git-files tar -c --files-from build/git-files | tar -C $staging_dir -x sed -i -r -e 1s/stretch/$codename/g $staging_dir/debian/changelog sed -r -e s/#UUID#/$(< /proc/sys/kernel/random/uuid)/g \ -e s/#DIST_ID#/$dist_id/g -e s/#CODENAME#/$codename/g \ -e s/#NODEREPO#/$NODEREPO/g -e s/#PYPI#/$pypi_name/g -e s/#PKGNAME#/$pkgname/g \ $staging_dir/Dockerfile # Build in Docker container, save results, and show package info docker build --tag $tag "$@" $staging_dir docker run --rm $tag tar -C /dpkg -c . | tar -C build -xv dpkg-deb -I build/${pkgname}_*~${codename}*.deb doc/howtos.rst000066400000000000000000000274321374426432200137170ustar00rootroot00000000000000==================== Packaging Cookbook ==================== This chapter has recipes and tips for specific dh-virtualenv use-cases, like proper handling of binary ``manylinux1`` wheels. It also demonstrates some Debian packaging and debhelper features that are useful in the context of Python software packaging. .. contents:: List of Recipes :local: .. _py3-package: Building Packages for Python3 ============================= The Python2 EOL in 2020 is not so far away, so you better start to use Python3 for new projects, and port old ones that you expect to survive until then. The following is for *Ubuntu Xenial* or *Debian Stretch* with Python 3.5, and on *Ubuntu Bionic* you get Python 3.6. In ``debian/control``, the ``Build-Depends`` and ``Pre-Depends`` lists have to refer to Python3 packages. .. code-block:: ini Source: py3software Section: contrib/python … Build-Depends: debhelper (>= 9), python3, dh-virtualenv (>= 1.0), python3-setuptools, python3-pip, python3-dev, libffi-dev … Package: py3software … Pre-Depends: dpkg (>= 1.16.1), python3 (>= 3.5), ${misc:Pre-Depends} And the Python update triggers in ``debian/«pkgname».triggers`` need to be adapted, too. .. code-block:: ini … interest-noawait /usr/bin/python3.5 … You may also need to add the :option:`--python` option in ``debian/rules``. .. code-block:: make %: dh $@ --with python-virtualenv override_dh_virtualenv: dh_virtualenv --python python3 If you're using the buildsystem alternative, it is instead specified through the :envvar:`DH_VIRTUALENV_ARGUMENTS` variable. .. code-block:: make export DH_VIRTUALENV_ARGUMENTS := --no-site-packages --python python3 %: dh $@ --buildsystem dh_virtualenv .. _fhs-links: Making executables available ============================ To make executables in your virtualenv's ``bin`` directory callable from any shell prompt, do **not** add that directory to the global ``PATH`` by a ``profile.d`` hook or similar. This would add all the other stuff in there too, and you simply do not want that. So use the ``debian/«pkgname».links`` file to add a symbolic link to *those* exectuables you want to be visible, typically the one created by your main application package. .. code-block:: ini opt/venvs/«venvname»/bin/«cmdname» usr/bin/«cmdname» Replace the contained ``«placeholders»`` with the correct names. Add more links if there are additional tools, one line per extra executable. For ``root``-only commands, use ``usr/sbin/…``. .. _manylinux1: Handling binary wheels ====================== The introduction of `manylinux`_ wheels via `PEP 513`_ is a gift, sent by the PyPA community to us lowly developers wanting to use packages like Numpy while *not* installing a Fortran compiler just for that. However, two steps during package building often clash with the contained shared libraries, namely *stripping* (reducing the size of symbol tables) and scraping package dependencies out of shared libraries (*shlibdeps*). So if you get errors thrown at you by either ``dh_strip`` or ``dh_shlibdeps``, extend your ``debian/rules`` file as outlined below. .. code-block:: makefile .PHONY: override_dh_strip override_dh_shlibdeps override_dh_strip: dh_strip --exclude=cffi override_dh_shlibdeps: dh_shlibdeps -X/x86/ -X/numpy/.libs -X/scipy/.libs -X/matplotlib/.libs This example works for the Python data science stack – you have to list the packages that cause *you* trouble. .. _manylinux: https://github.com/pypa/manylinux .. _`PEP 513`: https://www.python.org/dev/peps/pep-0513/ .. _node-env: Adding Node.js to your virtualenv ================================= There are polyglot projects with a mix of Python and Javascript code, and some of the JS code might be executed server-side in a Node.js runtime. A typical example is server-side rendering for Angular apps with `Angular Universal`_. If you have this requirement, there is a useful helper named ``nodeenv``, which extends a Python virtualenv to also support installation of NPM packages. The following changes in ``debian/control`` require *Node.js* to be available on both the build and the target hosts. As written, the current LTS version is selected (i.e. `8.x` in mid 2018). The `NodeSource packages`_ are recommended to provide that dependency. .. code-block:: ini … Build-Depends: debhelper (>= 9), python3, dh-virtualenv (>= 1.0), python3-setuptools, python3-pip, python3-dev, libffi-dev, nodejs (>= 8), nodejs (<< 9) … Depends: ${shlibs:Depends}, ${misc:Depends}, nodejs (>= 8), nodejs (<< 9) … You also need to extend ``debian/rules`` as follows, change the variables in the first section to define different versions and filesystem locations. .. code-block:: make export DH_VIRTUALENV_INSTALL_ROOT=/opt/venvs SNAKE=/usr/bin/python3 EXTRA_REQUIREMENTS=--upgrade-pip --preinstall "setuptools>=17.1" --preinstall "wheel" NODEENV_VERSION=1.3.1 PACKAGE=$(shell dh_listpackages) DH_VENV_ARGS=--setuptools --python $(SNAKE) $(EXTRA_REQUIREMENTS) DH_VENV_DIR=debian/$(PACKAGE)$(DH_VIRTUALENV_INSTALL_ROOT)/$(PACKAGE) ifeq (,$(wildcard $(CURDIR)/.npmrc)) NPM_CONFIG=~/.npmrc else NPM_CONFIG=$(CURDIR)/.npmrc endif %: dh $@ --with python-virtualenv $(DH_VENV_ARGS) .PHONY: override_dh_virtualenv override_dh_virtualenv: dh_virtualenv $(DH_VENV_ARGS) $(DH_VENV_DIR)/bin/python $(DH_VENV_DIR)/bin/pip install nodeenv==$(NODEENV_VERSION) $(DH_VENV_DIR)/bin/nodeenv -C '' -p -n system . $(DH_VENV_DIR)/bin/activate \ && node /usr/bin/npm install --userconfig=$(NPM_CONFIG) \ -g configurable-http-proxy You want to always copy all but the last line literally. The lines above it install and embed ``nodeenv`` into the virtualenv freshly created by the ``dh_virtualenv`` call. Also remember to use TABs in makefiles (``debian/rules`` is one). The last (logical) line globally installs the ``configurable-http-proxy`` NPM package – one important result of using ``-g`` is that Javascript commands appear in the ``bin`` directory just like Python ones. That in turn means that in the activated virtualenv Python can easily call those JS commands, because they're on the ``PATH``. Change the NPM package name to what you want to install. ``npm`` uses either a local ``.npmrc`` file in the project root, or else the ``~/.npmrc`` one. Add local repository URLs and credentials to one of these files. .. _`NodeSource packages`: https://github.com/nodesource/distributions .. _`Angular Universal`: https://universal.angular.io/ .. _docker-builds: Multi-platform builds in Docker =============================== The code shown here is taken from the :ref:`example-debianized-jupyterhub` project, and explains how to build a package in a Docker container. Why build a package in a container? This is why: * *repeatable* builds in a *clean* environment * explicitly *documented installation* of build requirements *(as code)* * easy *multi-distro multi-release builds* The build is driven by a small shell script named ``build.sh``, which we use to get the target platform and some project metadata we already have, and feed that into the Dockerfile via simple ``sed`` templating. So we work on a copy of the Dockerfile, and that is one reason for anything in the project workdir that is controlled by git being copied to a staging area (a separate build directory). The other reason is performance – we present Docker with a pristine copy of our workdir, and so there are no accidents like ``COPY``\ ing a full development virtualenv or all of ``.git`` into the container build. .. rubric:: The build script Let's get to the code – since we apply the :ref:`node-env` recipe, we first set the repository where to get Node.js from. .. literalinclude:: examples/build.sh :language: shell :end-at: NODEREPO Next, the given platform and existing project metadata is stored into a bunch of variables. .. literalinclude:: examples/build.sh :language: shell :start-after: NODEREPO :end-before: Prepare Based on the collected input parameters, the staging area is set up in the ``build/staging`` directory. ``tar`` does the selective copy work, and ``sed`` is used to inject dynamic values into the copied files. .. literalinclude:: examples/build.sh :language: shell :start-at: Prepare :end-before: Build in Docker After all that prep work, we finally get to build our package. The results are copied from ``/dpkg`` where the Dockerfile put them (see below), and then the package metadata is shown for a quick visual check if everything looks OK. .. literalinclude:: examples/build.sh :language: shell :start-at: Build in Docker .. rubric:: The Dockerfile This is the complete Dockerfile, the important things are the two ``RUN`` directives. .. literalinclude:: examples/Dockerfile.build :language: docker The first ``RUN`` installs all the build dependencies on top of the base image. The second one then builds the package and makes a copy of the resulting files, for the build script to pick them up. .. rubric:: Putting it all together Here's a sample run of building for *Ubuntu Bionic*. .. code-block:: console $ ./build.sh ubuntu:bionic Sending build context to Docker daemon 106kB Step 1/6 : FROM ubuntu:bionic AS dpkg-build … Successfully tagged debianized-jupyterhub-ubuntu-bionic:latest ./ ./jupyterhub_0.9.1-1~bionic_amd64.deb ./jupyterhub_0.9.1-1~bionic_amd64.buildinfo ./jupyterhub-dbgsym_0.9.1-1~bionic_amd64.ddeb ./jupyterhub_0.9.1-1~bionic_amd64.changes new debian package, version 2.0. size 265372284 bytes: control archive=390780 bytes. 84 bytes, 3 lines conffiles 1214 bytes, 25 lines control 2350661 bytes, 17055 lines md5sums 4369 bytes, 141 lines * postinst #!/bin/sh 1412 bytes, 47 lines * postrm #!/bin/sh 696 bytes, 35 lines * preinst #!/bin/sh 1047 bytes, 41 lines * prerm #!/bin/sh 217 bytes, 6 lines shlibs 419 bytes, 10 lines triggers Package: jupyterhub Version: 0.9.1-1~bionic Architecture: amd64 Maintainer: 1&1 Group Installed-Size: 563574 Pre-Depends: dpkg (>= 1.16.1), python3 (>= 3.5) Depends: perl:any, libc6 (>= 2.25), libexpat1 (>= 2.1~beta3), libgcc1 (>= 1:4.0), … Suggests: oracle-java8-jre | openjdk-8-jre | zulu-8 Section: contrib/python Priority: extra Homepage: https://github.com/1and1/debianized-jupyterhub Description: Debian packaging of JupyterHub, a multi-user server for Jupyter notebooks. … The package files are now in ``build/``, and you can ``dput`` them into your local repository. .. _cross-package: Cross-packaging for ARM targets =============================== If you need to create packages that can be installed on ARM architectures, but want to use any build host (e.g. a CI worker), first install the ``qemu-user-static`` and ``binfmt-support`` packages. Then build the package by starting a container in QEMU using this ``Dockerfile``. .. code-block:: docker FROM arm32v7/debian:latest RUN apt-get update && apt-get -y upgrade && apt-get update \ && apt-get -y install sudo dpkg-dev debhelper dh-virtualenv python3 python3-venv … The build might fail from time to time, due to unknown causes (maybe instabilities in QEMU). If you get a package out of it, that works 100% fine, however. See :ref:`example-configsite` for the full project that uses this. .. epigraph:: — with input from `@Nadav-Ruskin`_ .. _`@Nadav-Ruskin`: https://github.com/Nadav-Ruskin doc/index.rst000066400000000000000000000033271374426432200135000ustar00rootroot00000000000000.. dh-virtualenv documentation master file, created by sphinx-quickstart on Wed Feb 20 17:29:43 2013. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Welcome to dh-virtualenv's documentation! ========================================= Overview -------- ``dh-virtualenv`` is a tool that aims to combine Debian packaging with self-contained Python software deployment in a pre-built virtualenv. To do this, the project extends debhelper's build sequence by providing the new ``dh_virtualenv`` command. This new command effectively replaces the following commands in the default sequence: * ``dh_auto_install`` * ``dh_python2`` * ``dh_pycentral`` * ``dh_pysupport`` In the debhelper build sequence, ``dh_virtualenv`` is inserted right after ``dh_perl``. .. rubric:: Reading Guide .. #. :doc:`tutorial` helps you to set up your build machine and then package your first simple project. #. :doc:`usage` explains all available features in more detail. #. The :doc:`howtos` demonstrates specific features and tricks needed for packaging more challenging projects. #. The :doc:`trouble-shooting` explains some typical errors you might enounter, and their solution. #. To take a look into complete projects, see :doc:`examples`. #. :doc:`source` has a short overview of the implementation and links to the source code. #. Finally, the :doc:`changes` provides a history of releases with their new features and fixes. Contents of this Manual ----------------------- .. toctree:: :maxdepth: 2 tutorial usage howtos trouble-shooting examples source changes Indices and Tables ------------------ * :ref:`genindex` * :ref:`modindex` * :ref:`search` doc/make.bat000066400000000000000000000117661374426432200132520ustar00rootroot00000000000000@ECHO OFF REM Command file for Sphinx documentation if "%SPHINXBUILD%" == "" ( set SPHINXBUILD=sphinx-build ) set BUILDDIR=_build set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . set I18NSPHINXOPTS=%SPHINXOPTS% . if NOT "%PAPER%" == "" ( set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% ) if "%1" == "" goto help if "%1" == "help" ( :help echo.Please use `make ^` where ^ is one of echo. html to make standalone HTML files echo. dirhtml to make HTML files named index.html in directories echo. singlehtml to make a single large HTML file echo. pickle to make pickle files echo. json to make JSON files echo. htmlhelp to make HTML files and a HTML help project echo. qthelp to make HTML files and a qthelp project echo. devhelp to make HTML files and a Devhelp project echo. epub to make an epub echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter echo. text to make text files echo. man to make manual pages echo. texinfo to make Texinfo files echo. gettext to make PO message catalogs echo. changes to make an overview over all changed/added/deprecated items echo. linkcheck to check all external links for integrity echo. doctest to run all doctests embedded in the documentation if enabled goto end ) if "%1" == "clean" ( for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i del /q /s %BUILDDIR%\* goto end ) if "%1" == "html" ( %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/html. goto end ) if "%1" == "dirhtml" ( %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. goto end ) if "%1" == "singlehtml" ( %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml if errorlevel 1 exit /b 1 echo. echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. goto end ) if "%1" == "pickle" ( %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the pickle files. goto end ) if "%1" == "json" ( %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can process the JSON files. goto end ) if "%1" == "htmlhelp" ( %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run HTML Help Workshop with the ^ .hhp project file in %BUILDDIR%/htmlhelp. goto end ) if "%1" == "qthelp" ( %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp if errorlevel 1 exit /b 1 echo. echo.Build finished; now you can run "qcollectiongenerator" with the ^ .qhcp project file in %BUILDDIR%/qthelp, like this: echo.^> qcollectiongenerator %BUILDDIR%\qthelp\dh-virtualenv.qhcp echo.To view the help file: echo.^> assistant -collectionFile %BUILDDIR%\qthelp\dh-virtualenv.ghc goto end ) if "%1" == "devhelp" ( %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp if errorlevel 1 exit /b 1 echo. echo.Build finished. goto end ) if "%1" == "epub" ( %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub if errorlevel 1 exit /b 1 echo. echo.Build finished. The epub file is in %BUILDDIR%/epub. goto end ) if "%1" == "latex" ( %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex if errorlevel 1 exit /b 1 echo. echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. goto end ) if "%1" == "text" ( %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text if errorlevel 1 exit /b 1 echo. echo.Build finished. The text files are in %BUILDDIR%/text. goto end ) if "%1" == "man" ( %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man if errorlevel 1 exit /b 1 echo. echo.Build finished. The manual pages are in %BUILDDIR%/man. goto end ) if "%1" == "texinfo" ( %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo if errorlevel 1 exit /b 1 echo. echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. goto end ) if "%1" == "gettext" ( %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale if errorlevel 1 exit /b 1 echo. echo.Build finished. The message catalogs are in %BUILDDIR%/locale. goto end ) if "%1" == "changes" ( %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes if errorlevel 1 exit /b 1 echo. echo.The overview file is in %BUILDDIR%/changes. goto end ) if "%1" == "linkcheck" ( %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck if errorlevel 1 exit /b 1 echo. echo.Link check complete; look for any errors in the above output ^ or in %BUILDDIR%/linkcheck/output.txt. goto end ) if "%1" == "doctest" ( %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest if errorlevel 1 exit /b 1 echo. echo.Testing of doctests in the sources finished, look at the ^ results in %BUILDDIR%/doctest/output.txt. goto end ) :end doc/source.rst000066400000000000000000000001701374426432200136620ustar00rootroot00000000000000====================== API / Code Reference ====================== .. toctree:: :maxdepth: 4 api/dh_virtualenv doc/trouble-shooting.rst000066400000000000000000000020151374426432200156660ustar00rootroot00000000000000======================== Trouble-Shooting Guide ======================== Installing on older Debian releases =================================== **TODO** Fixing package building problems ================================ 'pkg-resources not found' or similar ------------------------------------ If you get errors regarding ``pkg-resources`` during the virtualenv creation, update your build machine's ``pip`` and ``virtualenv``. The versions on previous releases of many distros are just too old to handle current infrastructure (especially PyPI) – even Debian Jessie comes with the ancient pip 1.5.6. This is the one exception to “never sudo pip”, so go ahead and do this: .. code-block:: shell sudo pip install -U pip virtualenv Then try building the package again. Fixing package installation problems ==================================== dpkg: too-long line or missing newline in '…/triggers' ------------------------------------------------------ **TODO** https://github.com/spotify/dh-virtualenv/pull/84 doc/tutorial.rst000066400000000000000000000213201374426432200142250ustar00rootroot00000000000000================= Getting Started ================= This tutorial will guide you through setting up your first project using *dh-virtualenv*. Having some knowledge on how Debian packages work might help, but it is not a mandatory requirement when working on simple projects. You also need some basic build tools, so you should install these packages: .. code-block:: shell sudo apt-get install build-essential debhelper devscripts equivs These are only required on the *build host*, not the *target hosts* you later install the built packages on. If you perform your :ref:`package builds in a Docker container `, you can also skip installing these tools, because then only ``docker-ce`` is needed. Step 1: Install dh-virtualenv ============================= .. rubric:: Overview In order to use it, you need to install *dh-virtualenv* as a debhelper add-on on the build host. For Debian and Ubuntu, there are pre-built packages for the 1.0 version available – note that some of this info might get outdated over time, so take extra care to check the version numbers you're actually getting vs. what features you need. The following paragraphs describe the various installation options, including building from source when your specific environment provides no packages or only older versions. Using pre-1.1 versions is possible, but you don't get all features described in this document, and not all projects using dh-virtualenv might work with older versions (check their documentation). .. rubric:: Package installation from OS repositories On Debian *Stretch* (stable) it is a simple ``apt install dh-virtualenv`` to get v1.0 installed. To install on *Jessie* (oldstable) from `their package repositories`_, use these commands: .. code-block:: bash echo "deb http://ftp.debian.org/debian jessie-backports main" \ | sudo tee /etc/apt/sources.list.d/jessie-backports.list >/dev/null sudo apt-get update -qq sudo apt-get install -t jessie-backports dh-virtualenv Note that ``jessie-backports`` also only offers the 1.0 version. Another option to check out for *Ubuntu* is `this PPA`_, maintained by the author. It is also possible to get newer versions from Debian testing (sid) or recent releases in the `official Ubuntu repositories`_. Since dh-virtualenv has the ``all`` architecture (contains no native code), that is generally possible, but you might need to take extra care of dependencies. The recommendation is to only follow that route in :ref:`Docker container builds `, where manipulating dependencies has no lasting effect – don't do that on your workstation. .. rubric:: Build your own package For all other platforms you have to build and install the tool yourself. The easiest way (since v1.1) is to build the package using Docker with the ``invoke bdist_deb`` command in a boot-strapped working directory, see the README for details on that. Using Docker also allows cross-distribution builds. Otherwise, after you have cloned the repository, you must install build tools and dependencies on your worksatation, and then start the build: .. code-block:: bash # Install needed packages sudo apt-get install devscripts python-virtualenv python-sphinx \ python-sphinx-rtd-theme git equivs # Clone git repository git clone https://github.com/spotify/dh-virtualenv.git # Change into working directory cd dh-virtualenv # This will install build dependencies sudo mk-build-deps -ri # Build the *dh-virtualenv* package dpkg-buildpackage -us -uc -b # And finally, install it (you might have to solve some # dependencies when doing this) sudo dpkg -i ../dh-virtualenv_.deb .. _`their package repositories`: https://packages.debian.org/source/sid/dh-virtualenv .. _`official Ubuntu repositories`: http://packages.ubuntu.com/search?keywords=dh-virtualenv .. _`this PPA`: https://launchpad.net/~spotify-jyrki/+archive/ubuntu/dh-virtualenv Step 2: Set up packaging for your project ========================================= Grab your favourite Python project you want to use *dh-virtualenv* with and set it up. Only requirement is that your project has a somewhat sane ``setup.py`` and requirements listed in a ``requirements.txt`` file. Note however that defining any requirements is not mandatory, if you have none. Instead of following all the steps outlined below, you can use cookiecutters (project templates) to quickly create the needed information in the ``debian/`` directory for any existing project. * `dh-virtualenv-mold `_ is a cookiecutter template to add easy Debianization to any existing Python project. * `debianized-pypi-mold `_ does the same for 3rd party software released to PyPI which you want to package for deployment. See the related READMEs for details. For the manual way, start with defining the Debian packaging metadata for your software. To do this, create a directory called ``debian`` in the project root. To be able to build a debian package, a few files are needed. First, we need to define the compatibility level of the project. For this, do: .. code-block:: bash echo "9" > debian/compat The 9 is a magic number for latest compatibility level, but we don't need to worry about that. Next we need a file that tells what our project is about, a file called ``control``. Create a ``debian/control`` file similar to the following: .. code-block:: control Source: my-awesome-python-software Section: python Priority: extra Maintainer: Matt Maintainer Build-Depends: debhelper (>= 9), python, dh-virtualenv (>= 0.8) Standards-Version: 3.9.5 Package: my-awesome-python-software Architecture: any Pre-Depends: dpkg (>= 1.16.1), python2.7 | python2.6, ${misc:Pre-Depends} Depends: ${misc:Depends} Description: A short summary of what this is. Further indented lines can contain extra information. . A single dot separates paragraphs. The ``control`` file is used to define the build dependencies, so if you are building a package that requires for example ``lxml``, make sure you define ``libxml2-dev`` in *Build-Depends*. *Depends* in the 2nd section is used to define run-time dependencies. The *debhelper* magic will usually take care of that via the ``${misc:Depends}`` you see above. To help keeping your installed virtualenv in sync with the host's Python interpreter in case of updates, create a file named ``debian/«pkgname».triggers``, where ``«pkgname»`` is what you named your package in the ``control`` file. It triggers a special script whenever the Python binary changes; don't worry, that script is provided by ``dh-virtualenv`` automatically. .. rubric:: «pkgname».triggers .. code-block:: ini # Register interest in Python interpreter changes (Python 2 for now); and # don't make the Python package dependent on the virtualenv package # processing (noawait) interest-noawait /usr/bin/python2.6 interest-noawait /usr/bin/python2.7 # Also provide a symbolic trigger for all dh-virtualenv packages interest dh-virtualenv-interpreter-update That file *must* end with a new-line – if your editor is misconfigured to eat the end of the last line in a file, you better fix that. Note that if you provide a custom ``postinst`` script with your package, then don't forget to put the ``#DEBHELPER#`` marker into it, else the trigger script will be missing. The same applies to other maintainer scripts. Next, we need a changelog file. It is basically a documentation of changes in your package plus the source for version number for Debian package builder. Here's a short sample changelog to be entered in ``debian/changelog``: :: my-awesome-python-software (0.1-1) unstable; urgency=low * Initial public release -- Matt Maintainer Fri, 01 Nov 2013 17:00:00 +0200 You don't need to create this file by hand, a handy tool called ``dch`` exists for entering new changelog entries. Now, the last bit left is adding the ``debian/rules`` file. This file is usually an executable *Makefile* that Debian uses to build the package. The content for that is fairly simple: .. code-block:: make #!/usr/bin/make -f %: dh $@ --with python-virtualenv And there we go, debianization of your new package is ready! .. tip:: Do not forget to ``git add`` the ``debian/`` directory *before* you build for the first time, because generated files will be added there that you don't want in your source code repository. Step 3: Build your project ========================== Now you can just build your project by running ``( deactivate ; dpkg-buildpackage -us -uc -b )``. Enjoy your newly baked *dh-virtualenv* backed project! ☺ doc/usage.rst000066400000000000000000000327631374426432200135030ustar00rootroot00000000000000================= Packaging Guide ================= Building packages with *dh-virtualenv* is relatively easy to start with, but it also supports lot of customization to match your specific needs. By default, *dh-virtualenv* installs your packages under ``/opt/venvs/«packagename»``. The package name is provided by the ``debian/control`` file. To use an alternative install prefix, add a line like the following to the top of your ``debian/rules`` file. .. code-block:: make export DH_VIRTUALENV_INSTALL_ROOT=«/your/custom/install/dir» dh_virtualenv will now use the value of :envvar:`DH_VIRTUALENV_INSTALL_ROOT` instead of ``/opt/venvs`` when it constructs the install path. To use an install suffix other than the package name, call ``dh_virtualenv`` using the :option:`--install-suffix` command line option. See :ref:`advanced-usage` for further information on passing options. Simple usecase ============== To signal debhelper to use *dh-virtualenv* for building your package, you need to pass ``--with python-virtualenv`` to the debhelper sequencer. In a nutshell, the simplest ``debian/rules`` file to build using *dh-virtualenv* looks like this: .. code-block:: make #!/usr/bin/make -f %: dh $@ --with python-virtualenv However, the tool makes a few assumptions of your project's structure: * For installing requirements, you need to have a file called ``requirements.txt`` in the root directory of your project. The requirements file is not mandatory. * The project must have a ``setup.py`` file in the root of the project. ``dh_virtualenv`` will run ``setup.py install`` to add your project to the virtualenv. After these preparations, you can just build the package with your favorite tool! Environment variables ===================== Certain environment variables can be used to customise the behaviour of the debhelper sequencer in addition to the standard debhelper variables. .. envvar:: DH_VIRTUALENV_INSTALL_ROOT Define a custom root location to install your package(s). The resulting location for a specific package will be ``$DH_VIRTUALENV_INSTALL_ROOT/«, --package Act on the package named **. .. option:: -N , --no-package Do not act on the specified package. .. option:: -v, --verbose Turn on verbose mode. This has a few effects: it sets the root logger level to ``DEBUG``, and passes the verbose flag to ``pip`` when installing packages. This can also be provided using the standard ``DH_VERBOSE`` environment variable. .. option:: --install-suffix Override virtualenv installation suffix. The suffix is appended to ``/opt/venvs``, or the :envvar:`DH_VIRTUALENV_INSTALL_ROOT` environment variable if specified, to construct the installation path. .. option:: --extra-index-url Use extra index url ** when running ``pip`` to install packages. This can be provided multiple times to pass multiple URLs to ``pip``. A common use-case is enabling a private Python package repository. .. option:: --preinstall Package to install before processing the requirements. This flag can be used to provide a package that is installed by ``pip`` before processing the requirements file. It is handy if you need to install a custom setup script or other packages needed to parse ``setup.py``, and can be provided multiple times to pass multiple packages for pre-install. .. option:: --extras .. versionadded:: 1.1 Name of extras defined in the main package (specifically its ``setup.py``, in ``extras_require``). You can pass this multiple times to add different extra requirements. .. option:: --pip-tool Executable that will be used to install requirements after the preinstall stage. Usually you'll install this program by using the ``--preinstall`` argument. The replacement is expected to be found in the virtualenv's ``bin/`` directory. .. option:: --upgrade-pip .. versionadded:: 1.0 Force upgrading to the latest available release of ``pip``. This is the first thing done in the pre-install stage, and uses a separate ``pip`` call. Options provided via :option:`--extra-pip-arg` are ignored here, because the default ``pip`` of your system might not support them (since version 1.1). *Note:* This can produce non-repeatable builds. See also :option:`--upgrade-pip-to`. .. option:: --upgrade-pip-to .. versionadded:: 1.2 Same as :option:`--upgrade-pip`, but install an explicitly provided version. You can specify ``latest`` to get the exact same behaviour as with the simple option. *Note:* This can be used for more repeatable builds that do not have the risk of breaking on a new ``pip`` release. .. option:: --index-url Base URL of the PyPI server. This flag can be used to pass in a custom URL to a PyPI mirror. It's useful if you have an internal PyPI mirror, or you run a special instance that only exposes selected packages of PyPI. If this is not provided, the default will be whatever ``pip`` uses as default (usually the API of ``https://pypi.org/``). .. option:: --extra-pip-arg Extra arguments to pass to the pip executable. This is useful if you need to change the behaviour of pip during the packaging process. You can use this flag multiple times to pass in different pip flags. As an example, adding ``--extra-pip-arg --no-compile`` in the call of a ``override_dh_virtualenv`` rule in the ``debian/rules`` file will disable the generation of ``*.pyc`` files. .. option:: --extra-virtualenv-arg Extra parameters to pass to the virtualenv executable. This is useful if you need to change the behaviour of virtualenv during the packaging process. You can use this flag multiple times to pass in different virtualenv flags. .. option:: --requirements Use a different requirements file when installing. Some packages such as `pbr `_ expect the ``requirements.txt`` file to be a simple list of requirements that can be copied verbatim into the ``install_requires`` list. This command option allows specifying a different ``requirements.txt`` file that may include pip specific flags such as ``-i``, ``-r-`` and ``-e``. .. option:: --setuptools Use setuptools instead of distribute in the virtualenv. .. option:: --setuptools-test .. versionadded:: 1.0 Run ``python setup.py test`` when building the package. This was the old default behaviour before version 1.0. This option is incompatible with the deprecated :option:`--no-test`. .. option:: --python Use a specific Python interpreter found in ``path`` as the interpreter for the virtualenv. Default is to use the system default, usually ``/usr/bin/python``. .. option:: --builtin-venv Enable the use of the build-in ``venv`` module, i.e. use ``python -m venv`` to create the virtualenv. It will only work with Python 3.4 or later, e.g. by using the option :option:`--python` ``/usr/bin/python3.4``. .. option:: -S, --use-system-packages Enable the use of system site-packages in the created virtualenv by passing the ``--system-site-packages`` flag to ``virtualenv``. .. option:: --skip-install Skip running ``pip install .`` after dependencies have been installed. This will result in anything specified in ``setup.py`` being ignored. If this package is intended to install a virtualenv and a program that uses the supplied virtualenv, it is up to the user to ensure that if ``setup.py`` exists, any installation logic or dependencies contained therein are handled. This option is useful for web application deployments, where the package's virtual environment merely supports an application installed via other means. Typically, the ``debian/«packagename».install`` file is used to place the application at a location outside of the virtual environment. .. option:: --pypi-url .. deprecated:: 1.0 Use :option:`--index-url` instead. .. option:: --no-test .. deprecated:: 1.0 This option has no effect. See :option:`--setuptools-test`. .. _advanced-usage: Advanced usage ============== To provide command line options to the ``dh_virtualenv`` step, use debhelper's override mechanism. The following ``debian/rules`` will provide *http://example.com* as an additional source of Python packages: .. code-block:: make #!/usr/bin/make -f %: dh $@ --with python-virtualenv override_dh_virtualenv: dh_virtualenv --extra-index-url http://example.com pbuilder and dh-virtualenv ========================== Building your Debian package in a pbuilder_ environment can help to ensure proper dependencies and repeatable builds. However, precisely because pbuilder creates its own build environment, build failues can be much more difficult to understand and troubleshoot. This is especially true when there is a pip error inside the pbuilder environment. For that reason, make sure that you can build your Debian package successfully outside of a pbuilder environment before trying to build it inside. With those caveats, here are some tips for making pip and dh_virtual work inside pbuilder. If you want pip to retrieve packages from the network, you need to add ``USENETWORK=yes`` to your /etc/pbuilderrc or ~/.pbuilderrc file. pip has several options that can be used to make it more compatible with pbuilder. Use ``--no-cache-dir`` to stop creating wheels in your home directory, which will fail when running in a pbuilder environment, because pbuilder sets the HOME environment variable to "/nonexistent". Use ``--no-deps`` to make pip builds more repeatable_. Use ``--ignore-installed`` to ensure that pip installs every package in ``requirements.txt`` in the virtualenv. This option is especially important if you are using the --system-site-packages option in your virtualenv. Here's an example of how to use these arguments in your ``rules`` file. .. code-block:: make override_dh_virtualenv: dh_virtualenv \ --extra-pip-arg "--ignore-installed" \ --extra-pip-arg "--no-deps" \ --extra-pip-arg "--no-cache-dir" .. _pbuilder: https://wiki.ubuntu.com/PbuilderHowto .. _repeatable: https://pip.readthedocs.org/en/stable/user_guide.html#ensuring-repeatability Experimental buildsystem support ================================ .. important:: This section describes a completely experimental functionality of dh-virtualenv. Starting with version 0.9 of dh-virtualenv, there is a buildsystem alternative. The main difference in use is that instead of the ``--with python-virtualenv`` option, ``--buildsystem=dh_virtualenv`` is passed to debhelper. The ``debian rules`` file should look like this: .. code-block:: make #!/usr/bin/make -f %: dh $@ --buildsystem=dh_virtualenv Using the buildsystem instead of the part of the sequence (in other words, instead of the ``--with python-virtualenv``) one can get more flexibility into the build process. Flexibility comes from the fact that buildsystem will have individual steps for configure, build, test and install and those can be overridden by adding ``override_dh_auto_`` target into the ``debian/rules`` file. For example: .. code-block:: make #!/usr/bin/make -f %: dh $@ --buildsystem=dh_virtualenv override_dh_auto_test: py.test test/ In addition the separation of build and install steps makes it possible to use ``debian/install`` files to include built files into the Debian package. This is not possible with the sequencer addition. The build system honors the :envvar:`DH_VIRTUALENV_INSTALL_ROOT` environment variable. Following other environment variables can be used to customise the functionality: .. envvar:: DH_VIRTUALENV_ARGUMENTS Pass given extra arguments to the ``virtualenv`` command For example: .. code-block:: make export DH_VIRTUALENV_ARGUMENTS="--no-site-packages --always-copy" The default is to create the virtual environment with ``--no-site-packages``. .. envvar:: DH_VIRTUALENV_INSTALL_SUFFIX Override the default virtualenv name, instead of source package name. For example: .. code-block::make export DH_VIRTUALENV_INSTALL_SUFFIX=venv .. envvar:: DH_REQUIREMENTS_FILE .. versionadded:: 1.0 Override the location of requirements file. See :option:`--requirements`. .. envvar:: DH_UPGRADE_PIP .. versionadded:: 1.0 Force upgrade of the ``pip`` tool by setting :envvar:`DH_UPGRADE_PIP` to empty (latest version) or specific version. For example: .. code-block::make export DH_UPGRADE_PIP=8.1.2 .. envvar:: DH_UPGRADE_SETUPTOOLS .. versionadded:: 1.0 Force upgrade of setuptools by setting :envvar:`DH_UPGRADE_SETUPTOOLS` to empty (latest version) or specific version. .. envvar:: DH_UPGRADE_WHEEL .. versionadded:: 1.0 Force upgrade of wheel by setting ``DH_UPGRADE_WHEEL`` to empty (latest version) or specific version. .. envvar:: DH_PIP_EXTRA_ARGS .. versionadded:: 1.0 Pass additional parameters to the ``pip`` command. For example: .. code-block:: make export DH_PIP_EXTRA_ARGS="--no-index --find-links=./requirements/wheels" lib/000077500000000000000000000000001374426432200116335ustar00rootroot00000000000000lib/Debian/000077500000000000000000000000001374426432200130155ustar00rootroot00000000000000lib/Debian/Debhelper/000077500000000000000000000000001374426432200147075ustar00rootroot00000000000000lib/Debian/Debhelper/Buildsystem/000077500000000000000000000000001374426432200172135ustar00rootroot00000000000000lib/Debian/Debhelper/Buildsystem/dh_virtualenv.pm000066400000000000000000000113661374426432200224320ustar00rootroot00000000000000package Debian::Debhelper::Buildsystem::dh_virtualenv; use strict; use base 'Debian::Debhelper::Buildsystem'; use Debian::Debhelper::Dh_Lib; use File::Spec; use Cwd; sub DESCRIPTION { 'Python Virtualenv'; } sub DEFAULT_BUILD_DIRECTORY { my $this=shift; return $this->canonpath($this->get_sourcepath("build")); } sub check_auto_buildable { my $this=shift; return -e $this->get_sourcepath("setup.py") ? 1 : 0; } sub new { my $class = shift; my $this = $class->SUPER::new(@_); $this->prefer_out_of_source_building(); return $this; } sub get_install_root { my $prefix = "/usr/share/python"; if (defined $ENV{DH_VIRTUALENV_INSTALL_ROOT}) { $prefix = $ENV{DH_VIRTUALENV_INSTALL_ROOT}; } return $prefix; } sub get_venv_builddir { my $this = shift; my $builddir = $this->get_builddir(); my $virtualenv_name = $ENV{DH_VIRTUALENV_INSTALL_SUFFIX} || $this->sourcepackage(); my $prefix = $this->get_install_root(); return "$builddir$prefix/$virtualenv_name"; } sub get_exec { my $this = shift; my $executable = shift; my $builddir = $this->get_venv_builddir(); return Cwd::abs_path("$builddir/bin/$executable"); } sub get_python { my $this = shift; return $this->get_exec("python"); } sub get_pip { my $this = shift; return ($this->get_exec("python"), "-m", "pip"); } sub configure { my $this = shift; doit('mkdir', '-p', $this->get_venv_builddir()); } sub build { my $this = shift; my $sourcedir = $this->get_sourcedir(); my $builddir = $this->get_venv_builddir(); my @params = ('--no-site-packages'); my $reqfile = ('requirements.txt'); my @pipargs = (); if (defined $ENV{DH_VIRTUALENV_ARGUMENTS}) { @params = split(' ', $ENV{DH_VIRTUALENV_ARGUMENTS}); } if (defined $ENV{DH_REQUIREMENTS_FILE}) { $reqfile = $ENV{DH_REQUIREMENTS_FILE}; } if (defined $ENV{DH_PIP_EXTRA_ARGS}) { @pipargs = split(' ', $ENV{DH_PIP_EXTRA_ARGS}); } $this->doit_in_builddir( 'virtualenv', @params, Cwd::abs_path($builddir)); my $python = $this->get_python(); my @pip = $this->get_pip(); if (defined $ENV{DH_UPGRADE_PIP}) { my $version = length $ENV{DH_UPGRADE_PIP} && '=='.$ENV{DH_UPGRADE_PIP} || ''; $this->doit_in_sourcedir( @pip, 'install', '-U', 'pip' . $version); } if (defined $ENV{DH_UPGRADE_SETUPTOOLS}) { my $version = length $ENV{DH_UPGRADE_SETUPTOOLS} && '=='.$ENV{DH_UPGRADE_SETUPTOOLS} || ''; $this->doit_in_sourcedir( @pip, 'install', '-U', 'setuptools' . $version); } if (defined $ENV{DH_UPGRADE_WHEEL}) { my $version = length $ENV{DH_UPGRADE_WHEEL} && '=='.$ENV{DH_UPGRADE_WHEEL} || ''; $this->doit_in_sourcedir( @pip, 'install', '-U', 'wheel' . $version); } $this->doit_in_sourcedir( @pip, 'install', '-r', $reqfile, @pipargs); } sub test { my $this = shift; my $python = $this->get_python(); $this->doit_in_sourcedir( $python, 'setup.py', 'test'); } sub install { my $this = shift; my $destdir = shift; my @pip = $this->get_pip(); my $python = $this->get_python(); my $sourcepackage = $this->sourcepackage(); my $venv = $this->get_venv_builddir(); my $prefix = $this->get_install_root(); $this->doit_in_sourcedir( @pip, 'install', '.'); # Before we copy files, let's make the symlinks in the 'usr/local' # relative to the build path. my @files_in_local = <"$venv/local/*">; foreach (@files_in_local) { if ( -l $_ ) { my $target = readlink; my $relpath = File::Spec->abs2rel($target, "$venv/local"); my $basename = Debian::Debhelper::Dh_Lib->basename($_); unlink; symlink($relpath, $_); } } $this->doit_in_builddir('mkdir', '-p', $destdir); $this->doit_in_builddir('cp', '-r', '-T', '.', $destdir); my $new_python = undef; my @binaries = undef; if (defined $ENV{DH_VIRTUALENV_INSTALL_SUFFIX}) { $new_python = "$prefix/" . $ENV{DH_VIRTUALENV_INSTALL_SUFFIX} . "/bin/python"; my $curdir = "$destdir$prefix" . $ENV{DH_VIRTUALENV_INSTALL_SUFFIX} . "/bin/*"; @binaries = glob($curdir); } else { $new_python = "$prefix/$sourcepackage/bin/python"; @binaries = <"$destdir$prefix/$sourcepackage/bin/*">; } # Fix shebangs so that we use the Python in the final location # instead of the Python in the build directory { local $^I = q{}; local @ARGV = grep { -T } @binaries; while ( <> ) { s|^#!.*bin/(env )?python|#!$new_python|; print; } } } sub clean { my $this = shift; $this->rmdir_builddir(); } 1 lib/Debian/Debhelper/Sequence/000077500000000000000000000000001374426432200164575ustar00rootroot00000000000000lib/Debian/Debhelper/Sequence/python_virtualenv.pm000066400000000000000000000026271374426432200226240ustar00rootroot00000000000000#! /usr/bin/perl # debhelper sequence for wrapping packages inside virtualenvs # Copyright (c) Spotify AB 2013 # This file is part of dh-virtualenv. # dh-virtualenv is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 2 of the # License, or (at your option) any later version. # dh-virtualenv is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with dh-virtualenv. If not, see # . use warnings; use strict; use Debian::Debhelper::Dh_Lib; insert_before("dh_installinit", "dh_virtualenv"); # dh_auto_test can cause system python to run 'python setup.py test', # which will break due missing dependencies. remove_command("dh_auto_test"); # dh_auto_build causes system python to run 'python setup.py build' # which is unnecessary as we will run that inside the virtualenv # anyway remove_command("dh_auto_build"); # Same for dh_auto_install and dh_auto_clean remove_command("dh_auto_install"); remove_command("dh_auto_clean"); remove_command("dh_python2"); remove_command("dh_pycentral"); remove_command("dh_pysupport"); 1 setup.cfg000066400000000000000000000001651374426432200127100ustar00rootroot00000000000000[build_sphinx] source-dir = doc build-dir = doc/_build all-files = 1 [upload_sphinx] upload-dir = doc/_build/html setup.py000077500000000000000000000042661374426432200126120ustar00rootroot00000000000000#! /usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2013 Spotify AB # This file is part of dh-virtualenv. # dh-virtualenv is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 2 of the # License, or (at your option) any later version. # dh-virtualenv is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with dh-virtualenv. If not, see # . import io import re import os import sys import json from setuptools import setup version_py = os.path.join(os.path.dirname(__file__), "dh_virtualenv", "_version.py") project = {} with io.open(version_py, 'r', encoding='utf-8') as handle: for line in handle: try: key, value = re.match(r"^(\w+) ?= ?u?'(.+?)'$", line).groups() except (AttributeError, TypeError, ValueError): pass else: project[key] = value assert all(x in project for x in ('version', 'author', 'author_email', 'url')), 'Bad metadata in _version.py!' project.update( name='dh_virtualenv', description='Debian packaging sequence for Python virtualenvs.', license='GNU General Public License v2 or later', scripts=['bin/dh_virtualenv'], packages=['dh_virtualenv'], classifiers=[ 'Intended Audience :: Developers', 'Intended Audience :: System Administrators', 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)', 'Topic :: Software Development :: Build Tools', 'Topic :: System :: Installation/Setup', 'Topic :: Utilities', ]) # Ensure "setup.py" is importable by other tools, to access the project's metadata __all__ = ['project'] if __name__ == '__main__': if '--metadata' in sys.argv[:2]: json.dump(project, sys.stdout, default=repr, indent=4, sort_keys=True) sys.stdout.write('\n') else: setup(**project) tasks.py000066400000000000000000000015641374426432200125720ustar00rootroot00000000000000# -*- coding: utf-8 -*- # pylint: disable=wildcard-import, unused-wildcard-import, bad-continuation """ Project automation using Invoke. """ from __future__ import absolute_import, unicode_literals import os from rituals import config from rituals.easy import * # pylint: disable=redefined-builtin config.set_flat_layout() os.environ['INVOKE_RITUALS_DOCS_SOURCES'] = os.path.join(os.path.dirname(__file__), 'doc') @task(help={'distro': "base image name to use for building"}) def bdist_deb(ctx, distro=None): """Build package for Debian stable using Docker""" ctx.run("docker build --tag dh-venv-builder --build-arg distro={} ." .format(distro or 'debian:stable')) os.path.exists('dist') or os.makedirs('dist') ctx.run("docker run --rm dh-venv-builder tar -C /dpkg -c . | tar -C dist -xv") ctx.run("ls -lth dist/") namespace.add_task(bdist_deb) test/000077500000000000000000000000001374426432200120445ustar00rootroot00000000000000test/test_cmdline.py000066400000000000000000000130641374426432200150740ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (c) 2014 Spotify AB # This file is part of dh-virtualenv. # dh-virtualenv is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 2 of the # License, or (at your option) any later version. # dh-virtualenv is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with dh-virtualenv. If not, see # . import io import os import warnings from dh_virtualenv import cmdline from mock import patch from nose.tools import eq_, ok_ def get_mocked_stderr(): # optparse will try to print str(err) to sys.stderr, both on Python 2 and 3 # so we need to mock sys.stderr with the right *IO class if str == bytes: # We're on Python 2, where str(foo) is a bytes string return io.BytesIO() else: # We're on Python 3, where str(foo) is a unicode string return io.StringIO() @patch.object(cmdline.DebhelperOptionParser, 'error') def test_unknown_argument_is_error(error_mock): parser = cmdline.DebhelperOptionParser(usage='foo') parser.parse_args(['-f']) eq_(1, error_mock.call_count) def test_test_debhelper_option_parsing(): parser = cmdline.DebhelperOptionParser() parser.add_option('--sourcedirectory') opts, args = parser.parse_args(['-O--sourcedirectory', '/tmp']) eq_('/tmp', opts.sourcedirectory) eq_([], args) def test_parser_picks_up_DH_OPTIONS_from_environ(): with patch.dict(os.environ, {'DH_OPTIONS': '--sourcedirectory=/tmp/'}): parser = cmdline.get_default_parser() opts, args = parser.parse_args() eq_('/tmp/', opts.sourcedirectory) def test_get_default_parser(): parser = cmdline.get_default_parser() opts, args = parser.parse_args([ '-O--sourcedirectory', '/tmp/foo', '--extra-index-url', 'http://example.com' ]) eq_('/tmp/foo', opts.sourcedirectory) eq_(['http://example.com'], opts.extra_index_url) def test_pypi_url_creates_deprecation_warning(): # This test needs to be the first one that uses '--pypi-url' flag. # Otherwise the 'default' for warnings.simplefilter will exclude # the subsequent warnings. Another option would be to use 'always' # in cmdline.py, but that's quite wide cannon to shoot with. parser = cmdline.get_default_parser() with warnings.catch_warnings(record=True) as w: parser.parse_args([ '--pypi-url=http://example.com', ]) eq_(len(w), 1) ok_(issubclass(w[0].category, DeprecationWarning)) eq_(str(w[0].message), 'Use of --pypi-url is deprecated. Use --index-url instead') def test_no_test_creates_deprecation_warning(): parser = cmdline.get_default_parser() with warnings.catch_warnings(record=True) as w: parser.parse_args([ '--no-test', ]) eq_(len(w), 1) ok_(issubclass(w[0].category, DeprecationWarning)) eq_(str(w[0].message), 'Use of --no-test is deprecated and has no effect. ' 'Use --setuptools-test if you want to execute ' '`setup.py test` during package build.') @patch('sys.exit') def test_pypi_url_index_url_conflict(exit_): parser = cmdline.get_default_parser() f = get_mocked_stderr() with patch('sys.stderr', f): parser.parse_args([ '--pypi-url=http://example.com', '--index-url=http://example.org'] ) ok_('Deprecated --pypi-url and the new --index-url are mutually exclusive' in f.getvalue()) exit_.assert_called_once_with(2) @patch('sys.exit') def test_test_flag_conflict(exit_): parser = cmdline.get_default_parser() f = get_mocked_stderr() with patch('sys.stderr', f): parser.parse_args([ '--no-test', '--setuptools-test'] ) ok_('Deprecated --no-test and the new --setuptools-test are mutually ' 'exclusive' in f.getvalue()) exit_.assert_called_once_with(2) @patch('sys.exit') def test_pypi_url_index_url_conflict_independent_from_order(exit_): parser = cmdline.get_default_parser() f = get_mocked_stderr() with patch('sys.stderr', f): parser.parse_args([ '--index-url=http://example.org', '--pypi-url=http://example.com'] ) ok_('Deprecated --pypi-url and the new --index-url are mutually exclusive' in f.getvalue()) exit_.assert_called_once_with(2) def test_that_default_test_option_should_be_false(): parser = cmdline.get_default_parser() opts, args = parser.parse_args() eq_(False, opts.setuptools_test) def test_that_test_option_can_be_true(): parser = cmdline.get_default_parser() opts, args = parser.parse_args(['--setuptools-test']) eq_(True, opts.setuptools_test) def test_that_no_test_option_has_no_effect(): parser = cmdline.get_default_parser() opts, args = parser.parse_args(['--no-test']) eq_(False, opts.setuptools_test) def test_that_default_use_system_packages_option_should_be_false(): parser = cmdline.get_default_parser() opts, args = parser.parse_args() eq_(False, opts.use_system_packages) def test_that_use_system_packages_option_can_be_true(): parser = cmdline.get_default_parser() opts, args = parser.parse_args(['--use-system-packages']) eq_(True, opts.use_system_packages) test/test_deployment.py000066400000000000000000000420021374426432200156330ustar00rootroot00000000000000# -*- coding: utf-8 -*- # Copyright (c) 2013-2014 Spotify AB # This file is part of dh-virtualenv. # dh-virtualenv is free software: you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation, either version 2 of the # License, or (at your option) any later version. # dh-virtualenv is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # You should have received a copy of the GNU General Public License # along with dh-virtualenv. If not, see # . import functools import os import shutil import tempfile import textwrap import contextlib from mock import patch, call, ANY from nose.tools import eq_ from dh_virtualenv import Deployment from dh_virtualenv.cmdline import get_default_parser PY_CMD = os.path.abspath('debian/test/opt/venvs/test/bin/python') PIP_CMD = os.path.abspath('debian/test/opt/venvs/test/bin/pip') TEST_VENV_PATH = 'debian/test/opt/venvs/test' class FakeTemporaryFile(object): name = 'foo' def _test_bin(name): return os.path.abspath(os.path.join( 'debian/test/opt/venvs/test/bin', name, )) PY_CMD = _test_bin('python') PIP_CMD = _test_bin('pip') CUSTOM_PIP_CMD = _test_bin('pip-custom-platform') LOG_ARG = '--log=' + os.path.abspath(FakeTemporaryFile.name) def temporary_dir(fn): """Pass a temporary directory to the fn. This method makes sure it is destroyed at the end """ @functools.wraps(fn) def _inner(*args, **kwargs): try: tempdir = tempfile.mkdtemp() return fn(tempdir, *args, **kwargs) finally: shutil.rmtree(tempdir) return _inner def create_new_style_shebang(executable): shebang = '#!/bin/sh\n' shebang += "'''exec' " + executable + ' "$0" "$@"' + '\n' shebang += "' '''\n" return shebang def test_shebangs_fix(): """Generate a test for each possible interpreter""" for interpreter in ('python', 'pypy', 'ipy', 'jython'): yield check_shebangs_fix, interpreter, '/opt/venvs/test' def test_shebangs_fix_overridden_root(): """Generate a test for each possible interpreter while overriding root""" with patch.dict(os.environ, {'DH_VIRTUALENV_INSTALL_ROOT': 'foo'}): for interpreter in ('python', 'pypy', 'ipy', 'jython'): yield check_shebangs_fix, interpreter, 'foo/test' def test_shebangs_fix_special_chars_in_path(): """Shebang fix: Don't trip on special characters in path""" with patch.dict( os.environ, {'DH_VIRTUALENV_INSTALL_ROOT': 'some-directory:with/special_chars'}): for interpreter in ('python', 'pypy', 'ipy', 'jython'): yield (check_shebangs_fix, interpreter, 'some-directory:with/special_chars/test') def test_shebangs_fix_new_pip_with_over_127_chars(): """Shebang fix: Handle new pip with long shebangs""" with patch.dict( os.environ, {'DH_VIRTUALENV_INSTALL_ROOT': 127 * 'p'}): check_shebangs_fix_on_new_pip(127 * 'p' + '/test') def check_shebangs_fix(interpreter, path): """Checks shebang substitution for the given interpreter""" deployment = Deployment('test') temp = tempfile.NamedTemporaryFile() # We cheat here a little. The fix_shebangs walks through the # project directory, however we can just point to a single # file, as the underlying mechanism is just grep -r. deployment.bin_dir = temp.name expected_shebang = '#!' + os.path.join(path, 'bin/python') + '\n' with open(temp.name, 'w') as f: f.write('#!/usr/bin/{0}\n'.format(interpreter)) deployment.fix_shebangs() with open(temp.name) as f: eq_(f.read(), expected_shebang) with open(temp.name, 'w') as f: f.write('#!/usr/bin/env {0}\n'.format(interpreter)) deployment.fix_shebangs() with open(temp.name) as f: eq_(f.readline(), expected_shebang) # Additional test to check for paths wrapped in quotes because they contained space # Example: # #!"/some/local/path/dest/path/bin/python" # was changed to: # #!/dest/path/bin/python" # which caused interpreter not found error with open(temp.name, 'w') as f: f.write('#!"/usr/bin/{0}"\n'.format(interpreter)) deployment.fix_shebangs() with open(temp.name) as f: eq_(f.readline(), expected_shebang) def check_shebangs_fix_on_new_pip(path): """Test new pip style shebangs get replaced properly""" deployment = Deployment('test') temp = tempfile.NamedTemporaryFile() # We cheat here a little. The fix_shebangs walks through the # project directory, however we can just point to a single # file, as the underlying mechanism is just grep -r. deployment.bin_dir = temp.name build_time_shebang = create_new_style_shebang(os.path.join( deployment.virtualenv_install_dir, 'bin', 'python')) expected_shebang = create_new_style_shebang(os.path.join( path, 'bin/python')) with open(temp.name, 'w') as f: f.write(build_time_shebang) deployment.fix_shebangs() with open(temp.name) as f: eq_(f.read(), expected_shebang) @patch('os.path.exists', lambda x: False) @patch('subprocess.check_call') def test_install_dependencies_with_no_requirements(callmock): d = Deployment('test') d.pip_prefix = ['pip'] d.install_dependencies() callmock.assert_has_calls([]) @patch('os.path.exists', lambda x: True) @patch('subprocess.check_call') def test_install_dependencies_with_requirements(callmock): d = Deployment('test') d.pip_prefix = ['pip'] d.pip_args = ['install'] d.install_dependencies() callmock.assert_called_with( ['pip', 'install', '-r', './requirements.txt']) @patch('subprocess.check_call') def test_install_dependencies_with_preinstall(callmock): d = Deployment('test', preinstall=['foobar']) d.pip_prefix = d.pip_preinstall_prefix = ['pip'] d.pip_args = ['install'] d.install_dependencies() callmock.assert_called_with( ['pip', 'install', 'foobar']) @patch('subprocess.check_call') def test_upgrade_pip(callmock): d = Deployment('test', upgrade_pip=True) d.pip_prefix = d.pip_preinstall_prefix = ['pip'] d.pip_args = ['install'] d.install_dependencies() callmock.assert_called_with( ['pip', 'install', ANY, '-U', 'pip']) @patch('subprocess.check_call') def test_upgrade_pip_with_preinstall(callmock): d = Deployment('test', upgrade_pip=True, preinstall=['foobar']) d.pip_prefix = d.pip_preinstall_prefix = ['pip'] d.pip_args = ['install'] d.install_dependencies() callmock.assert_has_calls([ call(['pip', 'install', ANY, '-U', 'pip']), call(['pip', 'install', 'foobar'])]) @patch('os.path.exists', lambda x: True) @patch('subprocess.check_call') def test_install_dependencies_with_preinstall_with_requirements(callmock): d = Deployment('test', preinstall=['foobar']) d.pip_prefix = d.pip_preinstall_prefix = ['pip'] d.pip_args = ['install'] d.install_dependencies() callmock.assert_has_calls([ call(['pip', 'install', 'foobar']), call(['pip', 'install', '-r', './requirements.txt']) ]) @patch('os.path.exists', return_value=True) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_custom_pip_tool_used_for_installation(callmock, _): d = Deployment( 'test', preinstall=['pip-custom-platform'], pip_tool='pip-custom-platform', ) d.install_dependencies() d.install_package() callmock.assert_has_calls([ call([PY_CMD, PIP_CMD, 'install', LOG_ARG, 'pip-custom-platform']), call([PY_CMD, CUSTOM_PIP_CMD, 'install', LOG_ARG, '-r', './requirements.txt']), call([PY_CMD, CUSTOM_PIP_CMD, 'install', LOG_ARG, '.'], cwd=os.path.abspath('.')), ]) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_create_venv(callmock): d = Deployment('test') d.create_virtualenv() eq_(TEST_VENV_PATH, d.package_dir) callmock.assert_called_with(['virtualenv', TEST_VENV_PATH]) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_create_venv_with_verbose(callmock): d = Deployment('test', verbose=True) d.create_virtualenv() eq_(TEST_VENV_PATH, d.package_dir) callmock.assert_called_with(['virtualenv', '--verbose', TEST_VENV_PATH]) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_create_venv_with_extra_urls(callmock): d = Deployment('test', extra_urls=['foo', 'bar']) d.create_virtualenv() eq_(TEST_VENV_PATH, d.package_dir) callmock.assert_called_with(['virtualenv', TEST_VENV_PATH]) eq_([PY_CMD, PIP_CMD], d.pip_prefix) eq_(['install', '--extra-index-url=foo', '--extra-index-url=bar', LOG_ARG], d.pip_args) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_create_venv_with_extra_virtualenv(callmock): d = Deployment('test', extra_virtualenv_arg=["--never-download"]) d.create_virtualenv() eq_(TEST_VENV_PATH, d.package_dir) callmock.assert_called_with(['virtualenv', '--never-download', TEST_VENV_PATH]) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_create_venv_with_custom_index_url(callmock): d = Deployment('test', extra_urls=['foo', 'bar'], index_url='http://example.com/simple') d.create_virtualenv() eq_(TEST_VENV_PATH, d.package_dir) callmock.assert_called_with(['virtualenv', TEST_VENV_PATH]) eq_([PY_CMD, PIP_CMD], d.pip_prefix) eq_(['install', '--index-url=http://example.com/simple', '--extra-index-url=foo', '--extra-index-url=bar', LOG_ARG], d.pip_args) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_create_venv_with_extra_pip_arg(callmock): d = Deployment('test', extra_pip_arg=['--no-compile']) d.create_virtualenv() d.install_dependencies() eq_(TEST_VENV_PATH, d.package_dir) callmock.assert_called_with(['virtualenv', TEST_VENV_PATH]) eq_([PY_CMD, PIP_CMD], d.pip_prefix) eq_(['install', LOG_ARG, '--no-compile'], d.pip_args) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_create_venv_with_setuptools(callmock): d = Deployment('test', setuptools=True) d.create_virtualenv() eq_(TEST_VENV_PATH, d.package_dir) callmock.assert_called_with(['virtualenv', '--setuptools', TEST_VENV_PATH]) eq_([PY_CMD, PIP_CMD], d.pip_prefix) eq_(['install', LOG_ARG], d.pip_args) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_create_venv_with_system_packages(callmock): d = Deployment('test', use_system_packages=True) d.create_virtualenv() eq_(TEST_VENV_PATH, d.package_dir) callmock.assert_called_with(['virtualenv', '--system-site-packages', TEST_VENV_PATH]) eq_([PY_CMD, PIP_CMD], d.pip_prefix) eq_(['install', LOG_ARG], d.pip_args) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_venv_with_custom_python(callmock): d = Deployment('test', python='/tmp/python') d.create_virtualenv() eq_(TEST_VENV_PATH, d.package_dir) callmock.assert_called_with(['virtualenv', '--python', '/tmp/python', TEST_VENV_PATH]) eq_([PY_CMD, PIP_CMD], d.pip_prefix) eq_(['install', LOG_ARG], d.pip_args) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_install_package(callmock): d = Deployment('test') d.bin_dir = 'derp' d.pip_prefix = ['derp/python', 'derp/pip'] d.pip_args = ['install'] d.install_package() callmock.assert_called_with([ 'derp/python', 'derp/pip', 'install', '.', ], cwd=os.getcwd()) def test_fix_activate_path(): deployment = Deployment('test') temp = tempfile.NamedTemporaryFile() with open(temp.name, 'w') as fh: fh.write(textwrap.dedent(""" other things VIRTUAL_ENV="/this/path/is/wrong/and/longer/than/new/path" more other things """)) expected = textwrap.dedent(""" other things VIRTUAL_ENV="/opt/venvs/test" more other things """) with patch('dh_virtualenv.deployment.os.path.join', return_value=temp.name): deployment.fix_activate_path() with open(temp.name) as fh: eq_(expected, fh.read()) @patch('os.path.exists', lambda x: True) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) @patch('subprocess.check_call') def test_custom_src_dir(callmock): d = Deployment('test') d.sourcedirectory = 'root/srv/application' d.create_virtualenv() d.install_dependencies() callmock.assert_called_with([ PY_CMD, PIP_CMD, 'install', LOG_ARG, '-r', 'root/srv/application/requirements.txt'], ) d.install_package() callmock.assert_called_with([ PY_CMD, PIP_CMD, 'install', LOG_ARG, '.', ], cwd=os.path.abspath('root/srv/application')) @patch('os.path.exists', lambda *a: True) @patch('subprocess.check_call') def test_testrunner(callmock): d = Deployment('test') d.run_tests() callmock.assert_called_once_with([ PY_CMD, 'setup.py', 'test', ], cwd='.') @patch('os.path.exists', lambda *a: False) @patch('subprocess.check_call') def test_testrunner_setuppy_not_found(callmock): d = Deployment('test') d.run_tests() eq_(callmock.call_count, 0) @patch('tempfile.NamedTemporaryFile', FakeTemporaryFile) def test_deployment_from_options(): options, _ = get_default_parser().parse_args([ '--extra-index-url', 'http://example.com', '-O--pypi-url', 'http://example.org' ]) d = Deployment.from_options('foo', options) eq_(d.package, 'foo') eq_(d.pip_args, ['install', '--index-url=http://example.org', '--extra-index-url=http://example.com', LOG_ARG]) def test_deployment_from_options_with_verbose(): options, _ = get_default_parser().parse_args([ '--verbose' ]) d = Deployment.from_options('foo', options) eq_(d.package, 'foo') eq_(d.verbose, True) @patch('os.environ.get') def test_deployment_from_options_with_verbose_from_env(env_mock): env_mock.return_value = '1' options, _ = get_default_parser().parse_args([]) d = Deployment.from_options('foo', options) eq_(d.package, 'foo') eq_(d.verbose, True) @temporary_dir def test_fix_local_symlinks(deployment_dir): d = Deployment('testing') d.package_dir = deployment_dir local = os.path.join(deployment_dir, 'local') os.makedirs(local) target = os.path.join(deployment_dir, 'sometarget') symlink = os.path.join(local, 'symlink') os.symlink(target, symlink) d.fix_local_symlinks() eq_(os.readlink(symlink), '../sometarget') @temporary_dir def test_fix_local_symlinks_with_relative_links(deployment_dir): # Runs shouldn't ruin the already relative symlinks. d = Deployment('testing') d.package_dir = deployment_dir local = os.path.join(deployment_dir, 'local') os.makedirs(local) symlink = os.path.join(local, 'symlink') os.symlink('../target', symlink) d.fix_local_symlinks() eq_(os.readlink(symlink), '../target') @temporary_dir def test_fix_local_symlinks_does_not_blow_up_on_missing_local(deployment_dir): d = Deployment('testing') d.package_dir = deployment_dir d.fix_local_symlinks() @temporary_dir def test_find_script_files_normal_shebang(bin_dir): d = Deployment('testing') d.bin_dir = bin_dir script_files = [os.path.join(bin_dir, s) for s in ('s1', 's2', 's3')] for script in script_files: with open(os.path.join(bin_dir, script), 'w') as f: f.write('#!/usr/bin/python\n') with open(os.path.join(bin_dir, 'n1'), 'w') as f: f.write('#!/bin/bash') found_files = sorted(d.find_script_files()) eq_(found_files, script_files) @temporary_dir def test_find_script_files_long_shebang(bin_dir): d = Deployment('testing') d.bin_dir = bin_dir script_files = [os.path.join(bin_dir, s) for s in ('s1', 's2', 's3')] for script in script_files: with open(os.path.join(bin_dir, script), 'w') as f: # It does not really matter what we write into the # exec statement as executable here f.write( create_new_style_shebang('/usr/bin/python')) with open(os.path.join(bin_dir, 'n1'), 'w') as f: f.write('#!/bin/bash') found_files = sorted(d.find_script_files()) eq_(found_files, script_files) tox.ini000066400000000000000000000001671374426432200124040ustar00rootroot00000000000000[tox] envlist = py27,py35,py36,py37,py38 [testenv] deps = -r{toxinidir}/travis-requirements.txt commands = nosetests travis-requirements.txt000066400000000000000000000001721374426432200156570ustar00rootroot00000000000000Jinja2==2.7.1 MarkupSafe==0.18 Pygments==1.6 Sphinx==1.7.5 sphinx-rtd-theme==0.4.0 docutils==0.11 mock==1.0.1 nose==1.3.7