Skip to content

Commit 6ab3e95

Browse files
committed
feat: add activation, installation, and cleanup scripts for virtual environment management
1 parent 7a3d326 commit 6ab3e95

File tree

13 files changed

+226
-32
lines changed

13 files changed

+226
-32
lines changed

activate

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# Copyright (c) 2020-202x The virtualenv developers
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining
4+
# a copy of this software and associated documentation files (the
5+
# "Software"), to deal in the Software without restriction, including
6+
# without limitation the rights to use, copy, modify, merge, publish,
7+
# distribute, sublicense, and/or sell copies of the Software, and to
8+
# permit persons to whom the Software is furnished to do so, subject to
9+
# the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be
12+
# included in all copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
# This file must be used with "source bin/activate" *from bash*
23+
# you cannot run it directly
24+
25+
# Get script path (only used if environment is relocatable).
26+
if [ -n "${BASH_VERSION:+x}" ] ; then
27+
SCRIPT_PATH="${BASH_SOURCE[0]}"
28+
if [ "$SCRIPT_PATH" = "$0" ]; then
29+
# Only bash has a reasonably robust check for source'dness.
30+
echo "You must source this script: \$ source $0" >&2
31+
exit 33
32+
fi
33+
elif [ -n "${ZSH_VERSION:+x}" ] ; then
34+
SCRIPT_PATH="${(%):-%x}"
35+
elif [ -n "${KSH_VERSION:+x}" ] ; then
36+
SCRIPT_PATH="${.sh.file}"
37+
fi
38+
39+
deactivate () {
40+
unset -f pydoc >/dev/null 2>&1 || true
41+
42+
# reset old environment variables
43+
# ! [ -z ${VAR+_} ] returns true if VAR is declared at all
44+
if ! [ -z "${_OLD_VIRTUAL_PATH:+_}" ] ; then
45+
PATH="$_OLD_VIRTUAL_PATH"
46+
export PATH
47+
unset _OLD_VIRTUAL_PATH
48+
fi
49+
if ! [ -z "${_OLD_VIRTUAL_PYTHONHOME+_}" ] ; then
50+
PYTHONHOME="$_OLD_VIRTUAL_PYTHONHOME"
51+
export PYTHONHOME
52+
unset _OLD_VIRTUAL_PYTHONHOME
53+
fi
54+
55+
# The hash command must be called to get it to forget past
56+
# commands. Without forgetting past commands the $PATH changes
57+
# we made may not be respected
58+
hash -r 2>/dev/null
59+
60+
if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then
61+
PS1="$_OLD_VIRTUAL_PS1"
62+
export PS1
63+
unset _OLD_VIRTUAL_PS1
64+
fi
65+
66+
unset VIRTUAL_ENV
67+
unset VIRTUAL_ENV_PROMPT
68+
if [ ! "${1-}" = "nondestructive" ] ; then
69+
# Self destruct!
70+
unset -f deactivate
71+
fi
72+
}
73+
74+
# unset irrelevant variables
75+
deactivate nondestructive
76+
77+
VIRTUAL_ENV='C:\Users\niteris\dev\static-ffmpeg\.venv'
78+
if ([ "$OSTYPE" = "cygwin" ] || [ "$OSTYPE" = "msys" ]) && $(command -v cygpath &> /dev/null) ; then
79+
VIRTUAL_ENV=$(cygpath -u "$VIRTUAL_ENV")
80+
fi
81+
export VIRTUAL_ENV
82+
83+
_OLD_VIRTUAL_PATH="$PATH"
84+
PATH="$VIRTUAL_ENV/Scripts:$PATH"
85+
export PATH
86+
87+
if [ "xstatic-ffmpeg" != x ] ; then
88+
VIRTUAL_ENV_PROMPT="(static-ffmpeg) "
89+
else
90+
VIRTUAL_ENV_PROMPT="($(basename "$VIRTUAL_ENV")) "
91+
fi
92+
export VIRTUAL_ENV_PROMPT
93+
94+
# unset PYTHONHOME if set
95+
if ! [ -z "${PYTHONHOME+_}" ] ; then
96+
_OLD_VIRTUAL_PYTHONHOME="$PYTHONHOME"
97+
unset PYTHONHOME
98+
fi
99+
100+
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
101+
_OLD_VIRTUAL_PS1="${PS1-}"
102+
PS1="${VIRTUAL_ENV_PROMPT}${PS1-}"
103+
export PS1
104+
fi
105+
106+
# Make sure to unalias pydoc if it's already there
107+
alias pydoc 2>/dev/null >/dev/null && unalias pydoc || true
108+
109+
pydoc () {
110+
python -m pydoc "$@"
111+
}
112+
113+
# The hash command must be called to get it to forget past
114+
# commands. Without forgetting past commands the $PATH changes
115+
# we made may not be respected
116+
hash -r 2>/dev/null

