Skip to content

Commit

Permalink
Use chpl-venv for c2chapel python dependencies
Browse files Browse the repository at this point in the history
The dependency is pycparser. We still download the tarball
for it for the fake headers since those are not included
in the pip package.

---
Signed-off-by: Michael Ferguson <mppf@users.noreply.github.com>
  • Loading branch information
mppf committed Oct 22, 2020
1 parent 41cc7d7 commit 6948e22
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 29 deletions.
7 changes: 6 additions & 1 deletion Makefile
Expand Up @@ -130,6 +130,11 @@ third-party-chpldoc-venv: FORCE
cd third-party && $(MAKE) chpldoc-venv; \
fi

third-party-c2chapel-venv: FORCE
@if [ -z "$$CHPL_DONT_BUILD_C2CHAPEL_VENV" ]; then \
cd third-party && $(MAKE) c2chapel-venv; \
fi

test-venv: third-party-test-venv

chpldoc: compiler third-party-chpldoc-venv
Expand All @@ -156,7 +161,7 @@ mason: chpldoc notcompiler FORCE
protoc-gen-chpl: chpldoc notcompiler FORCE
cd tools/protoc-gen-chpl && $(MAKE) && $(MAKE) install

c2chapel: FORCE
c2chapel: third-party-c2chapel-venv FORCE
cd tools/c2chapel && $(MAKE)
cd tools/c2chapel && $(MAKE) install

Expand Down
4 changes: 4 additions & 0 deletions third-party/Makefile
Expand Up @@ -90,6 +90,10 @@ chpldoc-venv: $(CHPL_VENV_SPHINX_BUILD)
$(CHPL_VENV_SPHINX_BUILD): $(CHPL_VENV_CHPLDOC_REQUIREMENTS_FILE)
cd chpl-venv && $(MAKE) chpldoc-venv

c2chapel-venv: $(CHPL_VENV_C2CHAPEL_REQS)
$(CHPL_VENV_C2CHAPEL_REQS): $(CHPL_VENV_C2CHAPEL_REQUIREMENTS_FILE)
cd chpl-venv && $(MAKE) c2chapel-venv

# See gasnet/Makefile for explanation of the post-install step
gasnet: $(GASNET_INSTALL_DIR)
$(GASNET_INSTALL_DIR): $(GASNET_DEPEND)
Expand Down
11 changes: 11 additions & 0 deletions third-party/chpl-venv/Makefile
Expand Up @@ -89,6 +89,15 @@ $(CHPL_VENV_SPHINX_BUILD): $(CHPL_VENV_VIRTUALENV_DIR)
-U --force-reinstall $(CHPL_PIP_INSTALL_PARAMS) $(LOCAL_PIP_FLAGS) -r chpldoc-requirements.txt && \
$(PYTHON) $(CHPL_VENV_VIRTUALENV) --relocatable $(CHPL_VENV_VIRTUALENV_DIR)

$(CHPL_VENV_C2CHAPEL_REQS): $(CHPL_VENV_VIRTUALENV_DIR)
export PYTHONPATH="$(PIPLIBS):$$PYTHONPATH" && \
export PATH="$(CHPL_VENV_VIRTUALENV_BIN):$$PATH" && \
export VIRTUAL_ENV=$(CHPL_VENV_VIRTUALENV_DIR) && \
$(PYTHON) $(CHPL_VENV_VIRTUALENV_BIN)/pip install \
-U --force-reinstall $(CHPL_PIP_INSTALL_PARAMS) $(LOCAL_PIP_FLAGS) -r c2chapel-requirements.txt && \
$(PYTHON) $(CHPL_VENV_VIRTUALENV) --relocatable $(CHPL_VENV_VIRTUALENV_DIR) && \
touch $(CHPL_VENV_C2CHAPEL_REQS)

$(CHPL_VENV_CHPLSPELL_REQS): $(CHPL_VENV_VIRTUALENV_DIR)
export PYTHONPATH="$(PIPLIBS):$$PYTHONPATH" && \
export PATH="$(CHPL_VENV_VIRTUALENV_BIN):$$PATH" && \
Expand All @@ -102,6 +111,8 @@ test-venv: $(CHPL_VENV_TEST_REQS)

chpldoc-venv: $(CHPL_VENV_SPHINX_BUILD)

c2chapel-venv: $(CHPL_VENV_C2CHAPEL_REQS)

chplspell-venv: $(CHPL_VENV_CHPLSPELL_REQS)

# Phony convenience target for install python packages.
Expand Down
2 changes: 2 additions & 0 deletions third-party/chpl-venv/Makefile.include
Expand Up @@ -7,6 +7,7 @@ CHPL_VENV_DIR=$(shell cd $(THIRD_PARTY_DIR)/chpl-venv && pwd)

CHPL_VENV_TEST_REQUIREMENTS_FILE=$(CHPL_VENV_DIR)/test-requirements.txt
CHPL_VENV_CHPLDOC_REQUIREMENTS_FILE=$(CHPL_VENV_DIR)/chpldoc-requirements.txt
CHPL_VENV_C2CHAPEL_REQUIREMENTS_FILE=$(CHPL_VENV_DIR)/c2chapel-requirements.txt
CHPL_VENV_CHPLSPELL_REQUIREMENTS_FILE=$(CHPL_VENV_DIR)/chplspell-requirements.txt

