AM 215 Packaging

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/140

encourage image

There's no tags or description

Looks like no tags are added yet.

141 Terms

1
New cards

Module

An importable unit of Python code, often a single .py file; for example, blackjack.deck.

2
New cards

Package

A module that can contain child modules or packages; for example, blackjack contains blackjack.deck.

3
New cards

Submodule

A module below a parent package in the import hierarchy; blackjack.deck is a submodule of blackjack.

4
New cards

Subpackage

A child module that is itself a package and can contain further modules or packages.

5
New cards

Regular package

A package initialized through an init.py file.

6
New cards

Namespace package

A shared import name to which separate projects can contribute; it can span multiple search locations without a shared init.py.

7
New cards

init.py

The initialization file executed when a regular package is first imported in a Python process; it can expose names for consumers.

8
New cards

Public API

The names and behavior that consumers are intended to rely on, including functions, classes, arguments, return values, and units.

9
New cards

Distribution

Installable code and metadata; its distribution name can differ from the Python import name.

10
New cards

Editable install

An installation that uses working source files, allowing ordinary Python source edits to appear on a fresh run without reinstalling.

11
New cards

Entry point

A mapping from an installed shell command to a Python function, such as blackjack-sim to blackjack.simulation:main.

12
New cards

Resource

A non-code file shipped with a package, such as strategies.json.

13
New cards

Runtime dependency

A package required while the installed code runs; declare it in [project] dependencies.

14
New cards

Build dependency

A package required to produce a distribution; declare Python build requirements in [build-system] requires.

15
New cards

Dependency group

A project-local set of dependencies, such as development or testing tools; these groups are not automatically installed for downstream consumers.

16
New cards

Extra

A named set of optional dependencies offered to consumers through published metadata, such as a plot extra requiring Matplotlib.

17
New cards

Metadata

Recorded package information, such as its name, version, supported Python versions, dependencies, and license.

18
New cards

Lockfile

A record of resolved dependency versions and artifacts for a project environment.

19
New cards

pyproject.toml

The project configuration file containing metadata, dependency declarations, build settings, and possibly tool-specific settings.

20
New cards

Source tree

The collection of working project files and directories that a developer edits.

21
New cards

src layout

A project layout placing importable code under src/, which reduces accidental imports from the project root.

22
New cards

Frontend

The tool that coordinates a build; in this lecture, uv invoked through uv build.

23
New cards

Backend

The software that constructs distributions; the lecture uses uv_build for pure Python and setuptools for Cython.

24
New cards

Build isolation

Keeping Python build requirements separate from the developer environment so the build does not silently rely on undeclared local Python packages.

25
New cards

sdist (source distribution)

An archive containing the project source and inputs needed to build a distribution without the original checkout; commonly a .tar.gz file.

26
New cards

Wheel

A built distribution prepared for installation, with the .whl extension; it can contain Python files, compiled extensions, resources, and metadata.

27
New cards

Compiler

A system tool that translates native source code, such as C, into machine code.

28
New cards

Cython

A language and toolchain that translates Python-like code, optionally using static types, into native source such as C for compilation.

29
New cards

Extension module

Compiled native code that Python can import and call.

30
New cards

CPython

The usual implementation of Python; cp313 in a wheel tag refers to CPython 3.13.

31
New cards

ABI (application binary interface)

Low-level binary layouts and calling conventions needed for compiled components to work together.

32
New cards

Platform tag

Wheel compatibility information identifying an operating system and processor architecture, such as linux_x86_64.

33
New cards

Shared library

Native code loaded from a separate library file and used by another program or extension.

34
New cards

glibc

The GNU C library used by many Linux distributions; compiled extensions may require functions provided by particular glibc versions.

35
New cards

manylinux

A compatibility policy for Linux wheels using glibc, specifying system requirements that conforming wheels must meet.

36
New cards

Compatibility baseline

The minimum supported system level; manylinux_2_17_x86_64 specifies a glibc 2.17 baseline for x86_64 Linux.

37
New cards

Build container

A controlled system environment containing a toolchain and libraries for building software.

38
New cards

auditwheel

A tool that inspects Linux wheels' native-library dependencies and can bundle eligible libraries when repairing a wheel.

39
New cards

License

Terms granting permission to use, modify, or redistribute code, subject to specified conditions.

40
New cards

SPDX expression

