Skip to content

Commit 01133a3

Browse files
committed
Improve setup and config
* Bump requirements and use only minimum version * Align Makefile with other projects * Enable code validation and formatting Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent cebf847 commit 01133a3

File tree

4 files changed

+137
-192
lines changed

4 files changed

+137
-192
lines changed

Makefile

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
1-
# SPDX-License-Identifier: Apache-2.0
21
#
32
# Copyright (c) nexB Inc. and others. All rights reserved.
4-
# ScanCode is a trademark of nexB Inc.
3+
# FederatedCode is a trademark of nexB Inc.
54
# SPDX-License-Identifier: Apache-2.0
6-
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
7-
# See https://github.com/nexB/skeleton for support or download.
8-
# See https://aboutcode.org for more information about nexB OSS projects.
5+
# See https://github.com/nexB/federatedcode for support or download.
6+
# See https://aboutcode.org for more information about AboutCode FOSS projects.
97
#
10-
include .env
8+
# include .env
119

1210
# Python version can be specified with `$ PYTHON_EXE=python3.x make conf`
1311
PYTHON_EXE?=python3
1412
VENV=venv
13+
MANAGE=${VENV}/bin/python manage.py
1514
ACTIVATE?=. ${VENV}/bin/activate;
1615
MANAGE=${VENV}/bin/python manage.py
16+
BLACK_ARGS=--exclude=".cache|migrations|data|venv|lib|bin|var|etc"
17+
# Do not depend on Python to generate the SECRET_KEY
18+
GET_SECRET_KEY=`base64 /dev/urandom | head -c50`
19+
# Customize with `$ make envfile ENV_FILE=/etc/federatedcode/.env`
20+
ENV_FILE=.env
21+
# Customize with `$ make postgres FEDERATEDCODE_DB_PASSWORD=YOUR_PASSWORD`
22+
FEDERATEDCODE_DB_NAME=federatedcode
23+
FEDERATEDCODE_DB_USER=federatedcode
24+
FEDERATEDCODE_DB_PASSWORD=federatedcode
25+
POSTGRES_INITDB_ARGS=--encoding=UTF-8 --lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8
26+
DATE=$(shell date +"%Y-%m-%d_%H%M")
1727

1828
# Use sudo for postgres, but only on Linux
1929
UNAME := $(shell uname)
@@ -35,55 +45,68 @@ envfile:
3545

3646
isort:
3747
@echo "-> Apply isort changes to ensure proper imports ordering"
38-
${VENV}/bin/isort --sl -l 100 tests setup.py
48+
@${ACTIVATE} isort --profile black .
3949

4050
black:
4151
@echo "-> Apply black code formatter"
42-
${VENV}/bin/black -l 100 tests setup.py
52+
@${ACTIVATE} black ${BLACK_ARGS} .
4353

4454
doc8:
4555
@echo "-> Run doc8 validation"
4656
@${ACTIVATE} doc8 --max-line-length 100 --ignore-path docs/_build/ --quiet docs/
4757

48-
valid: isort black
58+
valid: isort black doc8
59+
60+
bandit:
61+
@echo "-> Run source code security analyzer"
62+
@${ACTIVATE} bandit -r fedcode federatedcode --quiet
4963

50-
check:
51-
@echo "-> Run pycodestyle (PEP8) validation"
52-
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=.eggs,venv,lib,thirdparty,docs,migrations,settings.py,.cache .
64+
check: doc8 bandit
65+
@echo "-> Run flake8 (pycodestyle, pyflakes, mccabe) validation"
66+
@${ACTIVATE} flake8 .
5367
@echo "-> Run isort imports ordering validation"
54-
@${ACTIVATE} isort --sl --check-only -l 100 setup.py tests .
68+
@${ACTIVATE} isort --profile black --check-only .
5569
@echo "-> Run black validation"
56-
@${ACTIVATE} black --check --check -l 100 tests setup.py
70+
@${ACTIVATE} black --check ${BLACK_ARGS} .
71+
@echo "-> Run docstring validation"
72+
@${ACTIVATE} pydocstyle fedcode federatedcode
73+
74+
check-deploy:
75+
@echo "-> Check Django deployment settings"
76+
${MANAGE} check --deploy
5777

