Overview of Pkg.jl
masterProject.toml and Manifest.toml files.repository·master·Indexed 20 days ago
https://github.com/julialang/pkg.jlThe official package manager for the Julia programming language, shipped as a standard library since v1.0. Pkg.jl handles dependency resolution, environment management, and package installation. It includes APIs for managing artifacts via Pkg.Artifacts, handling complex requirements with PackageSpec and RegistrySpec, and experimental support for Julia Apps—standalone programs defined with a @main entry point and configured in Project.toml.
Project.toml and Manifest.toml files.A weak dependency is a dependency that is not automatically installed when your package is installed, but you can still control which versions are allowed if the user chooses to install it. This is primarily used for Extensions (requires Julia 1.9+).
To define weak dependencies, list them under the [weakdeps] section in your Project.toml, and then define their version constraints in the [compat] section.
[weakdeps]
SomePackage = "b3785f31-9d33-4cdf-bc73-f646780f1739"
[compat]
SomePackage = "1.2"Use Preferences.jl to allow users to read and write configuration settings to the top-level Project.toml. These preferences can be accessed at runtime or compile-time to toggle package behaviors.
Avoid: Writing configuration files directly into your package directory; use Preferences.jl instead.
Julia's handling of semantic versioning (semver) differs for versions with a major version of 0:
0.0.1 and 0.0.2) are considered incompatible.0.a.c where c <= b).0.2.0 vs 0.3.0) are considered incompatible.Examples:
Example = "0.0.1" results in the range [0.0.1, 0.0.2) (effectively only version 0.0.1).Example = "0.2.1" results in the range [0.2.1, 0.3.0).[compat]
Example = "0.0.1" # Range: [0.0.1, 0.0.2)
Example = "0.2.1" # Range: [0.2.1, 0.3.0)A project is defined by two primary files located in its root directory:
Project.toml or JuliaProject.toml): Describes project metadata, including name, UUID (for packages), authors, license, and a list of dependencies (names and UUIDs).Manifest.toml or JuliaManifest.toml): Describes the complete, exact dependency graph. It records the specific versions of every package and library used.Version-specific Manifests: You can suffix the manifest file with -v{major}.{minor}.toml (e.g., Manifest-v1.10.toml). Julia prefers the manifest that matches the current VERSION, allowing you to maintain different environments for different Julia versions.
It is important to distinguish between the distributable unit and the code namespace:
Pkg. It is a source tree containing a Project.toml file.module keyword) that provides a namespace for code.Typically, a package contains a module with the same name (e.g., the DataFrames package contains a DataFrames module). You interact with the module using import or using, but Pkg manages the package.
A workspace allows you to group multiple projects together. When resolving dependencies, Pkg considers the requirements of all projects in the workspace and records the compatible versions in a single shared manifest file located next to the base project file.
[deps].[workspace]
projects = ["test", "docs", "benchmarks", "PrivatePackage"]An environment is a collection of specific package versions. The active environment is the one currently being modified by Pkg commands like add, rm, and up.
(@v1.10)).Project.toml) which tracks explicitly installed packages.instantiate command in Pkg, it materializes the environment by downloading and installing the exact package versions specified in the Manifest.toml file.A package extension is a module that is automatically loaded only when a specific set of other packages are loaded into the Julia session.
Use extensions to avoid making packages unconditional dependencies. This prevents increased load times and unnecessary dependency overhead for users who do not use the specific functionality provided by the secondary package. For example, a Plotting package can provide specialized plotting methods for a Contour package via an extension, but users of Plotting who don't use Contour won't have to load Contour automatically.
ext/ directory) and registered in the parent package's Project.toml.A package's public API consists of symbols that are explicitly made public. There are two ways to do this:
export symbol: Makes the symbol available in the global namespace when a user calls using YourPackage.public symbol: Makes the symbol part of the public API (meaning changes to its behavior require a version bump), but the user must still access it via qualification (e.g., YourPackage.symbol) when using using YourPackage.Versioning Note: When you change the behavior of a public symbol such that it no longer conforms to its previous documentation/specification, you must increment the major version number according to Julia's SemVer variant.
module HelloWorld
export greet
# greet is available via 'using HelloWorld'
public greet_alien
# greet_alien is public API, but requires 'HelloWorld.greet_alien()'
import Random
"Writes a friendly message."
greet() = print("Hello World!")
"Greet an alien."
greet_alien() = print("Hello ", Random.randstring(8))
end # moduleThe Pkg Protocol is used by Pkg Clients to retrieve resources from Pkg Servers, such as registry versions, package source trees, and artifacts.
Key features include:
/registries changes frequently, individual resources like /registry/$uuid/$hash, /package/$uuid/$hash, and /artifact/$hash can be cached indefinitely based on HTTP headers.zstd (preferred) and gzip via the Accept-Encoding header.