Skip to content

Commit

Permalink
Merge pull request #400 from lincc-frameworks/ask-to-create-venv
Browse files Browse the repository at this point in the history
Check virtual environment is active
  • Loading branch information
hombit authored Feb 8, 2024
2 parents 69eafc3 + e9fb180 commit 369b30b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Choose where you would like to create your new project, and call copier with the
```sh
copier copy gh:lincc-frameworks/python-project-template <path/to/destination>
cd <path/to/destination>
# Create a virtual environment, feel free to use conda, pyenv or your favorite tool
python3 -mvenv ~/.virtualenvs/<env_name>
source ~/.virtualenvs/<env_name>/bin/activate
bash .prepare_project.sh
```

Expand Down
3 changes: 2 additions & 1 deletion copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,10 @@ include_benchmarks:
_message_after_copy: |
Your project "{{ project_name }}" has been created successfully!
Next, change directory to the project root and complete git configuration:
Next, change directory to the project root, create virtual environment, and complete git configuration:
$ cd {{ _copier_conf.dst_path }}
$ python3 -mvenv ~/.virtualenvs/{{ project_name }} && source ~/.virtualenvs/{{ project_name }}/bin/activate
$ bash .prepare_project.sh
###
Expand Down
21 changes: 18 additions & 3 deletions python-project-template/.prepare_project.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
#!/usr/bin/env bash

echo "Checking virtual environment"
if [ -z "${VIRTUAL_ENV}" ] && [ -z "${CONDA_PREFIX}" ]; then
echo 'No virtual environment detected: none of $VIRTUAL_ENV or $CONDA_PREFIX is set.'
echo
echo "=== This script is going to install the project in the system python environment ==="
echo "Proceed? [y/N]"
read -r RESPONCE
if [ "${RESPONCE}" != "y" ]; then
echo "See https://lincc-ppt.readthedocs.io/ for details."
echo "Exiting."
exit 1
fi

fi

echo "Checking pip version"
MINIMUM_PIP_VERSION=22
pipversion=( $(pip --version | awk '{print $2}' | sed 's/\./ /g') )
pipversion=( $(python -m pip --version | awk '{print $2}' | sed 's/\./ /g') )
if let "${pipversion[0]}<${MINIMUM_PIP_VERSION}"; then
echo "Insufficient version of pip found. Requires at least version ${MINIMUM_PIP_VERSION}."
echo "See https://lincc-ppt.readthedocs.io/ for details."
Expand All @@ -25,10 +40,10 @@ echo "Initializing local git repository"
} > /dev/null

echo "Installing package and runtime dependencies in local environment"
pip install -e . > /dev/null
python -m pip install -e . > /dev/null

echo "Installing developer dependencies in local environment"
pip install -e .'[dev]' > /dev/null
python -m pip install -e .'[dev]' > /dev/null

echo "Installing pre-commit"
pre-commit install > /dev/null
Expand Down

0 comments on commit 369b30b

Please sign in to comment.