5878
clean:
5979
@echo "-> Clean the Python env"
6080
./configure --clean
6181

82+
migrate:
83+
@echo "-> Apply database migrations"
84+
${MANAGE} migrate
85+
6286
test:
6387
@echo "-> Run the test suite"
64-
${VENV}/bin/pytest -vvs
88+
@${ACTIVATE} pytest -vvs
6589

6690
docs:
6791
rm -rf docs/_build/
6892
@${ACTIVATE} sphinx-build docs/source docs/_build/
6993

70-
postgres:
94+
postgresdb:
7195
@echo "-> Configure PostgreSQL database"
72-
@echo "-> Create database user '${POSTGRES_DB}'"
73-
${SUDO_POSTGRES} createuser --no-createrole --no-superuser --login --inherit --createdb ${POSTGRES_DB} || true
74-
${SUDO_POSTGRES} psql -c "alter user ${POSTGRES_USER} with encrypted password '${POSTGRES_PASSWORD}';" || true
75-
@echo "-> Drop '${POSTGRES_DB}' database"
76-
${SUDO_POSTGRES} dropdb ${POSTGRES_DB} || true
77-
@echo "-> Create '${POSTGRES_DB}' database"
78-
${SUDO_POSTGRES} createdb --encoding=utf-8 --owner=${POSTGRES_USER} ${POSTGRES_DB}
96+
@echo "-> Create database user ${FEDERATEDCODE_DB_NAME}"
97+
@${SUDO_POSTGRES} createuser --no-createrole --no-superuser --login --inherit --createdb '${FEDERATEDCODE_DB_USER}' || true
98+
@${SUDO_POSTGRES} psql -c "alter user ${FEDERATEDCODE_DB_USER} with encrypted password '${FEDERATEDCODE_DB_PASSWORD}';" || true
99+
@echo "-> Drop ${SCANCODEIO_DB_NAME} database"
100+
@${SUDO_POSTGRES} dropdb ${FEDERATEDCODE_DB_NAME} || true
101+
@echo "-> Create ${FEDERATEDCODE_DB_NAME} database"
102+
@${SUDO_POSTGRES} createdb --owner=${FEDERATEDCODE_DB_USER} ${POSTGRES_INITDB_ARGS} ${FEDERATEDCODE_DB_NAME}
79103
@$(MAKE) migrate
80104

81-
migrate:
82-
@echo "-> Apply database migrations"
83-
${MANAGE} migrate
105+
backupdb:
106+
pg_dump -Fc ${FEDERATEDCODE_DB_NAME} > "${FEDERATEDCODE_DB_NAME}-db-${DATE}.dump"
84107

85108
run:
86109
@echo "-> Starting development server"
87-
${MANAGE} runserver
110+
${MANAGE} runserver 8002 --insecure
88111

89-
.PHONY: conf dev check valid black isort clean test docs envfile postgres migrate run
112+
.PHONY: dev envfile isort black doc8 valid bandit check check-deploy clean migrate test docs postgresdb backupdb run

