1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
===============================
Building and developing pymssql
===============================
Required software
_________________
To build ``pymssql`` you should have:
* `Python <https://python.org>`_ >= 3.6 including development files.
Please research your OS usual software distribution channels,
e.g, ``python-dev`` or ``python-devel`` packages on Linux.
* `Cython <https://cython.org>`_ -
to compile ``pymssql`` source files to ``C``.
* `setuptools <https://pypi.org/project/setuptools>`_ -
for ``setup.py`` support.
* `setuptools_scm <https://pypi.org/project/setuptools_scm>`_ -
for extracting version information from ``git``.
* `wheel <https://pypi.org/project/wheel/>`_ -
for building python wheels.
* `FreeTDS <https://freetds.org>`_ >= 1.2 including development files.
Please research your OS usual software distribution channels,
e.g, ``freetds-dev`` or ``freetds-devel`` packages on Linux.
* `GNU gperf <https://www.gnu.org/software/gperf/>`_ -
a perfect hash function generator, needed for FreeTDS.
On Windows prebuild version is available from
`Chocolatey <https://chocolatey.org/packages/gperf>`_.
* `win-iconv <https://github.com/win-iconv/win-iconv>`_
(Windows only) - developing ``pymssql`` on Windows also requires this library
to build FreeTDS.
* `OpenSSL <https://openssl.org>`_ - If you need to connect to Azure make sure
FreeTDS is built with SSL support.
Please research your OS usual software distribution channels.
On Windows one easy way is to get prebuild libraries from
`Chocolatey <https://chocolatey.org/packages/openssl>`_.
For testing the following is required:
* Microsoft SQL Server.
One possibility is to use official docker images for Microsoft SQL Server
on Linux available `here <https://hub.docker.com/_/microsoft-mssql-server>`_.
* `pytest <https://pypi.org/project/pytest/>`_ -
to run the tests.
* `pytest-timeout <https://pypi.org/project/pytest-timeout/>`_ -
for limiting long running tests.
* `psutil <https://pypi.org/project/psutil/>`_ -
for memory monitoring.
* `gevent <https://pypi.org/project/gevent/>`_
(optional) - for async tests.
* `Sqlalchemy <https://pypi.org/project/SQLAlchemy/>`_ -
(optional) - for basic Sqlalchemy testing.
To build documentation `Sphinx <https://pypi.org/project/Sphinx/>`_ and
`sphinx-rtd-theme <https://pypi.org/project/sphinx-rtd-theme/>`_ are also needed.
Windows
_______
In addition to the requirements above when developing ``pymssql`` on the Windows
platform you will need these additional tools installed:
* Visual Studio C++ Compiler Tools, see
`Python documentation <https://devguide.python.org/setup/#windows>`_
for instructions on what components to install.
* `Cmake <https://cmake.org/download/>`_
for building FreeTDS and win-iconv.
* `curl <https://chocolatey.org/packages/curl>`_ -
for downloading FreeTDS and win-iconv.
.. note::
If Windows computer is not readily available then
`virtual machine <https://developer.microsoft.com/en-us/windows/downloads/virtual-machines/>`_
from Microsoft could be used.
Linux
_____
For example on Alpine Linux the following command will install all necessary
packages for building pymssql::
apk add git gcc musl-dev krb5-dev openssl-dev freetds-dev
For Debian-based distributions::
apt update
apt install apt-utils git build-essential freetds-dev libssl-dev libkrb5-dev
Building ``pymssql`` wheel
__________________________
It is recommended to use python virtual environment for building ``pymssql``::
python3 -m venv <path_to_pve>
if using ``bash``::
source <path_to_pve>/bin/activate
or if on Windows::
<path_to_pve>/scripts/activate.bat
then install required python packages::
pip install -U pip
pip install -r dev/requirements-dev.txt
If and now build wheel::
python3 setup.py bdist_wheel
or::
pip wheel .
Environment Variables
_____________________
By default ``setup.py`` links against OpenSSL if it is available,
links FreeTDS statically and looks for FreeTDS headers and libraries
in places standard for the OS, but
there are several environment variables for build customization:
LINK_FREETDS_STATICALLY = [YES|NO|1|0|TRUE|FALSE]
default - YES,
defines if FreeTDS is linked statically or not.
LINK_OPENSSL = [YES|NO|1|0|TRUE|FALSE]
default - YES,
defines if ``pymssql`` is linked against OpenSSL.
PYMSSQL_FREETDS
if defined, determines prefix of the FreeTDS installation.
PYMSSQL_FREETDS_INCLUDEDIR
if defined, allows to fine tune where to search for FreeTDS headers.
PYMSSQL_FREETDS_LIBDIR
if defined, allows to fine tune where to search for FreeTDS libraries.
Example:
.. code-block:: console
PYMSSQL_FREETDS=/tmp/freetds python3 setup.py bdist_wheel
Building FreeTDS and ``pymssql`` from scratch
_____________________________________________
If one wants to use some specific FreeTDS version then there is a script
``dev/build.py`` that downloads and builds required FreeTDS version sources
(and win-conv on Windows) and builds ``pymssql`` wheel.
Run::
python dev/build.py --help
for supported options.
Testing
_______
.. danger::
ALL DATA IN TESTING DBS WILL BE DELETED !!!!
You will need to install two additional packages for testing::
easy_install pytest SQLAlchemy
You should build the package with::
python setup.py develop
You need to setup a ``tests.cfg`` file in ``tests/`` with the correct DB
connection information for your environment::
cp tests/tests.cfg.tpl tests/tests.cfg
vim|emacs|notepad tests/tests.cfg
To run the tests::
cd tests # optional
py.test
Which will go through and run all the tests with the settings from the ``DEFAULT``
section of ``tests.cfg``.
To run with a different ``tests.cfg`` section::
py.test --pymssql-section=<secname>
example::
py.test --pymssql-section=AllTestsWillRun
to avoid slow tests::
py.test -m "not slow"
or::
py.test --skip-slow
to skip tests that require MSSQL server::
py.test --skip-mssql-server-required
to select specific tests to run::
py.test tests/test_types.py
py.test tests/test_types.py tests/test_sprocs.py
py.test tests/test_types.py::TestTypes
py.test tests/test_types.py::TestTypes::test_image
|