Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the movie lister example work on Windows #458

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,12 @@ src/dependency_injector/providers/*.so

# Workspace for samples
.workspace/
/examples/miniapps/movie-lister/wslenv2-win/Scripts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure we need these imports here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how the virtual environment is created under Windows.

/examples/miniapps/movie-lister/wslenv2-win
/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
5 changes: 2 additions & 3 deletions examples/miniapps/movie-lister/data/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@


def create_csv(movies_data, path):
with open(path, 'w') as opened_file:
with open(path, 'w', newline='') as opened_file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you remember what error you got before making this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message was:
TypeError: __init__() missing 3 required positional arguments: 'title', 'year', and 'director'
which was caused by the CSV data being created with extra carriage return and new line.

The movies.csv file was like this:

The Hunger Games: Mockingjay - Part 2,2015,Francis Lawrence

Rogue One: A Star Wars Story,2016,Gareth Edwards

The Jungle Book,2016,Jon Favreau

writer = csv.writer(opened_file)
for row in movies_data:
writer.writerow(row)
writer.writerows(movies_data)


def create_sqlite(movies_data, path):
Expand Down
4 changes: 2 additions & 2 deletions examples/miniapps/movie-lister/movies/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from dependency_injector.wiring import inject, Provide

from .listers import MovieLister
from .containers import Container
from movies.listers import MovieLister
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked for any specific behavior of relative imports on Windows, but didn't find anything. Seems like you've had a problem with it. Do you remember how you ran it and what was the problem?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a problem when using VS Code..

from movies.containers import Container


@inject
Expand Down
2 changes: 1 addition & 1 deletion examples/miniapps/movie-lister/movies/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion examples/miniapps/movie-lister/movies/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sqlite3
from typing import Callable, List

from .entities import Movie
from movies.entities import Movie


class MovieFinder:
Expand Down
2 changes: 1 addition & 1 deletion examples/miniapps/movie-lister/movies/listers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Movie listers module."""

from .finders import MovieFinder
from movies.finders import MovieFinder


class MovieLister:
Expand Down
2 changes: 1 addition & 1 deletion examples/miniapps/movie-lister/movies/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from .containers import Container
from movies.containers import Container


@pytest.fixture
Expand Down
11 changes: 11 additions & 0 deletions examples/miniapps/movie-lister/setup_and_run_movie_lister.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
echo on
set PYTHON37=%UserProfile%\AppData\Local\Programs\Python\Python37\python.exe
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure if it's ok to use a specific version of Python in the documentation. The idea is that this example should work for all supported Python versions.

Copy link
Author

@jpvandervelden jpvandervelden Jun 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could be removed and a comment added that the assumption is made that PATH environment variable is pointing to the python installation.


REM set variabless
set ENV_NAME=wslenv2-win
set VENV_DIR=%ENV_NAME%\Scripts
set PYTHON_VENV=%VENV_DIR%\python.exe

%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 & set MOVIE_FINDER_TYPE=csv& %PYTHON_VENV% -m movies & set MOVIE_FINDER_TYPE=sqlite& %PYTHON_VENV% -m movies&%VENV_DIR%\deactivate & pause & exit 0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to split this line to multiple? Kind of hard to scroll it now

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.. it is, by adding a ^as a multiline command separator.
I will check in the file again.

14 changes: 14 additions & 0 deletions examples/miniapps/movie-lister/setup_and_run_movie_lister.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash -ef

rm -rf wslenv2

python3 -m venv wslenv2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this is basically doing what is done in the readme, correct?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

. 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