Skip to content

Commit 9772328

Browse files
committed
Install Python packages in container
1 parent e3fb9b1 commit 9772328

File tree

8 files changed

+31
-32
lines changed

8 files changed

+31
-32
lines changed

.devcontainer/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,11 @@ RUN apt-get clean autoclean
4242
RUN apt-get autoremove -y
4343
RUN rm -rf /var/lib/{apt,dpkg,cache,log}/*
4444

45+
# Create Python virtual environment and install packages
46+
COPY requirements.txt /tmp/requirements.txt
47+
RUN /usr/bin/python3 -m venv /opt/venv && \
48+
/opt/venv/bin/pip install -r /tmp/requirements.txt && \
49+
rm /tmp/requirements.txt
50+
ENV PATH="/opt/venv/bin:$PATH"
51+
4552
WORKDIR /workspace

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ namespace :test do
119119
# "Run the cross-validation against LLVM"
120120
task :llvm do
121121
begin
122-
sh "#{$root}/.home/.venv/bin/python3 -m pytest ext/auto-inst/test_parsing.py -v"
122+
sh "/opt/venv/bin/python3 -m pytest ext/auto-inst/test_parsing.py -v"
123123
rescue => e
124124
raise unless e.message.include?("status (5)") # don't fail on skipped tests
125125
end

backends/generators/tasks.rake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ namespace :gen do
2828
inst_dir = cfg_arch.path / "inst"
2929
csr_dir = cfg_arch.path / "csr"
3030

31-
# Run the Go generator script using the same Python environment
31+
# Run the Go generator script
3232
# Note: The script uses --output not --output-dir
33-
sh "#{$root}/.home/.venv/bin/python3 #{$root}/backends/generators/Go/go_generator.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --output=#{output_dir}inst.go"
33+
sh "/opt/venv/bin/python3 #{$root}/backends/generators/Go/go_generator.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --output=#{output_dir}inst.go"
3434
end
3535

3636
desc <<~DESC
@@ -79,9 +79,9 @@ namespace :gen do
7979
resolved_codes_file.flush
8080

8181
begin
82-
# Run the C header generator script using the same Python environment
82+
# Run the C header generator script
8383
# The script generates encoding.h for inclusion in C programs
84-
sh "#{$root}/.home/.venv/bin/python3 #{$root}/backends/generators/c_header/generate_encoding.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --ext-dir=#{ext_dir} --resolved-codes=#{resolved_codes_file.path} --output=#{output_dir}encoding.out.h --include-all"
84+
sh "/opt/venv/bin/python3 #{$root}/backends/generators/c_header/generate_encoding.py --inst-dir=#{inst_dir} --csr-dir=#{csr_dir} --ext-dir=#{ext_dir} --resolved-codes=#{resolved_codes_file.path} --output=#{output_dir}encoding.out.h --include-all"
8585
ensure
8686
resolved_codes_file.close
8787
resolved_codes_file.unlink

bin/pip

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

6-
if [ ! -v VIRTUAL_ENV ]; then
7-
source ${ROOT}/.home/.venv/bin/activate
8-
fi
9-
106
$PIP "$@"

bin/setup

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,6 @@ if [ ! -f $ROOT/ext/rbi-central/README.md ]; then
197197
git submodule update --init ext/rbi-central
198198
fi
199199

200-
if [ ! -d $ROOT/.home/.venv ]; then
201-
${RUN} /usr/bin/python3 -m venv ${ROOT}/.home/.venv
202-
fi
203-
204-
source ${ROOT}/.home/.venv/bin/activate
205-
206-
if [ ! -f ${ROOT}/.home/.venv/bin/pre-commit ]; then
207-
${RUN} ${ROOT}/.home/.venv/bin/pip install -r requirements.txt
208-
fi
209-
210200
# if [ ! -f $ROOT/ext/riscv-opcodes/README.md ]; then
211201
# git submodule update --init ext/riscv-opcodes
212202
# fi
@@ -230,8 +220,8 @@ if [ "${CONTAINER_TYPE}" == "devcontainer" ]; then
230220
NPM="npm"
231221
NPX="npx"
232222
NODE="node"
233-
PYTHON="${ROOT}/.home/.venv/bin/python3"
234-
PIP="${ROOT}/.home/.venv/bin/pip"
223+
PYTHON="/opt/venv/bin/python3"
224+
PIP="/opt/venv/bin/pip"
235225
BASH="bash"
236226
GPP="g++"
237227
GDB="gdb"
@@ -245,8 +235,8 @@ elif [ "${CONTAINER_TYPE}" == "docker" -o "${CONTAINER_TYPE}" == "podman" ]; the
245235
NPM="${CONTAINER_BASE} npm"
246236
NPX="${CONTAINER_BASE} npx"
247237
NODE="${CONTAINER_BASE} node"
248-
PYTHON="${CONTAINER_BASE} ${ROOT}/.home/.venv/bin/python3"
249-
PIP="${CONTAINER_BASE} ${ROOT}/.home/.venv/bin/pip"
238+
PYTHON="${CONTAINER_BASE} /opt/venv/bin/python3"
239+
PIP="${CONTAINER_BASE} /opt/venv/bin/pip"
250240
BASH="${CONTAINER_BASE} bash"
251241
GPP="${CONTAINER_BASE} g++"
252242
GDB="${CONTAINER_BASE} gdb"
@@ -260,8 +250,8 @@ elif [ "${CONTAINER_TYPE}" == "singularity" ]; then
260250
NPM="singularity run ${HOME_OPT} ${CONTAINER_PATH} npm"
261251
NPX="singularity run ${HOME_OPT} ${CONTAINER_PATH} npx"
262252
NODE="singularity run ${HOME_OPT} ${CONTAINER_PATH} node"
263-
PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/python3"
264-
PIP="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/pip"
253+
PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} /opt/venv/bin/python3"
254+
PIP="singularity run ${HOME_OPT} ${CONTAINER_PATH} /opt/venv/bin/pip"
265255
BASH="singularity run ${HOME_OPT} ${CONTAINER_PATH} bash"
266256
GPP="singularity run ${HOME_OPT} ${CONTAINER_PATH} g++"
267257
GDB="singularity run ${HOME_OPT} ${CONTAINER_PATH} gdb"

container.def

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
Bootstrap: docker
22
From: ubuntu:24.04
33

4-
# %files
5-
6-
# Gemfile $HOME/
7-
# package.json $HOME/
4+
%files
5+
requirements.txt /tmp/requirements.txt
86

97
%post
108
export DEBIAN_FRONTEND=noninteractive
@@ -46,8 +44,16 @@ From: ubuntu:24.04
4644
apt-get autoremove -y
4745
rm -rf /var/lib/{apt, dpkg, cache, log}
4846

47+
# Create Python virtual environment and install packages
48+
/usr/bin/python3 -m venv /opt/venv
49+
/opt/venv/bin/pip install -r /tmp/requirements.txt
50+
rm /tmp/requirements.txt
51+
4952
# cd $HOME
5053
# bundle install
5154

5255
# npm i wavedrom-cli
5356
# npm i i -E @antora/[email protected] @antora/[email protected] @antora/lunr-extension asciidoctor-kroki
57+
58+
%environment
59+
export PATH="/opt/venv/bin:$PATH"

tools/ruby-gems/udb/lib/udb/resolver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def initialize(
148148
@gen_path = gen_path_override || (@repo_root / "gen")
149149
@std_path = std_path_override || (@repo_root / "spec" / "std" / "isa")
150150
@custom_path = custom_path_override || (@repo_root / "spec" / "custom" / "isa")
151-
@python_path = python_path_override || (@repo_root / ".home" / ".venv" / "bin" / "python3")
151+
@python_path = python_path_override || Pathname.new("/opt") / "venv" / "bin" / "python3"
152152

153153
# cache of config names
154154
@cfg_info = T.let({}, T::Hash[T.any(String, Pathname), ConfigInfo])

tools/ruby-gems/udb/test/test_yaml_loader.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def resolve_yaml(yaml)
2626

2727
stdout, stderr, status =
2828
Dir.chdir(Udb.repo_root) do
29-
Open3.capture3("/bin/bash -c \"source #{Udb.repo_root}/.home/.venv/bin/activate && #{Udb.repo_root}/.home/.venv/bin/python3 #{UDB_GEM_PATH}/python/yaml_resolver.py resolve --no-progress --no-checks #{arch_dir} #{resolved_dir}\"")
29+
Open3.capture3("/opt/venv/bin/python3 #{UDB_GEM_PATH}/python/yaml_resolver.py resolve --no-progress --no-checks #{arch_dir} #{resolved_dir}")
3030
end
3131
# puts stdout
3232
# puts stderr
@@ -53,7 +53,7 @@ def resolve_multi_yaml(*yamls)
5353
File.write(test_dir / "test#{i + 1}.yaml", yaml)
5454
end
5555

56-
system "/bin/bash -c \"source #{Udb.repo_root}/.home/.venv/bin/activate && #{Udb.repo_root}/.home/.venv/bin/python3 #{UDB_GEM_PATH}/python/yaml_resolver.py resolve --no-checks #{arch_dir} #{resolved_dir}\""
56+
system "/opt/venv/bin/python3 #{UDB_GEM_PATH}/python/yaml_resolver.py resolve --no-checks #{arch_dir} #{resolved_dir}"
5757

5858
if $CHILD_STATUS == 0
5959
YAML.load_file(resolved_dir / "test" / "test1.yaml")

0 commit comments

Comments
 (0)