The container is an Apptainer sandbox, which is a read-write container within a directory structure. The container is a writable directory, in which programs can be installed after building the container.
The container hosts the PYthoN General UnIt test geNerator (Pynguin), that is, the Pynguin source code and installation, and the Python environment to run Pynguin. The host system provides a directory, which is mounted to the container. This directory contains the Python modules under test and Pynguin writes the generated tests and test reports to it.
-
Clone this repository on a host system where the Apptainer should run and where Apptainer is installed. At least, copy the definition file
pynguin-dev-apptainer.defto the host system. -
Build the Apptainer
Configure
The Apptainer is defined by
pynguin-dev-apptainer.def, which has several parameters whose values can be changed if needed:PYTHON_VERSION=3.10: Pynguin currently requires Python 3.10.PYNGUIN_GIT_URL=https://github.com/se2p/pynguin.git: The URL to Pynguin's git repository. Change it if you work on a fork of Pynguin.PYNGUIN_DEV=/home/pynguin-dev: The directory in the Apptainer where Pynguin will be cloned and installed.PYNGUIN_DATA=/mnt/pynguin-data: The mounting point for a folder of the host system that stores the modules under test and that stores the test results and reports.VIRTUALENVS_HOME={{PYNGUIN_DEV}}/virtualenvs: The directory in the Apptainer where the Python virtual environment will be installed.
Additionally, when building the Apptainer, further tools can be installed such as
nano. Have a look at the definition file and add the tools to install viaapt-get.Build
In the host system's directory containing the definition file:
apptainer build --sandbox pynguin-dev-apptainer pynguin-dev-apptainer.defThis command takes a while and builds the container named
pynguin-dev-apptainer(a different name can be used). The container is the newly created folder with the same name.When building the container,
poetrywill be installed and Pynguin will be cloned and installed (see the definition file). -
Start the Apptainer
apptainer shell --writable --no-home --bind <data directory in the host system>/:/mnt/pynguin-data pynguin-dev-apptainerwhere:
shellopens a shell to the started container.--writablemakes the container writable/mutable.--no-homeensures that the home directory of the host system is not mounted to the container.--bindmounts the data directory in the host system to/mnt/pynguin-datain the container (see parameterPYNGUIN_DATA).<data directory in the host system>is the host system's folder, which contains the modules under test and to which Pynguin writes the test outputs (test cases) and test reports.pynguin-dev-apptaineris the container (directory name) to be started.
-
Run Pynguin in the Apptainer
Inside the apptainer, go to the
PYNGUIN_DEVfolder and run the following command:./virtualenvs/pynguin-OLitu6Ry-py3.10/bin/pynguin --project-path /mnt/pynguin-data/subjects/ --output-path /mnt/pynguin-data/results/output/ --report_dir=/mnt/pynguin-data/results/reports/ --module-name example -vwhere:
./virtualenvs/pynguin-OLitu6Ry-py3.10/bin/pynguinis the path to the Python virtual environment where Pynguin is installed. The folder/environmentpynguin-OLitu6Ry-py3.10will have a different name in your case.--project-pathnames the folder containing the project (one or more Python modules) to be tested.--output-pathnames the folder to which Pynguin writes the test results (test cases).--report_dirnames the folder to which Pynguin writes the test reports.--module-namenames the Python module (file) for which tests should be generated.-venables a more verbose output in the shell.
For this command, we copied before the module
example.pytomnt/pynguin-data/subjects/(see Pynguin Quickstart).
Assuming that the Pynguin Apptainer runs on a server and that an SSH connection can be established to the server, we can use VS Code's Remote Development using SSH to connect to the server and the Apptainer to work on the Pynguin code within the Apptainer and execute Pynguin on the server.
For this purpose, the VS Code client requires at least the "Remote-SSH" extension. The "Remote Development" extension pack comprises several extensions for remote development.
On the machine running VS Code, add the following to ~/.ssh/config:
Host pynguin-dev-apptainer~*
RemoteCommand apptainer shell --writable --no-home --bind <data directory in the host system>/:/mnt/pynguin-data <fully qualified path name to the folder containing the Apptainer>/pynguin-dev-apptainer/
RequestTTY yes
Host <server-name> pynguin-dev-apptainer~<server-name>
HostName <host-name of the server>
User <user-name>
Fill in the placeholders (<...>). The remote command is the same as before to start the Apptainer. The only difference is that the fully qualified name of the Apptainer is used. (Source: Remote container with Singularity -- Apptainer is the successor of Singularity)
In VS Code, open "a remote window" or "connect current window to host". Select the connection <server-name> pynguin-dev-apptainer~<server-name> (see ~/.ssh/config above) and authenticate.
VS Code is now connected to the running Apptainer on the server. For instance, you can open a terminal in VS Code that gives you a shell in the Apptainer. If the given shell points to the host system and not the Apptainer, then the RemoteCommand in the ~/.ssh/config has not been executed. In this case, go to the settings of the "Remote SSH" extension and enable the "Enable Remote Command" and "Use Local Server" options. Check that the JSON settings (settings.json) contain the following lines (Source: How do I execute a remote command upon connection with Remote-SSH in VSCode?):
"remote.SSH.enableRemoteCommand": true,
"remote.SSH.useLocalServer": true,
To program Pynguin directly inside the Apptainer:
- Open the folder
PYNGUIN_DEV/pynguin. The Pynguin source code located in the Apptainer is now editable from VS Code. - You might have to install the Python extensions.
- Select the Python Interpreter by entering the path to
pythonorpynguinin the virtual environment created in the Apptainer, e.g.,VIRTUALENVS_HOME/pynguin-OLitu6Ry-py3.10/bin/pynguin(in general, the folderpynguin-OLitu6Ry-py3.10will likely have a different name). Now all dependencies of Pynguin code are resolved in VS Code, and Python or Pynguin can be triggered from VS Code and directly executed in the Apptainer. - When opening a terminal in VS Code, the shell is directly connected to the Apptainer and Pynguin can be executed from this shell.