- Changed the creation of the CSV file so it doesn't add an additional newline, which made the example fail on Windows.

- Changed the relative imports to absolute imports so the example works out of the box in VS Code.
- Added a shell script and a batch file to run the example on Linux and Windows.
This commit is contained in:
Jan-Paul van der Velden 2021-06-04 12:51:18 +02:00
parent 3888c4cc9a
commit 4206c333ae
10 changed files with 16 additions and 29 deletions

4
.gitignore vendored
View File

@ -77,3 +77,7 @@ src/dependency_injector/providers/*.so
/examples/miniapps/movie-lister/wslenv2/bin
/examples/miniapps/movie-lister/wslenv2/share/python-wheels
/examples/miniapps/movie-lister/wslenv2
/examples/miniapps/movie-lister/setup_venv.bat
/examples/miniapps/movie-lister/setup_venv.sh
/examples/miniapps/movie-lister/run_movie_lister.bat
/examples/miniapps/movie-lister/run_movie_lister.sh

View File

@ -18,10 +18,9 @@ SQLITE_FILE = DIR / 'movies.db'
def create_csv(movies_data, path):
with open(path, 'w') as opened_file:
with open(path, 'w', newline='') as opened_file:
writer = csv.writer(opened_file)
for row in movies_data:
writer.writerow(row)
writer.writerows(movies_data)
def create_sqlite(movies_data, path):

View File

@ -4,8 +4,8 @@ import sys
from dependency_injector.wiring import inject, Provide
from .listers import MovieLister
from .containers import Container
from movies.listers import MovieLister
from movies.containers import Container
@inject

View File

@ -2,7 +2,7 @@
from dependency_injector import containers, providers
from . import finders, listers, entities
from movies import finders, listers, entities
class Container(containers.DeclarativeContainer):

View File

@ -4,7 +4,7 @@ import csv
import sqlite3
from typing import Callable, List
from .entities import Movie
from movies.entities import Movie
class MovieFinder:

View File

@ -1,6 +1,6 @@
"""Movie listers module."""
from .finders import MovieFinder
from movies.finders import MovieFinder
class MovieLister:

View File

@ -4,7 +4,7 @@ from unittest import mock
import pytest
from .containers import Container
from movies.containers import Container
@pytest.fixture

View File

@ -1,12 +0,0 @@
echo on
set PYTHON37=%UserProfile%\AppData\Local\Programs\Python\Python37\python.exe
REM set variabless
set ENV_NAME=wslenv2-win
set VENV_DIR=%ENV_NAME%\Scripts
set PYTHON_VENV=%VENV_DIR%\python.exe
Start /WAIT cmd /k "%VENV_DIR%\activate & cd & %PYTHON_VENV% data/fixtures.py & set MOVIE_FINDER_TYPE=sqlite & %PYTHON_VENV% -m movies & %VENV_DIR%\deactivate & pause & exit 0"
REM MOVIE_FINDER_TYPE=csv
REM MOVIE_FINDER_TYPE=sqlite

View File

@ -6,12 +6,6 @@ set ENV_NAME=wslenv2-win
set VENV_DIR=%ENV_NAME%\Scripts
set PYTHON_VENV=%VENV_DIR%\python.exe
REM cleanup
rd /s /q %ENV_NAME%
%PYTHON37% -m venv %ENV_NAME%
Start /WAIT cmd /k "%VENV_DIR%\activate & %PYTHON_VENV% -m pip install --upgrade pip & %PYTHON_VENV% -m pip install -r .\requirements.txt & %VENV_DIR%\deactivate & pause & exit 0"
REM MOVIE_FINDER_TYPE=csv
REM MOVIE_FINDER_TYPE=sqlite
Start /WAIT cmd /k "%VENV_DIR%\activate & %PYTHON_VENV% -m pip install --upgrade pip & %PYTHON_VENV% -m pip install -r .\requirements.txt & set MOVIE_FINDER_TYPE=csv& %PYTHON_VENV% -m movies & set MOVIE_FINDER_TYPE=sqlite& %PYTHON_VENV% -m movies&%VENV_DIR%\deactivate & pause & exit 0"

View File

@ -4,9 +4,11 @@ rm -rf wslenv2
python3 -m venv wslenv2
. wslenv2/bin/activate
pip install -r requirements.txt
wslenv2/bin/python data/fixtures.py
MOVIE_FINDER_TYPE=csv wslenv2/bin/python -m movies
MOVIE_FINDER_TYPE=sqlite wslenv2/bin/python -m movies
source deactivate