Skip to content

Commit

Permalink
Fixup Python deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
silverjam committed Apr 4, 2019
1 parent 89b47f4 commit dffdcc4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 63 deletions.
21 changes: 2 additions & 19 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ stdenv.mkDerivation rec {
zlib.dev
ghc
cabal-install
python27Full
python27Packages.setuptools
python27Packages.virtualenv
python27Packages.pip
python27Packages.cython
python37Full
python37Packages.setuptools
python27Packages.virtualenv
python37Packages.pip
python37Packages.cython
nodejs
coreutils
bash
Expand All @@ -34,14 +24,7 @@ stdenv.mkDerivation rec {
llvm
libcxxStdenv
];
shellHook = ''
[[ -z "$SOURCE_DATE_EPOCH" ]] || unset SOURCE_DATE_EPOCH
rm -rf .dist.py2
rm -rf .dist.py3
virtualenv .dist.py2
virtualenv .dist.py3 --python=`which python3`
.dist.py2/bin/pip install --ignore-installed twine wheel virtualenv
.dist.py3/bin/pip install --ignore-installed twine wheel virtualenv
source .dist.py3/bin/activate
shellHook = ''
[[ -z "$SOURCE_DATE_EPOCH" ]] || unset SOURCE_DATE_EPOCH
'';
}
10 changes: 1 addition & 9 deletions python/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
HAS_NIX := $(shell which nix-shell || echo y)

DEPLOY_PYTHON := $(CURDIR)/deploy.sh

.PHONY: deploy

ifneq ($(HAS_NIX),)
DEPLOY_COMMAND := nix-shell ../default.nix --pure --run "PYPI_USERNAME=$(PYPI_USERNAME) PYPI_PASSWORD=$(PYPI_PASSWORD) SBP_VERSION=$(SBP_VERSION) $(DEPLOY_PYTHON)"
else
DEPLOY_PYTHON := $(CURDIR)/deploy.bash
DEPLOY_COMMAND := SBP_VERSION=$(SBP_VERSION) $(SHELL) $(DEPLOY_PYTHON)
endif

deploy:
@[ -n "$(PYPI_USERNAME)" ] || { echo "\n!!! Please set PYPI_USERNAME in the environment !!!\n"; exit 1; }
@[ -n "$(PYPI_PASSWORD)" ] || { echo "\n!!! Please set PYPI_PASSWORD in the environment !!!\n"; exit 1; }
$(DEPLOY_COMMAND)
62 changes: 62 additions & 0 deletions python/deploy.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

set -euo pipefail
IFS=$'\n\t'

[[ -n "$PYPI_USERNAME" ]] || \
{ printf "\n!!! Please set PYPI_USERNAME in the environment !!!\n\n"; exit 1; }

[[ -n "$PYPI_PASSWORD" ]] || \
{ printf "\n!!! Please set PYPI_PASSWORD in the environment !!!\n\n"; exit 1; }

if ! command -v conda; then
echo '!!! Please install conda to deploy python !!!'
fi

conda_dir=$(mktemp -d)
conda create --yes -p "$conda_dir" python=3.5

# Activate conda
{
# Workaround bug in activate code...
export PS1=''

eval "$(conda shell.bash hook)"
# shellcheck disable=SC1091
source activate "$conda_dir"
}

conda install --yes \
cython virtualenv twine wheel

deploy_dir=$(mktemp -d)
trap 'rm -rf "$deploy_dir" "$conda_dir"' EXIT

echo "$deploy_dir"
cd "$deploy_dir"

echo ">>> Building staging area for deployment ..."

mkdir module

cp -r "$(dirname "$0")"/../.git .

cp -r "$(dirname "$0")"/.coveragerc module/.
cp -r "$(dirname "$0")"/.gitignore module/.

cp -r "$(dirname "$0")"/* module/.

echo ">>> Pruning ..."
rm -r -f module/docs/_build
rm -r -f module/build/*

echo ">>> Patching setup.py ..."
sed -i.backup 's@IS_RELEASED = False@IS_RELEASED = True@' module/setup.py

cd module

echo ">>> Building Python wheel ..."
python setup.py sdist bdist_wheel

echo ">>> Uploading Python wheel ..."
twine upload -u "$PYPI_USERNAME" -p "$PYPI_PASSWORD" "dist/sbp-$SBP_VERSION-*.whl"
35 changes: 0 additions & 35 deletions python/deploy.sh

This file was deleted.

0 comments on commit dffdcc4

Please sign in to comment.