# Do not include this file from $(CHPL_MAKE_HOME)/make/Makefile.base.
Expand All @@ -31,6 +32,7 @@ CHPL_VENV_VIRTUALENV_DIR=$(CHPL_VENV_DIR)/$(CHPL_VENV_VIRTUALENV_SUBDIR)
CHPL_VENV_VIRTUALENV_BIN=$(CHPL_VENV_VIRTUALENV_DIR)/bin
CHPL_VENV_SPHINX_BUILD=$(CHPL_VENV_VIRTUALENV_BIN)/sphinx-build
CHPL_VENV_TEST_REQS=$(CHPL_VENV_VIRTUALENV_DIR)/chpl-test-reqs
CHPL_VENV_C2CHAPEL_REQS=$(CHPL_VENV_VIRTUALENV_DIR)/c2chapel-reqs
CHPL_VENV_CHPLSPELL_REQS=$(CHPL_VENV_VIRTUALENV_DIR)/chpl-chplspell-reqs


Expand Down
13 changes: 13 additions & 0 deletions third-party/chpl-venv/README.md
Expand Up @@ -28,6 +28,9 @@ section.
The primary packages required by `start_test` are: `argparse`, `PyYAML`, and
`virtualenv` (for installation).

The primary packages required by `c2chapel` are: `argparse`, `pycparser`, and
`virtualenv` (for installation).

### Sphinx

Python documentation generator
Expand Down Expand Up @@ -133,3 +136,13 @@ Required by Sphinx, and man page generation.
**License**: public domain, Python, 2-Clause BSD, GPL 3 (see COPYING.txt, also found at http://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/COPYING.txt)

**Website**: https://pypi.python.org/pypi/docutils

### pycparser

C parser in Python

Required by c2chapel.

**License**: BSD

**Website**: https://pypi.org/project/pycparser/
3 changes: 3 additions & 0 deletions third-party/chpl-venv/c2chapel-requirements.txt
@@ -0,0 +1,3 @@
argparse==1.3.0
# tools/c2chapel/Makefile should match so fakeHeaders download matches
pycparser==2.17
42 changes: 16 additions & 26 deletions tools/c2chapel/Makefile
Expand Up @@ -33,6 +33,8 @@ include $(CHPL_MAKE_HOME)/third-party/chpl-venv/Makefile.include
bdir=$(CHPL_BIN_DIR)
link=$(bdir)/c2chapel

# Note, this version is used only for the fake headers,
# but it should probably match third-party/chpl-venv/c2chapel-requirements.txt
VERSION=2.17
TAR=release_v$(VERSION).tar.gz

Expand All @@ -48,39 +50,24 @@ FAKES=$(INSTALL)/fakeHeaders
VIRTUAL_ENV=$(shell which virtualenv)
THIRD_PARTY_VENV=$(CHPL_VENV_DIR)/$(CHPL_VENV_VIRTUALENV)

.PHONY: clean clobber c2chapel install venv

all: c2chapel

venv:
ifneq ($(wildcard $(VIRTUAL_ENV)),)
$(info Using system virtualenv)
else ifneq ($(wildcard $(THIRD_PARTY_VENV)),)
$(eval VIRTUAL_ENV=PYTHONPATH=$(PIPLIBS) && $(THIRD_PARTY_VENV))
# Add warning suppression flags
$(eval VENV_PIP_FLAGS=--no-warn-conflicts --no-warn-script-location)
$(info Using chpl-venv virtualenv ($(VIRTUAL_ENV)))
else
$(error Unable to find virtualenv. Either install virtualenv yourself \
or 'make test-venv' from $$CHPL_HOME)
endif
.PHONY: clean clobber c2chapel c2chapel-venv install venv

all: c2chapel install

c2chapel-venv:
cd ../../third-party && $(MAKE) c2chapel-venv

c2chapel: c2chapel-venv $(FAKES)

c2chapel: venv
mkdir -p $(VENV_DIR)
$(FAKES):
mkdir -p $(FAKES)
cd $(INSTALL) && \
echo "Fetching release $(VERSION) tarball..." && \
echo "Fetching pycparser release $(VERSION) tarball for fake headers..." && \
wget $(RELEASE) -O $(TAR) && \
tar xzf $(TAR) -C $(FAKES) --strip 3 pycparser-release_v$(VERSION)/utils/fake_libc_include

./utils/fixFakes.sh $(FAKES) $(PWD)/utils/custom.h

$(VIRTUAL_ENV) $(VENV_DIR)

. $(VENV_DIR)/bin/activate && \
python $(VENV_DIR)/bin/pip install $(VENV_PIP_FLAGS) $(INSTALL)/$(TAR) && \
python $(VENV_DIR)/bin/pip install $(VENV_PIP_FLAGS) $(CHPL_PIP_INSTALL_PARAMS) argparse

check:
cd test && ./tester.sh

Expand All @@ -96,7 +83,8 @@ cleanall: clean

clobber: clean

install:

$(link):
@echo "Installing c2chapel..."
ifneq ($(wildcard $(link)),)
@echo "Removing old symbolic link..."
Expand All @@ -106,3 +94,5 @@ endif
@echo "Installing symbolic link..."
mkdir -p $(bdir)
ln -s $(shell pwd)/c2chapel $(link)

install: c2chapel $(link)
16 changes: 14 additions & 2 deletions tools/c2chapel/c2chapel
Expand Up @@ -20,8 +20,20 @@
# limitations under the License.
#

PREFIX=$CHPL_HOME/tools/c2chapel
if [ -z "$CHPL_HOME" ]; then
echo "Error: CHPL_HOME is not set"
exit 1
fi

python=$($CHPL_HOME/util/config/find-python.sh)
venv_path=$("$python" "$CHPL_HOME/util/chplenv/chpl_home_utils.py" --venv)

. ${PREFIX}/install/venv/bin/activate
if [ ! -d "$venv_path" ]; then
echo "Error: virtualenv '$venv_path' does not exist"
exit 1
fi

. ${venv_path}/bin/activate

PREFIX=$CHPL_HOME/tools/c2chapel
exec ${PREFIX}/c2chapel.py "${@}"

0 comments on commit 6948e22

Please sign in to comment.