Skip to content

Commit

Permalink
Use requirements.txt (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
hlin committed Sep 2, 2019
1 parent b389c98 commit 31906a9
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 38 deletions.
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
include LICENSE
include requirements.txt
include test-requirements.txt
41 changes: 23 additions & 18 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,35 @@ Installation and setup

1. Install the prerequisite system packages::

$ sudo yum -y install postgresql-devel krb5-devel rpm-devel gcc python-devel
$ sudo dnf -y install postgresql-devel krb5-devel rpm-devel gcc python-devel python3-virtualenvwrapper

2. Set up a virtualenv::

$ virtualenv venv
$ mkvirtualenv -p python3 plm

3. Activate the virtualenv::
... Run ``source /usr/bin/virtualenvwrapper.sh`` if ``mkvirtualenv`` command not available

$ . venv/bin/activate
3. Install the prerequisite packages::

4. Install the prerequisite packages::
$ workon plm
$ pip install -r requirements.txt

$ python setup.py install

5. Create ``config.py`` with the database settings::
4. Create ``config.py`` with the database settings::

$ echo "SQLALCHEMY_DATABASE_URI = 'postgresql://myusername:mypass@dbhost/dbname'" > config.py
$ vi config.py

6. Set the ``PLM_CONFIG_FILE`` environment variable to the full filesystem path of
5. Set the ``PLM_CONFIG_FILE`` environment variable to the full filesystem path of
this new file::

$ export PLM_CONFIG_FILE=$(pwd)/config.py

7. Install brewkoji package. This creates ``/etc/koji.conf.d/brewkoji.conf``,
6. Install brewkoji package. This creates ``/etc/koji.conf.d/brewkoji.conf``,
so ``products.py`` can contact the Brew hub::

$ sudo yum -y install brewkoji
$ sudo dnf -y install brewkoji

8. Trust Brew's SSL certificate::
7. Trust Brew's SSL certificate::

$ export REQUESTS_CA_BUNDLE=/etc/pki/ca-trust/source/anchors/RH-IT-Root-CA.crt

Expand All @@ -99,7 +98,7 @@ Installation and setup

$ export REQUESTS_CA_BUNDLE=/etc/pki/tls/certs/ca-bundle.crt

9. Run the server::
8. Run the server::

$ FLASK_APP=product_listings_manager.app flask run

Expand All @@ -110,16 +109,22 @@ You can access the http://localhost:5000/ at that point.
Running the tests
-----------------

Install required packages for test::

$ pip install -r test-requirements.txt

You can invoke the tests with ``tox``::

$ pip install tox
$ tox

Alternatively, you can run pytest directly. In this example I add the
``--live`` argument to run against the live composedb instance::
Alternatively, you can run pytest directly::

$ pytest --cov=product_listings_manager tests

Using the ``--live`` argument if you want to run against the live composedb instance::

$ pytest --cov=product_listings_manager --live tests

$ pip install pytest
$ python -m pytest --live product_listings_manager/tests/

Configuring a local database
----------------------------
Expand Down
9 changes: 9 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# This is a list of pypi packages to be installed into virtualenv. Alternatively,
# you can install these as RPMs instead of pypi packages.

Flask
Flask-Restful
Flask-SQLAlchemy
SQLAlchemy
koji
psycopg2-binary
36 changes: 21 additions & 15 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
import os
import re
from setuptools import setup, find_packages


Expand All @@ -12,6 +12,24 @@ def read_module_contents():
return init.read()


def read_requirements(filename):
specifiers = []
dep_links = []
with open(filename, 'r') as f:
for line in f:
if line.startswith('-r') or line.strip() == '':
continue
if line.startswith('git+'):
dep_links.append(line.strip())
else:
specifiers.append(line.strip())
return specifiers, dep_links


setup_py_path = os.path.dirname(os.path.realpath(__file__))
install_requires, _ = read_requirements(os.path.join(setup_py_path, 'requirements.txt'))
tests_requires, _ = read_requirements(os.path.join(setup_py_path, 'test-requirements.txt'))

module_file = read_module_contents()
metadata = dict(re.findall(r"__([a-z]+)__\s*=\s*'([^']+)'", module_file))
version = metadata['version']
Expand All @@ -37,18 +55,6 @@ def read_module_contents():
license='MIT',
long_description=LONG_DESCRIPTION,
packages=find_packages(exclude=['tests']),
install_requires=[
'Flask',
'Flask-Restful',
'Flask-SQLAlchemy',
'SQLAlchemy',
'koji',
'psycopg2-binary',
],
tests_require=[
'pytest',
'pytest-cov',
'mock',
'factory-boy'
],
install_requires=install_requires,
tests_require=tests_requires
)
8 changes: 8 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Packages required for test

factory-boy
flake8
mock
pytest
pytest-cov
tox
7 changes: 2 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ setenv =
# Set RPM_PY_VERBOSE to "true" to debug koji package installation failures
passenv = RPM_PY_VERBOSE
deps =
pytest
pytest-cov
mock
factory-boy
flake8
-rrequirements.txt
-rtest-requirements.txt
commands =
flake8
pytest --cov=product_listings_manager --cov-report=term-missing -v tests
Expand Down

0 comments on commit 31906a9

Please sign in to comment.