Managing dependencies
*********************

An experiment lists its Python packages in "requirements.txt" and
locks their exact versions in "constraints.txt". Local installs and
deployments both install from "constraints.txt".


Add a Python package
====================

Add the package to "requirements.txt", one per line, below the PsyNet
pin that "psynet setup" wrote:

   librosa==0.10.2
   praat-parselmouth

A package without a version gets the version chosen when
"constraints.txt" is next generated. Packages hosted in a Git
repository use this form:

   mypackage@git+https://github.com/example/mypackage.git@v1.2.3#egg=mypackage

For a private repository, include a deploy token as described in
Deploy tokens:

   mypackage@git+https://<username>:<deploy_token>@gitlab.com/example/mypackage.git@v1.2.3#egg=mypackage

Then update the lockfile and the virtual environment:

   psynet setup

"psynet setup" regenerates "constraints.txt" when it no longer matches
"requirements.txt", then synchronizes the virtual environment with it,
removing any package that "constraints.txt" doesn't list. Commit both
files.

To regenerate "constraints.txt" without installing anything, run
"psynet generate-constraints".


Choose a PsyNet version
=======================

PsyNet comes in three kinds of version:

Releases
   Numbered versions such as "14.0.0", published on PyPI and listed in
   the changelog. Use a release for any study you run with real
   participants. "uv pip install psynet" installs the latest one.

Release candidates
   Versions such as "14.0.0rc1", published on PyPI shortly before a
   release so that people can try it. They are installed only when
   named exactly: "uv pip install "psynet==14.0.0rc1"".

Development versions
   Commits on the "master" branch that are not released yet. They have
   the newest features and fixes, but they can change or break without
   notice, and a later release may still change the features they add.
   Install the current one with "uv pip install "psynet @
   git+https://gitlab.com/PsyNetDev/PsyNet@master"".

The version switcher at the top of these pages shows which version
they describe and lets you switch: a plain number is a release, a name
ending in "rc" and a number is a release candidate, and a name ending
in "alpha" is the development version. If you follow pages for a
version you haven't installed, some commands or options may not exist
yet.

Whichever version you install, "psynet setup" writes it to
"requirements.txt". A development version is recorded as the exact
commit, so the experiment doesn't change when "master" moves on.


Update PsyNet
=============

The PsyNet version is pinned in "requirements.txt". A released version
is pinned like this:

   psynet[experiment]==13.3.0

An unreleased commit, tag or branch, including a branch on a fork, is
pinned with a Git URL:

   psynet[experiment]@git+https://gitlab.com/PsyNetDev/PsyNet@<tag-branch-or-sha>#egg=psynet

The "[experiment]" extra installs the experiment runtime, including
Dallinger. A pin without it installs only the command-line tools, and
deploying refuses it. Older experiments often use the Git URL form
with a release tag such as "v10.1.0".

The changelog lists the changes in each version. Only major versions,
where the first number increases (for example from 10.3.1 to 11.0.0),
should require changes to the experiment. For PsyNet 14, follow
Upgrading to PsyNet 14.

After changing the pin, run "psynet setup", then "psynet debug local".
After a major upgrade, the error messages usually point to what needs
changing.


How constraints are generated
=============================

"constraints.txt" is generated with Dallinger's lock policy: packages
are resolved against the "dev-requirements.txt" that Dallinger tests
with, for the Dallinger version that the PsyNet pin implies. The file
starts with a header like this, which records the "requirements.txt"
it was generated from:

   # This file was autogenerated by uv via the following command:
   #    dallinger constraints generate
   #
   # Compiled from a requirements.txt file with md5sum c240530cbeca4ce1a8c350dd55f476ef and a .python-version file requesting Python 3.14

Bundled demos in the PsyNet repository don't have a "constraints.txt",
because they use the repository's development environment. A copied
demo gets one from "psynet setup".


Write constraints by hand
-------------------------

Generation can fail when Dallinger's pins leave no compatible version
of a package. In that case, edit "constraints.txt" by hand, for
example by removing the pin on the conflicting package, and delete the
header. Without the header, "psynet setup" and the checks during
debugging and deployment treat the file as hand-written and leave it
alone, so keep it in step with "requirements.txt" yourself.


Add system packages
===================

To install system packages into the experiment's Docker image, add a
Linux shell script called "prepare_docker_image.sh" to the experiment
directory. For example, to install "unzip":

   apt update
   apt install unzip

The script replaces PsyNet's default script,
"psynet/resources/scripts/prepare_docker_image.sh", which installs
build tools so that packages can be compiled from source. Start from a
copy of the default to keep them. The "demos/experiments/gibbs_video"
demo uses this script to install "ffmpeg".

Warning:

  Don't write files into the experiment directory from this script.
  "psynet debug local --docker" mounts the staged experiment directory
  over the container's, which hides those files. Put them elsewhere in
  the container.
