Skip to content

Commit

Permalink
using nix to create the venv and make hermetic dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Nov 20, 2023
1 parent 72a4def commit cc25d86
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 20 deletions.
35 changes: 15 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean venv docs clean-assets assets test setup run build deploy
.PHONY: clean docs clean-assets assets test setup run build deploy
asset-apps := _dashboard _default _scaffold _minimal _documentation showcase
asset-zips := $(asset-apps:%=py4web/assets/py4web.app.%.zip)
clean:
Expand All @@ -14,30 +14,25 @@ py4web/assets/py4web.app.%.zip: apps/%
cd $< && find . | \
egrep "\.(py|html|css|js|png|jpg|gif|json|yaml|md|txt|mm|ico)$$" | \
zip -@ $(addprefix ../../, $@)
venv:
python -m venv venv
venv/bin/pip install -U pip
venv/bin/pip install -U -r requirements.txt
venv/bin/pip install ./
docs: venv
venv/bin/pip install -U -r docs/requirements.txt
cd docs; . ../venv/bin/activate && ./updateDocs.sh html
test: venv
venv/bin/pip install -U -r test-requirements.txt
venv/bin/python -m pytest --cov=py4web --cov-report html:cov.html -v tests/
docs:
.venv/bin/pip install -U -r docs/requirements.txt
cd docs; ./updateDocs.sh html
test:
.venv/bin/pip install -U -r test-requirements.txt
.venv/bin/python -m pytest --cov=py4web --cov-report html:cov.html -v tests/
setup:
venv/bin/python py4web.py setup apps
venv/bin/python py4web.py set_password
.venv/bin/python py4web.py setup apps
.venv/bin/python py4web.py set_password
run:
venv/bin/python py4web.py run -p password.txt apps
.venv/bin/python py4web.py run -p password.txt apps
upgrade-utils:
find apps -name "utils.js" -exec cp apps/_dashboard/static/js/utils.js {} \;
upgrade-vue:
curl -L https://unpkg.com/vue/dist/vue.min.js > apps/_dashboard/static/js/vue.min.js
find apps -name "vue.min.js" -exec cp apps/_dashboard/static/js/vue.min.js {} \;
build: clean assets venv
venv/bin/pip install --upgrade build
venv/bin/pip install --upgrade twine
venv/bin/python -m build
build: clean assets
.venv/bin/pip install --upgrade build
.venv/bin/pip install --upgrade twine
.venv/bin/python -m build
deploy: build
venv/bin/python -m twine upload dist/*
.venv/bin/python -m twine upload dist/*
56 changes: 56 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
let
nixpkgs-src = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/tarball/nixos-22.11";
};

pkgs = import nixpkgs-src {
config = {
allowUnfree = true;
};
};

# This is the Python version that will be used.
myPython = pkgs.python310;

pythonWithPkgs = myPython.withPackages (pythonPkgs: with pythonPkgs; [
pip
setuptools
wheel
]);

lib-path = with pkgs; lib.makeLibraryPath [
libffi
openssl
];

shell = pkgs.mkShell {
buildInputs = [
# my python and packages
pythonWithPkgs
pkgs.memcached

# other packages needed for compiling python libs
pkgs.readline
pkgs.libffi
pkgs.openssl
];

shellHook = ''
# Allow the use of wheels.
SOURCE_DATE_EPOCH=$(date +%s)
# Augment the dynamic linker path
export "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${lib-path}"
# Setup the virtual environment if it doesn't already exist.
if test ! -d .venv; then
python -m venv .venv
fi
.venv/bin/pip install -U -r requirements.txt
source .venv/bin/activate
export PYTHONPATH=`pwd`.venv/${myPython.sitePackages}/:$PYTHONPATH
'';
};
in

shell

0 comments on commit cc25d86

Please sign in to comment.