Skip to content

Commit 11b54fe

Browse files
authored
Merge pull request #270 from riscv-software-src/python
Add python env executables, pre-commit, and pyyaml
2 parents c550227 + 7b534eb commit 11b54fe

File tree

12 files changed

+90
-44
lines changed

12 files changed

+90
-44
lines changed

.devcontainer/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
FROM ubuntu:24.04 AS spython-base
22
RUN export DEBIAN_FRONTEND=noninteractive
33
RUN apt-get update
4-
RUN apt-get install -y --no-install-recommends git
4+
RUN apt-get install -y --no-install-recommends git gh
5+
RUN apt-get install -y --no-install-recommends less
56
RUN apt-get install -y --no-install-recommends python3
67
RUN apt-get install -y --no-install-recommends python3.12-venv python3-pip
78
RUN apt-get install -y --no-install-recommends build-essential

bin/.container-tag

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2
1+
0.3

bin/bash

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
ROOT=$(dirname $(realpath $BASH_SOURCE[0]))
4+
source $ROOT/setup
5+
6+
$BASH "$@"

bin/node

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
ROOT=$(dirname $(realpath $BASH_SOURCE[0]))
44
source $ROOT/setup
55

6-
$NODE "$@"
6+
$NODE "$@"

bin/npx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
ROOT=$(dirname $(realpath $BASH_SOURCE[0]))
44
source $ROOT/setup
55

6-
$NPX "$@"
6+
$NPX "$@"

bin/pip

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
ROOT=$(dirname $(realpath $BASH_SOURCE[0]))
4+
source $ROOT/setup
5+
6+
if [ ! -v VIRTUAL_ENV ]; then
7+
source ${ROOT}/.home/.venv/bin/activate
8+
fi
9+
10+
$PIP "$@"

bin/pre-commit

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
ROOT=$(dirname $(dirname $(realpath $BASH_SOURCE[0])))
4+
5+
${ROOT}/bin/bash -c "source ${ROOT}/.home/.venv/bin/activate && pre-commit $@"
6+

bin/python

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
ROOT=$(dirname $(realpath $BASH_SOURCE[0]))
4+
source $ROOT/setup
5+
6+
$PYTHON "$@"

bin/ruby

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
ROOT=$(dirname $(realpath $BASH_SOURCE[0]))
44
source $ROOT/setup
55

6-
$RUBY "$@"
6+
$RUBY "$@"

bin/setup

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,70 +25,83 @@ if [ -f $ROOT/.git ]; then
2525
HOME_OPT="${HOME_OPT} --bind ${GIT_PATH}:${GIT_PATH}"
2626
fi
2727

28+
if [ -v DEVCONTAINER_ENV ]; then
29+
RUN=""
30+
else
31+
RUN="singularity run ${HOME_OPT} ${CONTAINER_PATH} "
32+
fi
33+
2834
if [ ! -d $ROOT/.home ]; then
2935
mkdir $ROOT/.home
3036
fi
3137

32-
if [ ! -f ${CONTAINER_PATH} ]; then
33-
echo "Fetching container..."
34-
if [ ! -d "${ROOT}/.singularity" ]; then
35-
mkdir -p ${ROOT}/.singularity
38+
if [ ! -v DEVCONTAINER_ENV ]; then
39+
if [ ! -f ${CONTAINER_PATH} ]; then
40+
echo "Fetching container..."
41+
if [ ! -d "${ROOT}/.singularity" ]; then
42+
mkdir -p ${ROOT}/.singularity
43+
fi
44+
singularity pull ${SINGULARITY_CACHE} ${CONTAINER_PATH} oras://docker.io/riscvintl/spec-generator:$CONTAINER_TAG
3645
fi
37-
singularity pull ${SINGULARITY_CACHE} ${CONTAINER_PATH} oras://docker.io/riscvintl/spec-generator:$CONTAINER_TAG
3846
fi
3947