requirements-dev.txt

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,11 @@
11
aboutcode-toolkit==10.1.0
2-
alabaster==0.7.13
3-
anyio==4.1.0
4-
asgiref==3.7.2
5-
attrs==23.1.0
6-
Babel==2.14.0
72
black==23.7.0
8-
boolean.py==4.0
9-
certifi==2023.5.7
10-
cffi==1.15.1
11-
charset-normalizer==3.1.0
12-
click==8.1.7
13-
colorama==0.4.6
14-
cryptography==41.0.1
15-
dateparser==1.1.8
16-
Deprecated==1.2.14
17-
Django==5.0.1
18-
django-environ==0.11.2
19-
django-oauth-toolkit==2.3.0
20-
django-rest-framework==0.1.0
21-
djangorestframework==3.14.0
22-
docutils==0.20.1
23-
et-xmlfile==1.1.0
24-
exceptiongroup==1.1.1
253
execnet==2.0.2
26-
gitdb==4.0.10
27-
GitPython==3.1.40
28-
gunicorn==21.2.0
29-
h11==0.14.0
30-
http-message-signatures==0.4.4
31-
http-sfv==0.9.8
32-
httpcore==0.17.3
33-
httpx==0.25.1
34-
idna==3.4
35-
imagesize==1.4.1
36-
importlib-metadata==7.0.1
37-
iniconfig==2.0.0
384
isort==5.12.0
39-
jaraco.classes==3.3.0
40-
jeepney==0.8.0
41-
Jinja2==3.1.2
42-
jwcrypto==1.5.0
43-
keyring==24.3.0
44-
license-expression==30.2.0
45-
livereload==2.6.3
46-
markdown-it-py==3.0.0
47-
MarkupSafe==2.1.3
48-
mdurl==0.1.2
49-
more-itertools==10.1.0
50-
mypy-extensions==1.0.0
51-
nh3==0.2.15
52-
oauthlib==3.2.2
53-
openpyxl==3.1.2
54-
packageurl-python==0.11.1
55-
packaging==23.1
56-
pathspec==0.11.2
57-
Pillow==9.5.0
58-
pkginfo==1.9.6
59-
platformdirs==3.10.0
60-
pluggy==1.0.0
61-
psycopg==3.1.16
62-
psycopg-binary==3.1.16
63-
psycopg2-binary==2.9.9
64-
pycodestyle==2.11.1
65-
pycparser==2.21
66-
Pygments==2.17.2
675
pytest==7.3.2
686
pytest-django==4.5.2
697
pytest-xdist==3.5.0
708
python-dateutil==2.8.2
71-
pytz==2023.3
72-
PyYAML==6.0.1
73-
readme-renderer==42.0
74-
regex==2023.8.8
75-
requests==2.31.0
76-
requests-toolbelt==1.0.0
77-
rfc3986==2.0.0
78-
rich==13.7.0
79-
saneyaml==0.6.0
80-
SecretStorage==3.3.3
81-
six==1.16.0
82-
smmap==5.0.0
83-
sniffio==1.3.0
84-
snowballstemmer==2.2.0
859
Sphinx==7.2.6
8610
sphinx-autobuild==2021.3.14
8711
sphinx-copybutton==0.5.2
@@ -95,13 +19,3 @@ sphinxcontrib-jquery==4.1
9519
sphinxcontrib-jsmath==1.0.1
9620
sphinxcontrib-qthelp==1.0.6
9721
sphinxcontrib-serializinghtml==1.1.9
98-
sqlparse==0.4.4
99-
tomli==2.0.1
100-
tornado==6.4
101-
twine==4.0.2
102-
typing_extensions==4.6.3
103-
tzlocal==5.0.1
104-
unidiff==0.7.5
105-
urllib3==2.0.3
106-
wrapt==1.15.0
107-
zipp==3.17.0

requirements.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ anyio==4.1.0
44
asgiref==3.7.2
55
attrs==23.1.0
66
Babel==2.14.0
7-
black==23.7.0
87
boolean.py==4.0
98
certifi==2023.5.7
109
cffi==1.15.1
@@ -64,9 +63,6 @@ psycopg2-binary==2.9.9
6463
pycodestyle==2.11.1
6564
pycparser==2.21
6665
Pygments==2.17.2
67-
pytest==7.3.2
68-
pytest-django==4.5.2
69-
pytest-xdist==3.5.0
7066
python-dateutil==2.8.2
7167
pytz==2023.3
7268
PyYAML==6.0.1
@@ -82,19 +78,6 @@ six==1.16.0
8278
smmap==5.0.0
8379
sniffio==1.3.0
8480
snowballstemmer==2.2.0
85-
Sphinx==7.2.6
86-
sphinx-autobuild==2021.3.14
87-
sphinx-copybutton==0.5.2
88-
sphinx-reredirects==0.1.3
89-
sphinx-rtd-dark-mode==1.3.0
90-
sphinx-rtd-theme==2.0.0
91-
sphinxcontrib-applehelp==1.0.7
92-
sphinxcontrib-devhelp==1.0.5
93-
sphinxcontrib-htmlhelp==2.0.4
94-
sphinxcontrib-jquery==4.1
95-
sphinxcontrib-jsmath==1.0.1
96-
sphinxcontrib-qthelp==1.0.6
97-
sphinxcontrib-serializinghtml==1.1.9
9881
sqlparse==0.4.4
9982
tomli==2.0.1
10083
tornado==6.4

0 commit comments

Comments
 (0)