A standardized expression identifying license terms; MIT is a simple example.

41
New cards

Semantic versioning

A compatibility policy using MAJOR.MINOR.PATCH: breaking changes increment MAJOR, compatible features MINOR, and compatible fixes PATCH for a stable public API.

42
New cards

PEP 440

Python's rules for version identifiers, ordering, and requirement specifiers; a project's compatibility policy is a separate matter.

43
New cards

Git commit

A recorded source revision identified by a commit ID.

44
New cards

Git tag

A readable reference to a source revision, such as v0.2.0; a tag identifies source and does not contain the built wheel.

45
New cards

SHA-256 digest

A 64-character hexadecimal fingerprint of exact file bytes, used to compare an artifact with a trusted expected value.

46
New cards

Package index

A service from which installers discover and obtain package distributions.

47
New cards

PyPI

The main public Python Package Index used to distribute Python packages.

48
New cards

TestPyPI

A separate package index for testing package publication and installation.

49
New cards

Explicit index

In the lecture's uv configuration, an index used only for packages explicitly assigned to it.

50
New cards

Upload endpoint

The service URL that receives published distribution files; it can differ from the URL used to discover packages for installation.

51
New cards

GEV (generalized extreme-value distribution)

A probability distribution fitted in the lecture to the maximum losses from flat-bet evenings.

52
New cards

Martingale betting

A betting rule that doubles the bet after a loss; the lecture's model assumes unlimited credit.

53
New cards

What problem does packaging solve?

It lets another project reliably install and use your code by supplying code, metadata, requirements, resources, and build information.

54
New cards

Which project supplies the blackjack game, and which performs the analysis?

am215-blackjack supplies the game; blackjack-extremes uses it to analyze large betting losses.

55
New cards

Distribution name versus import name

The distribution name is used by installers, such as am215-blackjack; the import name is used in Python, such as blackjack.

56
New cards

What does uv add am215-blackjack do?

Adds the distribution as a dependency of the current project and normally updates its lockfile and environment.

57
New cards

What does from blackjack import Deck, play_round do?

Makes those names from blackjack available in the current Python code; importing play_round does not itself call the function.

58
New cards

What does from .deck import Card, Deck mean inside init.py?

Import Card and Deck from the deck module within the current package, exposing those names through the package.

59
New cards

Re-export

Making a name defined in an internal module available through another import location; for example, exposing Deck through blackjack.init.py.

60
New cards

Would an empty init.py automatically expose the Deck class from deck.py?

No. The class must be explicitly imported or otherwise defined in the package namespace for from blackjack import Deck to work as shown.

61
New cards

Can two projects contribute lab.cards and lab.statistics to the same namespace?

Yes. Both can contribute under lab if neither defines a conflicting regular lab package; in the example neither supplies lab/init.py.

62
New cards

What does lab.file is None show in the namespace example?

The shared lab namespace has no single initializing source file; it is assembled from package search locations.

63
New cards

How can a source checkout hide an incomplete wheel?

Python may import complete source files from the checkout instead of the installed wheel's incomplete package, making a broken distribution appear to work.

64
New cards

What does requires-python = ">=3.12" declare?

The project requires Python 3.12 or newer; this is metadata, not a Python program statement.

65
New cards

What does dependencies = ["numpy>=2"] declare?

NumPy version 2 or newer is a runtime requirement of the installed project.

66
New cards

What does uv_build>=0.12.1,<0.13 mean?

Use a uv_build version at least 0.12.1 and below 0.13; both constraints must hold.

67
New cards

Why set module-name = "blackjack" in the build configuration?

To identify the importable package when its name differs from the distribution name am215-blackjack.

68
New cards

Runtime dependency versus development dependency

Runtime dependencies are needed by consumers running the package; development dependencies are tools used while working on the project.

69
New cards

Dependency group versus extra

A group is local project tooling; an extra is optional functionality's dependencies that consumers can request through the distribution metadata.

70
New cards

Given NumPy as runtime, Ruff in dev, and pytest in test, what does uv sync --no-default-groups --group test select?

NumPy and pytest, plus any dependencies they require; Ruff is omitted because default groups are disabled and dev is not selected.

71
New cards

Given a plot extra requiring Matplotlib, what does uv sync --no-default-groups --extra plot select?

Runtime dependencies such as NumPy and the plot extra's Matplotlib; it does not select the dev or test groups.

