Skip to content

Commit 753dd72

Browse files
authored
Merge pull request #480 from sbs2001/housekeeping
Remove old code and organize deps
2 parents 24e3396 + 5de32fe commit 753dd72

18 files changed

Lines changed: 109 additions & 302 deletions

File tree

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ jobs:
1919
uses: actions/cache@v2
2020
with:
2121
path: .venv
22-
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements.txt') }}
22+
key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements*.txt') }}
2323
restore-keys: |
2424
${{ runner.os }}-venv-
2525
2626
- name: Install dependencies
2727
run: |
2828
sudo apt install python3-dev postgresql libpq-dev build-essential libxml2-dev libxslt1-dev postgresql ncat
29-
python -m pip install --upgrade pip
29+
python -m pip install --upgrade pip
3030
3131
- uses: syphar/restore-virtualenv@v1
3232
id: cache-virtualenv
3333
with:
34-
requirement_files: requirements.txt # this is optional
34+
requirement_files: requirements*.txt # this is optional
3535

3636
- uses: syphar/restore-pip-download-cache@v1
3737
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
3838

39-
- run: pip install -r requirements.txt
39+
- run: pip install -r requirements.txt -r requirements-dev.txt
4040
if: steps.cache-virtualenv.outputs.cache-hit != 'true'
4141

4242
- name: Setup database

.github/workflows/upstream_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: |
3838
sudo apt install python3-dev postgresql libpq-dev build-essential libxml2-dev libxslt1-dev
3939
python -m pip install --upgrade pip
40-
pip install -r requirements.txt
40+
pip install -r requirements.txt -r requirements-dev.txt
4141
pip install pytest-xdist
4242
4343
- name: Run tests

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
- postgresql
66

77
install:
8-
- pip install -e . -r requirements.txt
8+
- pip install -e . -r requirements.txt -r requirements-dev.txt
99

1010
env:
1111
global:

README.rst

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,8 @@ Create a virtualenv, install dependencies, generate static files and run the dat
149149
python3 -m venv venv
150150
source venv/bin/activate
151151
pip install -r requirements.txt
152-
DJANGO_DEV=1 python manage.py collectstatic
153-
DJANGO_DEV=1 python manage.py migrate
154-
155-
The environment variable ``DJANGO_DEV`` is used to load settings suitable for
156-
development, defined in ``vulnerablecode/dev.py``. If you
157-
don't want to type it every time use ``export DJANGO_DEV=1`` instead.
158-
Do not use `DJANGO_DEV` in a production environment.
152+
python manage.py collectstatic
153+
python manage.py migrate
159154

160155

161156
For a production mode, an environment variable named ``SECRET_KEY`` needs to be
@@ -211,11 +206,11 @@ Non-Python dependencies are curated in::
211206

212207
Run Tests
213208
---------
214-
209+
Make sure to install dev dependencies by running ``pip install -r requirements-dev.txt``
215210
Use these commands to run code style checks and the test suite::
216211

217212
black -l 100 --check .
218-
DJANGO_DEV=1 python -m pytest
213+
python -m pytest
219214

220215

221216
Data import
@@ -233,23 +228,23 @@ for instructions on how to obtain your GitHub token.
233228

234229
To run all data importers use::
235230

236-
DJANGO_DEV=1 python manage.py import --all
231+
python manage.py import --all
237232

238233
To list available importers use::
239234

240-
DJANGO_DEV=1 python manage.py import --list
235+
python manage.py import --list
241236

242237
To run specific importers::
243238

244-
DJANGO_DEV=1 python manage.py import rust npm
239+
python manage.py import rust npm
245240

246241

247242
REST API access
248243
---------------
249244

250245
Start the webserver::
251246

252-
DJANGO_DEV=1 python manage.py runserver
247+
python manage.py runserver
253248

254249

255250
For full documentation about API endpoints use this URL::

etc/nix/flake.nix

Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
let
2121

2222
vulnerablecode-src = ./../..;
23+
requirements =
24+
builtins.readFile (vulnerablecode-src + "/requirements.txt");
25+
requirementsDev =
26+
builtins.readFile (vulnerablecode-src + "/requirements-dev.txt");
2327

