Choose the Package the Ticket Tool Needs

PythonBeginner
Practice Now

Introduction

BenchTicket turns event orders into a window-ready price list. Its package installation currently searches two sources, and a look-alike package changes the prices even though installation succeeds.

You will compare normal business output, identify the installed dependencies, and save an installation recipe that rebuilds the approved tool. All package sources and names are synthetic and stay inside this lab. You need basic terminal and text-file skills; no Python programming is required.

Read the Ticket Desk's Working Example

In this step, you will understand the price list before changing its dependencies. Start in Terminal. cd changes directory; the absolute path works from any current location:

cd /home/labex/project/ticket-build

orders.csv is a small comma-separated table: each order has an ID, adult and child quantities, and a membership value. cat prints it:

cat orders.csv

Adults cost 1200 cents and children 600. Orders with at least two adults and two children receive 400 cents off; members receive another 200, with a zero minimum. A cent is one hundredth of the currency unit.

The prepared demo runs a separate, approved example installation; it does not complete your project environment:

/opt/labex-lookalike/demo

For T101, expect 3200,32.00; for T103, 1600,16.00; T104 remains zero. These relationships matter more than a package's version label. Keep the original orders and application unchanged.

Observe a Successful Install with Incorrect Prices

In this step, you will see the difference between installation success and business correctness. Stay in Terminal, in ticket-build.

A virtual environment holds project-specific Python packages. python3 is the interpreter and -m runs a module. The venv module creates an environment; --without-pip leaves out a second pip copy because the prepared pip can manage another environment with --python:

python3 -m venv --without-pip .venv

Read the prepared recipe:

cat install.sh

bash runs this script. "$1" is its first argument: the environment path. Quotes keep that path together. set -e stops the script if installation fails. --isolated ignores user pip settings and environment variables; --no-cache-dir avoids cached downloads. --index-url and --extra-index-url name two package indexes, and -r reads requirements.

bash install.sh .venv

Now run the original consumer with that environment's interpreter:

.venv/bin/python quote.py orders.csv

T101 incorrectly costs 3600,36.00 and T103 costs 1800,18.00. The controlled substitute only changes calculation behavior; it does not steal data. Installation exiting successfully did not establish correct prices.

Identify What the Resolver Selected

In this step, you will connect the incorrect behavior to actual installed packages. A package index lists available distributions; a wheel is an installable Python package archive.

python3 -m pip runs pip as a module. Its show command reads installed metadata from the environment selected by --python:

python3 -m pip --isolated --python .venv show benchticket-prices benchticket-labels

Expect prices version 9.0.0, which requires benchticket-labels, and labels version 1.0.0. Labels is an indirect dependency: installing prices caused pip to install it too. Hyphens in distribution names correspond to underscores in these import names.

Read the independently supplied approval catalogue:

cat /opt/labex-lookalike/approval/packages.tsv

The approved versions are prices 1.4.0 and labels 1.0.0. The SHA-256 column will be used in the next lab.

Pip searches both configured indexes; --extra-index-url is not a lower-priority backup. Here the higher matching version wins. The local public path is a synthetic second source, not the real PyPI. Next, limit this recipe to the reviewed package set.

Save and Apply the Approved Recipe

In this step, you will save the approved versions and use the approved index. == means an exact version requirement.

The following here-document writes a whole file. > replaces that named file; <<'EOF' takes the following lines literally until a line containing only EOF. Use it only for the two editable recipe files:

cat > requirements.txt <<'EOF'
benchticket-prices==1.4.0
benchticket-labels==1.0.0
EOF

Replace the recipe, keeping the environment argument and stopping on failure. The approved index contains both required packages:

cat > install.sh <<'EOF'
#!/bin/bash
set -e
python3 -m pip --isolated --python "$1" install --no-cache-dir --index-url http://127.0.0.1:8123/approved/simple -r requirements.txt
EOF
bash install.sh .venv

Pip replaces prices 9.0.0 with 1.4.0. Read the installed versions again:

python3 -m pip --isolated --python .venv show benchticket-prices benchticket-labels

Both should match the catalogue. If a path was mistyped, return with cd /home/labex/project/ticket-build, inspect the two files with cat, and repeat this installation; no VM reset is needed.

Hand Over Every Correct Order

In this step, you will produce the real window price list. The prepared consumer reads the supplied CSV, calls installed package functions, and formats each amount. Its --output option saves the result:

.venv/bin/python quote.py orders.csv --output handover.csv
cat handover.csv

The totals for T101 through T105 must be 3200, 1200, 1600, 0, and 4200 cents. IDs, quantities and membership values must remain attached to the right order.

diff -u compares two text files and shows changed lines. Compare against the independently supplied example:

diff -u /opt/labex-lookalike/approval/reference.csv handover.csv

No output means the files match. $? contains the immediately preceding command's exit status; read it before another command changes it:

echo $?

Expect 0. A difference returns 1; this is distinct from a missing file or a Python import error. Repair the recipe and reinstall, then rerun the consumer. Do not edit the orders or manually type a price list.

Rebuild Without Borrowing the First Environment

In this step, you will confirm that the saved recipe works independently of the current installation. A second virtual environment starts without the ticket packages:

python3 -m venv --without-pip .rebuild

Pass that different target to the same recipe:

bash install.sh .rebuild
.rebuild/bin/python quote.py orders.csv

Expect the same correct five orders. The original .venv, saved handover.csv, orders and consumer remain in place.

This result establishes a working recipe for the supplied approved source. Exact versions alone do not establish exact bytes: another source could provide a different wheel under the same name and version. The next independent lab introduces hashes for that boundary.

This lab uses synthetic, controlled package servers, not a production private index. Closing every source or copying a known CSV would prevent the useful rebuild you just demonstrated.

Summary

You compared actual ticket prices, identified direct and indirect dependencies, and rebuilt the approved package set from a saved recipe. You also delivered a complete price list without changing the original data or application. Package selection and successful installation are separate from business correctness.