4048
if [ ! -f $ROOT/.bundle/config ]; then
4149
OLDDIR=$PWD
4250
cd $ROOT
43-
singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle config set --local path ${ROOT}/.home/.gems
44-
singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle config set --local cache_path ${ROOT}/.home/.cache
51+
${RUN} bundle config set --local path ${ROOT}/.home/.gems
52+
${RUN} bundle config set --local cache_path ${ROOT}/.home/.cache
4553
cd $OLDDIR
4654
fi
4755

4856
if [ ! -d $ROOT/.home/.gems ]; then
4957
OLDDIR=$PWD
5058
cd $ROOT
51-
singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle install
59+
${RUN} bundle install
5260
cd $OLDDIR
5361
fi
5462

55-
if [ ! -f $ROOT/ext/riscv-opcodes/README.md ]; then
56-
git submodule update --init ext/riscv-opcodes
63+
if [ ! -d $ROOT/.home/.venv ]; then
64+
${RUN} /usr/bin/python3 -m venv ${ROOT}/.home/.venv
65+
fi
66+
source ${ROOT}/.home/.venv/bin/activate
67+
if [ ! -f ${ROOT}/.home/.venv/bin/pre-commit ]; then
68+
${RUN} ${ROOT}/.home/.venv/bin/pip install -r requirements.txt
5769
fi
5870

71+
# if [ ! -f $ROOT/ext/riscv-opcodes/README.md ]; then
72+
# git submodule update --init ext/riscv-opcodes
73+
# fi
74+
5975
if [[ ! -z "$DEVELOPMENT" && $DEVELOPMENT -eq 1 ]]; then
6076
if [ ! -d "${ROOT}/.home/.yard/gem_index"]; then
61-
singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri
62-
singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec --gemfile ${ROOT}/Gemfile yard gems
77+
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri
78+
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard gems
6379
touch ${ROOT}/.stamps/dev_gems
6480
fi
6581
fi
6682

67-
if [[ ! -z "$VSCODE" && $VSCODE -eq 1 ]]; then
68-
declare -a exts=(
69-
castwide.solargraph,
70-
redhat.vscode-yaml,
71-
onnovalkering.vscode-singularity,
72-
asciidoctor.asciidoctor-vscode
73-
)
74-
for ext in "${exts[@]}"; do
75-
ignore=`code --list-extensions | grep "${ext}"`
76-
if [ $? -eq 1 ]; then
77-
echo "Installing VS Code extension ${ext}"
78-
code --install-extension ${ext}
79-
else
80-
echo "Extension ${ext} already installed"
81-
fi
82-
done
83-
fi
84-
8583
if [ ! -d ${ROOT}/node_modules ]; then
86-
singularity run ${HOME_OPT} ${CONTAINER_PATH} npm i
84+
${RUN} npm i
8785
fi
8886

89-
BUNDLE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle"
90-
RUBY="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec ruby"
91-
RAKE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec rake"
92-
NPM="singularity run ${HOME_OPT} ${CONTAINER_PATH} npm"
93-
NPX="singularity run ${HOME_OPT} ${CONTAINER_PATH} npx"
94-
NODE="singularity run ${HOME_OPT} ${CONTAINER_PATH} node"
87+
if [ -v DEVCONTAINER_ENV ]; then
88+
BUNDLE="bundle"
89+
RUBY="bundle exec ruby"
90+
RAKE="bundle exec rake"
91+
NPM="npm"
92+
NPX="npx"
93+
NODE="node"
94+
PYTHON="python3"
95+
PIP="${ROOT}/.home/.venv/bin/pip"
96+
BASH="bash"
97+
else
98+
BUNDLE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle"
99+
RUBY="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec ruby"
100+
RAKE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec rake"
101+
NPM="singularity run ${HOME_OPT} ${CONTAINER_PATH} npm"
102+
NPX="singularity run ${HOME_OPT} ${CONTAINER_PATH} npx"
103+
NODE="singularity run ${HOME_OPT} ${CONTAINER_PATH} node"
104+
PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} python3"
105+
PIP="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/pip"
106+
BASH="singularity run ${HOME_OPT} ${CONTAINER_PATH} bash"
107+
fi

0 commit comments

Comments
 (0)