mirror of
https://github.com/ets-labs/python-dependency-injector.git
synced 2024-11-22 17:47:02 +03:00
- 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:
parent
3888c4cc9a
commit
4206c333ae
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -77,3 +77,7 @@ src/dependency_injector/providers/*.so
|
||||||
/examples/miniapps/movie-lister/wslenv2/bin
|
/examples/miniapps/movie-lister/wslenv2/bin
|
||||||
/examples/miniapps/movie-lister/wslenv2/share/python-wheels
|
/examples/miniapps/movie-lister/wslenv2/share/python-wheels
|
||||||
/examples/miniapps/movie-lister/wslenv2
|
/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
|
||||||
|
|
|
@ -18,10 +18,9 @@ SQLITE_FILE = DIR / 'movies.db'
|
||||||
|
|
||||||
|
|
||||||
def create_csv(movies_data, path):
|
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)
|
writer = csv.writer(opened_file)
|
||||||
for row in movies_data:
|
writer.writerows(movies_data)
|
||||||
writer.writerow(row)
|
|
||||||
|
|
||||||
|
|
||||||
def create_sqlite(movies_data, path):
|
def create_sqlite(movies_data, path):
|
||||||
|
|
|
@ -4,8 +4,8 @@ import sys
|
||||||
|
|
||||||
from dependency_injector.wiring import inject, Provide
|
from dependency_injector.wiring import inject, Provide
|
||||||
|
|
||||||
from .listers import MovieLister
|
from movies.listers import MovieLister
|
||||||
from .containers import Container
|
from movies.containers import Container
|
||||||
|
|
||||||
|
|
||||||
@inject
|
@inject
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from dependency_injector import containers, providers
|
from dependency_injector import containers, providers
|
||||||
|
|
||||||
from . import finders, listers, entities
|
from movies import finders, listers, entities
|
||||||
|
|
||||||
|
|
||||||
class Container(containers.DeclarativeContainer):
|
class Container(containers.DeclarativeContainer):
|
||||||
|
|
|
@ -4,7 +4,7 @@ import csv
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from typing import Callable, List
|
from typing import Callable, List
|
||||||
|
|
||||||
from .entities import Movie
|
from movies.entities import Movie
|
||||||
|
|
||||||
|
|
||||||
class MovieFinder:
|
class MovieFinder:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Movie listers module."""
|
"""Movie listers module."""
|
||||||
|
|
||||||
from .finders import MovieFinder
|
from movies.finders import MovieFinder
|
||||||
|
|
||||||
|
|
||||||
class MovieLister:
|
class MovieLister:
|
||||||
|
|
|
@ -4,7 +4,7 @@ from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from .containers import Container
|
from movies.containers import Container
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|
|
@ -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
|
|
|
@ -6,12 +6,6 @@ set ENV_NAME=wslenv2-win
|
||||||
set VENV_DIR=%ENV_NAME%\Scripts
|
set VENV_DIR=%ENV_NAME%\Scripts
|
||||||
set PYTHON_VENV=%VENV_DIR%\python.exe
|
set PYTHON_VENV=%VENV_DIR%\python.exe
|
||||||
|
|
||||||
REM cleanup
|
|
||||||
rd /s /q %ENV_NAME%
|
|
||||||
|
|
||||||
%PYTHON37% -m venv %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"
|
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"
|
||||||
|
|
||||||
REM MOVIE_FINDER_TYPE=csv
|
|
||||||
REM MOVIE_FINDER_TYPE=sqlite
|
|
|
@ -4,9 +4,11 @@ rm -rf wslenv2
|
||||||
|
|
||||||
python3 -m venv wslenv2
|
python3 -m venv wslenv2
|
||||||
. wslenv2/bin/activate
|
. wslenv2/bin/activate
|
||||||
|
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
|
|
||||||
wslenv2/bin/python data/fixtures.py
|
wslenv2/bin/python data/fixtures.py
|
||||||
|
|
||||||
MOVIE_FINDER_TYPE=csv wslenv2/bin/python -m movies
|
MOVIE_FINDER_TYPE=csv wslenv2/bin/python -m movies
|
||||||
MOVIE_FINDER_TYPE=sqlite wslenv2/bin/python -m movies
|
MOVIE_FINDER_TYPE=sqlite wslenv2/bin/python -m movies
|
||||||
|
|
||||||
|
source deactivate
|
Loading…
Reference in New Issue
Block a user