72
New cards

Does --group test automatically exclude the default dev group?

No. uv sync --group test also includes default groups unless you explicitly exclude them, as with --no-default-groups.

73
New cards

How does a consumer request the plotting extra?

Use the requirement am215-blackjack[plot]; extras add optional dependencies to the package's normal requirements.

74
New cards

Does selecting an extra automatically run that feature?

No. Selecting an extra installs its optional dependencies; the program still needs to invoke the feature.

75
New cards

What does uv sync do in the lecture's installable project?

Synchronizes the project environment with the selected dependencies and installs the project editably by default.

76
New cards

What does uv run python -c "import blackjack; print(blackjack.file)" check?

Runs inline Python in the project environment and prints which blackjack file was imported; a src/ path indicates working source in this example.

77
New cards

What does python -c mean?

Execute the Python code supplied in the following command-line string instead of reading a script file.

78
New cards

Does a library's development lockfile bind its users?

No. Consumers resolve the library's declared requirements together with their own requirements and use their own locks.

79
New cards

Version constraint versus resolved version

A constraint specifies acceptable versions, such as numpy>=2; resolution selects particular versions satisfying all relevant project requirements.

80
New cards

What does blackjack-sim = "blackjack.simulation:main" declare under [project.scripts]?

An installed command named blackjack-sim that calls main in the blackjack.simulation module; the colon separates module and function names.

81
New cards

What do --seed 42 --rounds 200 --trajectories 3 supply to blackjack-sim?

A random seed of 42, 200 rounds per trajectory, and three trajectories; the program's argument-handling code interprets these options.

82
New cards

What does (files("blackjack") / "strategies.json").read_text() do?

Finds the resource through the installed blackjack package and reads its text; / joins the resource path rather than performing division.

83
New cards

Why use importlib.resources instead of relying on the current directory?

It locates data through the installed package, allowing the program to find resources when run from another directory.

84
New cards

Does reading a resource through importlib.resources guarantee that it was included in the wheel?

No. The build must actually include the resource; the access method cannot recover a missing file.

85
New cards

What happens during an isolated build?

The frontend prepares a separate build environment, installs declared build requirements, and asks the backend to produce distributions.

86
New cards

Does build isolation provide a complete operating system or guarantee a C compiler?

No. It isolates Python build dependencies; required system compilers and libraries must still be available.

87
New cards

Does building a wheel always compile code?

No. Pure-Python wheels package Python files and metadata; native extensions require compilation.

88
New cards

What must an sdist contain?

Enough project source, configuration, and other necessary project inputs to build without the original checkout, using the required build tools.

89
New cards

What does a wheel's .dist-info directory contain?

Distribution metadata, including files such as METADATA, entry_points.txt, and license text.

90
New cards

What does METADATA record in a wheel?

Package information including runtime requirements and optional extras.

91
New cards

What do py3-none-any mean in a wheel filename?

Python 3 tag; no specific Python ABI requirement; no platform-specific restriction in the tag. Separate Python-version requirements in metadata still apply.

92
New cards

What does uv build produce by default in the lecture?

An sdist, then a wheel built from that sdist, with outputs written to dist/.

93
New cards

uv build --sdist versus uv build --wheel

--sdist builds only the source archive; --wheel builds a wheel directly from the checkout.

94
New cards

Why build a wheel from a saved sdist?

To check that the distributed source contains the necessary project build inputs without relying on extra files in the checkout.

95
New cards

What does uv build dist/am215_blackjack-0.2.0.tar.gz --wheel --out-dir rebuilt do?

Builds a wheel using the saved source archive and writes the output to rebuilt/.

96
New cards

Does rebuilding automatically remove old versions from dist/?

No. Matching filenames are replaced, but files with different names can remain.

97
New cards

What does uv venv --python 3.13 consumer do?

Creates a virtual environment named consumer using Python 3.13.

98
New cards

What does uv pip install --python consumer/bin/python . do?

Builds and installs the source project in the current directory into the consumer environment; . means the current directory.

99
New cards

Installing a checkout or sdist versus installing a wheel

A checkout or sdist must be built into a wheel before installation; an existing compatible wheel supplies prepared files without rebuilding that project.

100
New cards

Does a wheel normally contain all its Python dependencies?

No. It declares runtime dependencies, which the installer resolves and installs separately as needed.