clean

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
set -x
3+
rm -rf .tox
4+
rm -rf build
5+
rm -rf dist
6+
rm -rf venv
7+
rm -rf .venv
8+
rm -rf .env_*
9+
# remove all *.pyc files
10+
find . -name "*.pyc" -exec rm -rf {} \;
11+
# remove all *.egg files
12+
find . -name "*.egg" -exec rm -rf {} \;
13+
rm -rf build
14+
rm -rf dist
15+
rm -rf *.egg-info
16+
rm -rf .eggs
17+
rm -rf .tox
18+
rm -rf .cache
19+
rm -rf .pytest_cache
20+
rm -rf .mypy_cache
21+
rm -rf .coverage
22+
rm -rf .iso_env

downloaded_files/dashboard.lock

Whitespace-only changes.

install

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e
3+
uv venv --python 3.11
4+
uv pip install -r requirements.testing.txt
5+
uv pip install .
6+
# This is needed to force the installation to finalize.
7+
uv run python -c "import os; _ = os.getcwd()"
8+
set +e
9+
10+
# if ./activate exists, remove it
11+
if [ -f activate ]; then
12+
rm activate
13+
fi
14+
# symlink activate to .venv/bin/activate on linux/mac and .venv/Scripts/activate on windows
15+
if [[ "$OSTYPE" == "linux-gnu"* || "$OSTYPE" == "darwin"* ]]; then
16+
ln -s .venv/bin/activate activate
17+
else
18+
ln -s .venv/Scripts/activate activate
19+
fi

lint

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo Running ruff static_ffmpeg
5+
uv run ruff check --fix static_ffmpeg
6+
echo Running ruff tests
7+
uv run ruff check --fix tests
8+
echo Running black static_ffmpeg tests
9+
uv run black static_ffmpeg tests
10+
echo Running isort static_ffmpeg tests
11+
uv run isort --profile black static_ffmpeg tests
12+
echo Running flake8 static_ffmpeg tests
13+
uv run flake8 static_ffmpeg tests
14+
echo Running mypy static_ffmpeg
15+
uv run mypy static_ffmpeg tests
16+
echo Linting complete!
17+
exit 0

requirements.testing.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
flake8
22
mypy
33
pylint
4-
pytest
4+
pytest
5+
ruff

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
requests
22
filelock
3+
progress

static_ffmpeg/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
"""
44

55
from ._add_paths import add_paths
6+
7+
__all__ = ["add_paths"]

static_ffmpeg/run.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import requests # type: ignore
1414
from filelock import FileLock, Timeout
15+
from progress.spinner import Spinner # type: ignore
1516

1617
TIMEOUT = 10 * 60 # Wait upto 10 minutes to validate install
1718
# otherwise break the lock and install anyway.
@@ -52,12 +53,14 @@ def download_file(url, local_path):
5253
with requests.get(url, stream=True, timeout=TIMEOUT) as req:
5354
req.raise_for_status()
5455
with open(local_path, "wb") as file_d:
55-
for chunk in req.iter_content(chunk_size=8192 * 16):
56-
# If you have chunk encoded response uncomment if
57-
# and set chunk_size parameter to None.
58-
# if chunk:
59-
sys.stdout.write(".")
60-
file_d.write(chunk)
56+
with Spinner() as spinner:
57+
for chunk in req.iter_content(chunk_size=8192 * 16):
58+
# If you have chunk encoded response uncomment if
59+
# and set chunk_size parameter to None.
60+
# if chunk:
61+
sys.stdout.write(".")
62+
file_d.write(chunk)
63+
spinner.next()
6164
sys.stdout.write(f"\nDownload of {url} -> {local_path} completed.\n")
6265
return local_path
6366

test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
echo "Running unittests"
4+
uv run pytest tests -v

0 commit comments

Comments
 (0)