Skip to content

Commit bb700fa

Browse files
authored
[HOTFIX] Migrate from setup.py to poetry, tox QA (#2249)
* Migrate from setup.py to use poetry build and publish * Tox QA * Version is now configured only at pyproject.toml * Added poetry build test * Updated mobsf PyPI publishing workflow * Update local DBs
1 parent 6e329c0 commit bb700fa

File tree

16 files changed

+180337
-47782
lines changed

16 files changed

+180337
-47782
lines changed

.dockerignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
.dockerignore
66
.sonarcloud.properties
77
.pyup.yml
8+
.python-version
89
tox.ini
910
mobsf/db.sqlite3
1011
Dockerfile
@@ -15,8 +16,6 @@ build
1516
docker-compose.yml
1617
*.md
1718
venv
18-
setup.py
19-
MANIFEST.in
2019
setup.bat
2120
run.bat
2221
setup.sh

.github/workflows/mobsf-test.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
run: |
2727
python -m pip install pip==22.3.1 poetry==1.6.1
2828
29-
- name: Lint
29+
- name: Lint on Ubuntu
3030
if: startsWith(matrix.os, 'ubuntu')
3131
run: |
3232
python -m pip install --upgrade tox
@@ -52,14 +52,22 @@ jobs:
5252
5353
- name: Install Python dependencies
5454
run: |
55-
poetry install --only main --no-interaction --no-ansi || poetry install --only main --no-interaction --no-ansi || poetry install --only main --no-interaction --no-ansi
55+
poetry install --only main --no-root --no-interaction --no-ansi || poetry install --only main --no-root --no-interaction --no-ansi || poetry install --only main --no-root --no-interaction --no-ansi
5656
5757
- name: Migrate Database
5858
run: |
5959
poetry run python manage.py makemigrations
6060
poetry run python manage.py makemigrations StaticAnalyzer
6161
poetry run python manage.py migrate
62-
- name: Unit Tests
62+
63+
- name: Unit Tests on Ubuntu, macOS and Windows
6364
run: |
6465
git submodule update --init --recursive
6566
poetry run python manage.py test mobsf
67+
68+
- name: Python Package Test in Ubuntu and macOS
69+
if: startsWith(matrix.os, 'ubuntu') || startsWith(matrix.os, 'macOS')
70+
run: |
71+
poetry build
72+
python -m pip install dist/*.whl
73+
mobsf db

.github/workflows/python-publish.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ jobs:
1818
- name: Install dependencies
1919
run: |
2020
python -m pip install --upgrade pip
21-
pip install setuptools twine
21+
pip install poetry==1.6.1
2222
- name: Build and publish
2323
env:
24-
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
25-
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
24+
PYPI_TOKEN: ${{ secrets.PYPI_PASSWORD }}
2625
run: |
27-
python setup.py sdist
28-
twine upload dist/*
26+
poetry config pypi-token.pypi ${PYPI_TOKEN}
27+
poetry build
28+
poetry publish

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ classes-error.zip
6868
*/migrations/*
6969
.fuse_hidden*
7070
.tox
71+
.python-version
7172

7273
#MobSF Files
7374
mobsf/debug.log

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ RUN adduser $MOBSF_USER --shell /bin/false -u 9901 --ingroup $MOBSF_USER --gecos
6464
COPY poetry.lock pyproject.toml ./
6565
RUN python3 -m pip install --upgrade --no-cache-dir pip poetry==${POETRY_VERSION} && \
6666
poetry config virtualenvs.create false && \
67-
poetry install --only main --no-interaction --no-ansi
67+
poetry install --only main --no-root --no-interaction --no-ansi
6868

6969
# Cleanup
7070
RUN \

MANIFEST.in

Lines changed: 0 additions & 12 deletions
This file was deleted.

mobsf/__main__.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import platform
44

55
from django.core.management import execute_from_command_line
6+
from django.db import connection
7+
8+
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mobsf.MobSF.settings')
610

711

812
def db():
9-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mobsf.MobSF.settings')
1013
execute_from_command_line([
1114
'',
1215
'makemigrations',
@@ -23,10 +26,20 @@ def db():
2326

2427

2528
def main():
26-
if len(sys.argv) == 2:
27-
listen = sys.argv[1]
28-
else:
29-
listen = '127.0.0.1:8000'
29+
try:
30+
if not connection.introspection.table_names():
31+
db()
32+
except Exception:
33+
db()
34+
listen = '127.0.0.1:8000'
35+
if len(sys.argv) == 2 and sys.argv[1]:
36+
if sys.argv[1] == 'db':
37+
db()
38+
listen = None
39+
elif sys.argv[1]:
40+
listen = sys.argv[1]
41+
if not listen:
42+
exit(0)
3043
if platform.system() != 'Windows':
3144
sys.argv = [
3245
'',
@@ -36,6 +49,11 @@ def main():
3649
'--workers=1',
3750
'--threads=10',
3851
'--timeout=3600',
52+
'--log-level=citical',
53+
'--log-file=-',
54+
'--access-logfile=-',
55+
'--error-logfile=-',
56+
'--capture-output',
3957
]
4058
from gunicorn.app.wsgiapp import run
4159
run()

mobsf/signatures/exodus_trackers

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)