Skip to content

Commit

Permalink
Use venv
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-zakharenkov committed Mar 14, 2024
1 parent 1ad072b commit 7031e4d
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 27 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8==6.0.0 black==23.1.0 shapely==2.0.1
pip install flake8==6.0.0 black==23.1.0
pip install -r subways/requirements.txt
pip install -r tools/make_poly/requirements.txt
- name: Lint with flake8
run: |
flake8
Expand All @@ -36,4 +37,6 @@ jobs:
black --check --line-length 79 .
- name: Test with unittest
run: |
python -m unittest discover tests
export PYTHONPATH=$(pwd)
python -m unittest discover subways
python -m unittest discover tools/make_poly
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ if you allow the `scripts/process_subway.py` to fetch data from Overpass API. He
git clone https://github.com/alexey-zakharenkov/subways.git subways_validator
cd subways_validator
```
3. Install python dependencies
3. Activate virtual environment
```bash
pip install -r subways/requirements.txt
[ -d '.venv' ] || bash scripts/create_venv.sh
source .venv/bin/activate
```
4. Execute
```bash
Expand Down
9 changes: 9 additions & 0 deletions scripts/create_venv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
set -e -u

echo "Create virtualenv and install python dependencies"
SUBWAYS_REPO_PATH="$(readlink -f $(dirname "$0")/..)"
"${PYTHON:-python3.11}" -m venv "$SUBWAYS_REPO_PATH"/.venv
source "$SUBWAYS_REPO_PATH"/.venv/bin/activate
pip install --upgrade pip
pip install -r "$SUBWAYS_REPO_PATH"/subways/requirements.txt
34 changes: 19 additions & 15 deletions scripts/process_subways.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,39 +91,43 @@ function check_poly() {

if [ -z "${POLY-}" -o ! -f "${POLY-}" ]; then
POLY=${POLY:-$(mktemp "$TMPDIR/all-metro.XXXXXXXX.poly")}
if [ -n "$("$PYTHON" -c "import shapely" 2>&1)" ]; then
"$PYTHON" -m pip install shapely==2.0.1
fi
"$PYTHON" "$SUBWAYS_REPO_PATH"/tools/make_poly/make_all_metro_poly.py \
python -m pip install -r "$SUBWAYS_REPO_PATH"/tools/make_poly/requirements.txt
python "$SUBWAYS_REPO_PATH"/tools/make_poly/make_all_metro_poly.py \
${CITIES_INFO_URL:+--cities-info-url "$CITIES_INFO_URL"} > "$POLY"
fi
fi
POLY_CHECKED=1
fi
}


PYTHON=${PYTHON:-python3}
# This will fail if there is no python
"$PYTHON" --version > /dev/null

# "readlink -f" echoes canonicalized absolute path to a file/directory
SUBWAYS_REPO_PATH="$(readlink -f $(dirname "$0")/..)"

if [ ! -f "$SUBWAYS_REPO_PATH/scripts/process_subways.py" ]; then
echo "Please clone the subways repo to $SUBWAYS_PATH"
echo "Please clone the subways repo to $SUBWAYS_REPO_PATH"
exit 2
fi

TMPDIR="${TMPDIR:-$SUBWAYS_REPO_PATH}"
mkdir -p "$TMPDIR"
# Check/create virtual environment

if [ ! -d "$SUBWAYS_REPO_PATH/.venv" ]; then
PYTHON="$PYTHON" bash "$SUBWAYS_REPO_PATH/scripts/create_venv.sh"
fi
source "$SUBWAYS_REPO_PATH/.venv/bin/activate"
export PYTHONPATH="$SUBWAYS_REPO_PATH"


# Downloading the latest version of the subways script
if [ -n "${GIT_PULL-}" ]; then (
cd "$SUBWAYS_PATH"
pushd "$SUBWAYS_REPO_PATH"
git pull origin master
popd
) fi


TMPDIR="${TMPDIR:-"$SUBWAYS_REPO_PATH"}"
mkdir -p "$TMPDIR"

if [ -z "${FILTERED_DATA-}" ]; then
FILTERED_DATA="$TMPDIR/subways.osm"
NEED_TO_REMOVE_FILTERED_DATA=1
Expand Down Expand Up @@ -244,7 +248,7 @@ if [ -n "${DUMP-}" ]; then
fi

VALIDATION="$TMPDIR/validation.json"
"$PYTHON" "$SUBWAYS_REPO_PATH/scripts/process_subways.py" ${QUIET:+-q} \
python "$SUBWAYS_REPO_PATH/scripts/process_subways.py" ${QUIET:+-q} \
-x "$FILTERED_DATA" -l "$VALIDATION" \
${CITIES_INFO_URL:+--cities-info-url "$CITIES_INFO_URL"} \
${MAPSME:+--output-mapsme "$MAPSME"} \
Expand All @@ -270,7 +274,7 @@ fi

mkdir -p $HTML_DIR
rm -f "$HTML_DIR"/*.html
"$PYTHON" "$SUBWAYS_REPO_PATH/tools/v2h/validation_to_html.py" \
python "$SUBWAYS_REPO_PATH/tools/v2h/validation_to_html.py" \
${CITIES_INFO_URL:+--cities-info-url "$CITIES_INFO_URL"} \
"$VALIDATION" "$HTML_DIR"

Expand Down
11 changes: 3 additions & 8 deletions subways/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ To perform tests manually, run this command from the top directory
of the repository:

```bash
python -m unittest discover tests
export PYTHONPATH=$(cwd)
source .venv/bin/activate
python -m unittest discover subways
```

or simply

```bash
python -m unittest
```

1 change: 1 addition & 0 deletions tools/make_poly/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shapely==2.0.1

0 comments on commit 7031e4d

Please sign in to comment.