2428
# Extract version from setup.py.
2529
version = builtins.head (builtins.match ''.*version=["']?([^"',]+).*''
@@ -53,9 +57,9 @@
5357
# mach-nix release) is usually insufficient. Use
5458
# ./get-latest-pypi-deps-db.sh to obtain the data rev & hash.
5559
pypiDataRev =
56-
"e9b0fc6b92cd6efbca7ba3b3d4a551bcc13a73c5"; # 2021-03-27T08:13:04Z
60+
"8dcec158c51f8a96f316630679222e436c1b078c"; # 2021-06-16T08:41:20Z
5761
pypiDataSha256 =
58-
"1ssa48l2iz8kncby1gfrbds79mg114dkhpxrridwcq6q2c37p62s";
62+
"0499zl39aia74f0i7fkn5dsy8244dkmcw4vzd5nf4kai605j2jli";
5963
});
6064

6165
in {
@@ -65,16 +69,17 @@
6569
with final.pkgs; {
6670

6771
pythonEnv = machnixFor.${system}.mkPython {
68-
requirements =
69-
builtins.readFile (vulnerablecode-src + "/requirements.txt");
72+
requirements = ''
73+
${requirements}
74+
'';
7075
};
7176

7277
vulnerablecode = stdenv.mkDerivation {
7378
inherit version;
7479
name = "vulnerablecode-${version}";
7580
src = vulnerablecode-src;
7681
dontConfigure = true; # do not use ./configure
77-
propagatedBuildInputs = [ pythonEnv postgresql gitMinimal];
82+
propagatedBuildInputs = [ pythonEnv postgresql gitMinimal ];
7883

7984
postPatch = ''
8085
# Make sure the pycodestyle binary in $PATH is used.
@@ -110,48 +115,53 @@
110115
forAllSystems (system: self.packages.${system}.vulnerablecode);
111116

112117
# Tests run by 'nix flake check' and by Hydra.
113-
checks = forAllSystems (system: {
114-
inherit (self.packages.${system}) vulnerablecode;
115-
116-
vulnerablecode-test = with nixpkgsFor.${system};
117-
stdenv.mkDerivation {
118-
name = "${vulnerablecode.name}-test";
119-
120-
buildInputs = [ wget vulnerablecode ];
121-
122-
# Used by pygit2.
123-
# See https://github.com/NixOS/nixpkgs/pull/72544#issuecomment-582674047.
124-
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
125-
126-
unpackPhase = "true";
127-
128-
buildPhase = ''
129-
source ${libSh}
130-
initPostgres $(pwd)
131-
export DJANGO_DEV=1
132-
${vulnerablecode}/manage.py migrate
118+
checks = forAllSystems (system:
119+
let
120+
pythonEnvDev = machnixFor.${system}.mkPython {
121+
requirements = ''
122+
${requirements}
123+
${requirementsDev}
133124
'';
134-
135-
doCheck = true;
136-
checkPhase = ''
137-
# Run pytest on the installed version. A running postgres
138-
# database server is needed.
139-
(
140-
cd ${vulnerablecode}
141-
black -l 100 --check .
142-
pytest -m "not webtest"
143-
)
144-
145-
# Launch the webserver and call the API.
146-
${vulnerablecode}/manage.py runserver &
147-
sleep 2
148-
wget http://127.0.0.1:8000/api/
149-
kill %1 # kill background task (i.e. webserver)
150-
'';
151-
152-
installPhase =
153-
"mkdir -p $out"; # make this derivation return success
154125
};
155-
});
126+
127+
in {
128+
inherit (self.packages.${system}) vulnerablecode;
129+
130+
vulnerablecode-test = with nixpkgsFor.${system};
131+
stdenv.mkDerivation {
132+
name = "${vulnerablecode.name}-test";
133+
134+
buildInputs = [ wget vulnerablecode pythonEnvDev ];
135+
136+
unpackPhase = "true";
137+
138+
buildPhase = ''
139+
source ${libSh}
140+
initPostgres $(pwd)
141+
export DJANGO_DEV=1
142+
${vulnerablecode}/manage.py migrate
143+
'';
144+
145+
doCheck = true;
146+
checkPhase = ''
147+
# Run pytest on the installed version. A running postgres
148+
# database server is needed.
149+
(
150+
cd ${vulnerablecode}
151+
black -l 100 --check .
152+
pytest -m "not webtest"
153+
)
154+
155+
# Launch the webserver and call the API.
156+
${vulnerablecode}/manage.py runserver &
157+
sleep 2
158+
wget http://127.0.0.1:8000/api/
159+
kill %1 # kill background task (i.e. webserver)
160+
'';
161+
162+
installPhase =
163+
"mkdir -p $out"; # make this derivation return success
164+
};
165+
});
156166
};
157167
}

requirements-dev.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pytest
2+
pytest-django
3+
freezegun
4+
ipython
5+
black

requirements.txt

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,17 @@
1-
aiohttp==3.7.4
2-
asgiref==3.2.7
3-
attrs==20.3.0
4-
backcall==0.1.0
5-
beautifulsoup4==4.7.1
6-
binaryornot==0.4.4
7-
cached-property==1.5.1
8-
cffi==1.14.0
9-
contextlib2==0.5.5
10-
decorator==4.4.2
11-
univers==21.4.16.6
12-
dj-database-url==0.4.2
13-
Django==3.0.14
14-
django-filter==2.2.0
15-
djangorestframework==3.11.2
16-
django-widget-tweaks==1.4.8
17-
drf-spectacular==0.13.0
18-
gunicorn==19.7.1
19-
importlib-metadata==1.3.0
20-
ipython==7.13.0
21-
ipython-genutils==0.2.0
22-
jedi==0.17.0
23-
lxml==4.6.3
24-
more-itertools==8.0.2
25-
packageurl-python==0.9.3
26-
packaging==20.9
27-
parso==0.7.0
28-
pexpect==4.8.0
29-
pickleshare==0.7.5
30-
pluggy==0.13.1
31-
prompt-toolkit==3.0.5
32-
black==20.8b1
33-
psycopg2==2.8.4
34-
ptyprocess==0.6.0
35-
py==1.10.0
36-
pycparser==2.20
37-
gitpython==3.1.14
38-
Pygments==2.7.4
39-
pyparsing==2.4.5
40-
pytest==6.2.3
41-
pytest-django==4.1.0
42-
django-widget-tweaks==1.4.8
43-
pytest-dependency==0.4.0
44-
pytest-django==4.1.0
45-
pytest-mock==1.13.0
46-
python-dateutil==2.8.1
47-
pytz==2019.3
48-
schema==0.7.4
49-
six==1.13.0
50-
soupsieve==1.9.5
51-
sqlparse==0.3.0
52-
tqdm==4.41.1
53-
traitlets==4.3.3
54-
wcwidth==0.1.7
55-
whitenoise==5.0.1
56-
zipp==0.6.0
57-
requests==2.23.0
58-
toml==0.10.2
59-
PyYAML==5.4
60-
freezegun==1.1.0
61-
saneyaml==0.5.2
1+
Django>=3.2.4
2+
psycopg2>=2.8.6
3+
requests>=2.25.1
4+
aiohttp>=3.7.4.post0
5+
djangorestframework>=3.12.4
6+
django-filter>=2.4.0
7+
django-widget-tweaks>=1.4.8
8+
drf-spectacular>=0.17.1
9+
packageurl-python>=0.9.4
10+
binaryornot>=0.4.4
11+
GitPython>=3.1.17
12+
univers>=21.4.16.6
13+
saneyaml>=0.5.2
14+
beautifulsoup4>=4.9.3
15+
python-dateutil>=2.8.1
16+
toml>=0.10.2
17+
lxml>=4.6.3

vulnerabilities/import_runner.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,9 @@
2424
import dataclasses
2525
import datetime
2626
import logging
27-
from collections import Counter
2827
from itertools import chain
29-
import traceback
30-
from typing import Set
3128
from typing import Tuple
3229

33-
from django.core import serializers
3430
from django.db import transaction
3531

3632
from vulnerabilities import models

0 commit comments

Comments
 (0)