Skip to content

Commit 608b98e

Browse files
Ben DavisallRisc
authored andcommitted
Massively improved the docstrings for each module and some classes.
1 parent c0de555 commit 608b98e

10 files changed

Lines changed: 139 additions & 113 deletions

File tree

src/fastsandpm/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,26 @@
3232
>>> manifest = fastsandpm.get_manifest("./my-project")
3333
>>> print(manifest.package.name)
3434
'my-package'
35+
>>> resolved = fastsandpm.dependencies.resolve(manifest)
36+
>>> print(type(resolved))
37+
<class 'dict'>
38+
>>> build_library(resolved, pathlib.Path("my-library"))
3539
36-
Classes:
37-
Manifest: The main manifest model representing a proj.toml file.
38-
Package: Package metadata (name, version, description, authors).
39-
ManifestNotFoundError: Raised when a manifest file cannot be found.
40-
ManifestParseError: Raised when a manifest file cannot be parsed.
40+
Included Classes:
41+
- :py:class:`~manifest.Manifest`: The main manifest model representing a `proj.toml` file.
42+
- :py:class:`~manifest.Package`: Package metadata (name, version, description, authors).
43+
- :py:class:`~manifest.ManifestNotFoundError`: Raised when a manifest file cannot be found.
44+
- :py:class:`~manifest.ManifestParseError`: Raised when a manifest file cannot be parsed.
4145
4246
Functions:
43-
get_manifest: Load and parse a manifest from a repository path.
47+
- :py:func:`~manifest.get_manifest`: Load and parse a manifest from a repository path.
48+
- :py:func:`~dependencies.resolve`: Resolve all dependencies for a manifest.
49+
- :py:func:`~install.build_library`: Build a library from a resovled dependency definition.
50+
- :py:func:`~install.library_from_manifest`: Build a library of dependencies from a manifest.
4451
4552
Attributes:
46-
__version__: The current version of the FastSandPM package.
47-
__author__: The primary author of the package.
53+
__version__ (str): The current version of the FastSandPM package.
54+
__author__ (str): The primary author of the package.
4855
4956
See Also:
5057
- fastsandpm.dependencies: Dependency resolution subpackage

src/fastsandpm/_git_utils.py

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,35 @@
2424
git-based sources.
2525
2626
Repository Operations:
27-
clone: Clone a repository from a remote URL.
28-
checkout: Checkout a specific commit, branch, or tag.
29-
fetch: Fetch updates from the remote repository.
27+
- clone: Clone a repository from a remote URL.
28+
- checkout: Checkout a specific commit, branch, or tag.
29+
- fetch: Fetch updates from the remote repository.
3030
3131
Repository State:
32-
is_dirty: Check if a repository has uncommitted changes.
33-
is_git_repo: Check if a path is a git repository.
34-
get_head_commit: Get the HEAD commit hash.
35-
get_current_branch: Get the current branch name.
36-
get_tags_at_head: Get all tags pointing to HEAD.
37-
get_remote_url: Get the URL of a remote.
32+
- is_dirty: Check if a repository has uncommitted changes.
33+
- is_git_repo: Check if a path is a git repository.
34+
- get_head_commit: Get the HEAD commit hash.
35+
- get_current_branch: Get the current branch name.
36+
- get_tags_at_head: Get all tags pointing to HEAD.
37+
- get_remote_url: Get the URL of a remote.
3838
3939
Remote Operations:
40-
remote_exists: Check if a remote repository is accessible.
41-
get_available_tags: Get all tags from a remote repository.
42-
get_remote_refs: Get all refs grouped by commit hash (cached).
43-
get_commit_for_ref: Get commit hash for a specific ref.
44-
get_remote_file: Fetch a single file from a remote repository.
40+
- remote_exists: Check if a remote repository is accessible.
41+
- get_available_tags: Get all tags from a remote repository.
42+
- get_remote_refs: Get all refs grouped by commit hash (cached).
43+
- get_commit_for_ref: Get commit hash for a specific ref.
44+
- get_remote_file: Fetch a single file from a remote repository.
4545
4646
URL Parsing:
47-
parse_github_url: Parse GitHub URLs to extract owner/repo.
48-
parse_gitlab_url: Parse GitLab URLs to extract host/project path.
47+
- parse_github_url: Parse GitHub URLs to extract owner/repo.
48+
- parse_gitlab_url: Parse GitLab URLs to extract host/project path.
4949
5050
Hosting Provider APIs:
51-
fetch_file_from_github: Fetch a file via GitHub raw content URL.
52-
fetch_file_from_gitlab: Fetch a file via GitLab repository API.
53-
fetch_file_from_hosting_api: Try fetching via supported hosting APIs.
51+
- fetch_file_from_github: Fetch a file via GitHub raw content URL.
52+
- fetch_file_from_gitlab: Fetch a file via GitLab repository API.
53+
- fetch_file_from_hosting_api: Try fetching via supported hosting APIs.
5454
55-
Note:
56-
This module requires git to be installed and available in the system PATH.
55+
.. note:: This module requires git to be installed and available in the system PATH.
5756
"""
5857

5958
from __future__ import annotations

src/fastsandpm/dependencies/__init__.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,25 @@
2222
including requirement definitions, candidate generation, and resolution
2323
algorithms.
2424
25-
Modules:
26-
requirements: Defines requirement types for different dependency sources.
27-
candidates: Implements candidate generation from requirements.
28-
provider: Provides the dependency resolution provider for resolvelib.
25+
Included Classes:
26+
- :py:class:`~requirements.ConcreteRequirement`: Union type of all concrete requirement types.
27+
- :py:class:`~requirements.GitRequirement`: Base class for git-based requirements.
28+
- :py:class:`~requirements.BranchGitRequirement`: Git requirement pinned to a specific branch.
29+
- :py:class:`~requirements.CommitGitRequirement`: Git requirement pinned to a specific commit.
30+
- :py:class:`~requirements.TaggedGitRequirement`: Git requirement pinned to a specific tag.
31+
- :py:class:`~requirements.VersionedGitRequirement`: Git requirement with version constraints.
32+
- :py:class:`~requirements.PackageIndexRequirement`: Requirement from a package index.
33+
- :py:class:`~requirements.PathRequirement`: Requirement from a local filesystem path.
34+
- :py:class:`~candidates.Candidate`: Abstract base class for dependency candidates.
35+
- :py:class:`~candidates.PackageIndexCandidate`: Candidate from a package index registry.
36+
- :py:class:`~candidates.PathCandidate`: Candidate from a local filesystem path.
37+
- :py:class:`~candidates.GitCandidate`: Candidate from a git repository.
2938
30-
Classes:
31-
ConcreteRequirement: Union type of all concrete requirement types.
32-
GitRequirement: Base class for git-based requirements.
33-
BranchGitRequirement: Git requirement pinned to a specific branch.
34-
CommitGitRequirement: Git requirement pinned to a specific commit.
35-
TaggedGitRequirement: Git requirement pinned to a specific tag.
36-
VersionedGitRequirement: Git requirement with version constraints.
37-
PackageIndexRequirement: Requirement from a package index.
38-
PathRequirement: Requirement from a local filesystem path.
39-
Candidate: Abstract base class for dependency candidates.
40-
PackageIndexCandidate: Candidate from a package index registry.
41-
PathCandidate: Candidate from a local filesystem path.
42-
GitCandidate: Candidate from a git repository.
39+
Included Functions:
40+
- :py:func:`~candidates.candidate_factory`: Singledispatch function to create candidates
41+
from requirements.
4342
44-
Functions:
45-
candidate_factory: Singledispatch function to create candidates from requirements.
46-
resolve: Resolve all dependencies for a manifest.
43+
- :py:func:`~provider.resolve`: Resolve all dependencies for a manifest.
4744
"""
4845

4946
from __future__ import annotations

src/fastsandpm/dependencies/candidates.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@
2323
concrete versions of dependencies that can satisfy requirements.
2424
2525
Classes:
26-
Candidate: Abstract base class for all candidate types.
27-
PackageIndexCandidate: Candidate from a package index registry.
28-
PathCandidate: Candidate from a local filesystem path.
29-
GitCandidate: Candidate from a git repository.
26+
- :py:class:`Candidate`: Abstract base class for all candidate types.
27+
- :py:class:`PackageIndexCandidate`: Candidate from a package index registry.
28+
- :py:class:`PathCandidate`: Candidate from a local filesystem path.
29+
- :py:class:`GitCandidate`: Candidate from a git repository.
3030
3131
Functions:
32-
candidate_factory: Singledispatch function to create candidates from requirements.
32+
- :py:func:`candidate_factory`: Singledispatch function to create candidates from requirements.
3333
"""
3434

3535
from __future__ import annotations
@@ -87,6 +87,7 @@ def satisfies(self, requirement: ConcreteRequirement) -> bool:
8787
"""Check if this candidate satisfies the given requirement.
8888
8989
A candidate satisfies a requirement when:
90+
9091
- The requirement name and candidate name match
9192
- If the requirement specifies a version, the candidate's version matches
9293
@@ -114,8 +115,9 @@ class PackageIndexCandidate(Candidate):
114115
Artifactory. This implementation is currently a placeholder as package
115116
index registries are not yet fully implemented.
116117
117-
Note:
118-
Package index registry support is under development.
118+
.. warning::
119+
120+
Package index registry support is under development and is not currently implemented.
119121
"""
120122

121123
def get_manifest(self) -> Manifest | None:
@@ -169,9 +171,9 @@ def satisfies(self, requirement: ConcreteRequirement) -> bool:
169171
A path candidate satisfies a requirement when the requirement name
170172
and candidate name match, and type-specific conditions are met:
171173
172-
* For PackageIndexRequirement: the candidate's version matches the specifier
173-
* For PathRequirement: the candidate path ends with the requirement path
174-
* For Git requirements: the path is a git repo and HEAD complies with
174+
- For PackageIndexRequirement: the candidate's version matches the specifier
175+
- For PathRequirement: the candidate path ends with the requirement path
176+
- For Git requirements: the path is a git repo and HEAD complies with
175177
the requirement's constraints (commit, branch, tag, or version)
176178
177179
Args:
@@ -191,7 +193,7 @@ def satisfies(self, requirement: ConcreteRequirement) -> bool:
191193
req_parts = requirement.path.parts
192194
cand_parts = self.path.parts
193195
if len(req_parts) <= len(cand_parts):
194-
return cand_parts[-len(req_parts) :] == req_parts
196+
return cand_parts[-len(req_parts):] == req_parts
195197
return False
196198

197199
# Handle Git requirements: check if candidate points to a git repo
@@ -327,6 +329,7 @@ def satisfies(self, requirement: ConcreteRequirement) -> bool:
327329
"""Check if this git candidate satisfies the given requirement.
328330
329331
A git candidate satisfies a requirement when:
332+
330333
- The requirement name and candidate name match
331334
- If the requirement specifies a version, the candidate's version matches
332335
- For PackageIndexRequirement: only if no specific index is required
@@ -400,9 +403,15 @@ def candidate_factory(
400403
Yields:
401404
Candidate objects that could satisfy the requirement.
402405
403-
Note:
406+
.. note::
407+
404408
The base implementation yields no candidates. Specialized implementations
405-
are registered for each concrete requirement type.
409+
are registered for each concrete requirement type through the singledispatch.
410+
411+
.. note::
412+
413+
Package index registries are not yet implemented, so this currently
414+
yields no candidates.
406415
"""
407416
yield from []
408417

@@ -420,8 +429,7 @@ def _package_index_candidate_factory(
420429
Yields:
421430
PackageIndexCandidate objects matching the requirement.
422431
423-
Note:
424-
Package index registries are not yet implemented, so this currently
432+
.. note:: Package index registries are not yet implemented, so this currently
425433
yields no candidates.
426434
"""
427435
yield from []

src/fastsandpm/dependencies/provider.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
and dependency extraction during the resolution process.
2424
2525
Classes:
26-
FastSandProvider: The main dependency resolution provider.
26+
- :py:class:`~FastSandProvider`: The main dependency resolution provider.
2727
2828
Functions:
29-
resolve: Convenience function to resolve dependencies for a manifest.
29+
- :py:func:`~resolve`: Convenience function to resolve dependencies for a manifest.
3030
3131
Type Aliases:
32-
FastSandReqInfo: Type alias for requirement information tuples.
33-
FastSandReporter: Type alias for the resolution reporter.
32+
- :py:type:`~FastSandReqInfo`: FastSandReqInfo: Type alias for requirement information tuples.
33+
- :py:type:`~FastSandReporter`: Type alias for the resolution reporter.
3434
"""
3535

3636
from __future__ import annotations
@@ -59,6 +59,9 @@
5959

6060

6161
FastSandReqInfo = RequirementInformation[ConcreteRequirement, Candidate]
62+
""".. py:type:: FastSandReqInfo:
63+
Type alias for requirement information tuples.
64+
"""
6265

6366

6467
class FastSandProvider(resolvelib.AbstractProvider[ConcreteRequirement, Candidate, str]):
@@ -279,6 +282,7 @@ def narrow_requirement_selection(
279282

280283

281284
FastSandReporter = resolvelib.BaseReporter[ConcreteRequirement, Candidate, str]
285+
"""Type alias for the resolution reporter."""
282286

283287

284288
def resolve(manifest: Manifest) -> dict[str, Candidate]:

src/fastsandpm/manifest.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
of package metadata, dependencies, and registry configurations.
2424
2525
Classes:
26-
ManifestNotFoundError: Exception raised when manifest file is not found.
27-
ManifestParseError: Exception raised when manifest parsing fails.
28-
Package: Package metadata (name, version, description, authors).
29-
Dependencies: Collection of package dependencies.
30-
Manifest: The complete manifest model.
26+
- :py:exc:`~ManifestNotFoundError`: Exception raised when manifest file is not found.
27+
- :py:exc:`~ManifestParseError`: Exception raised when manifest parsing fails.
28+
- :py:class:`~Package`: Package metadata (name, version, description, authors).
29+
- :py:class:`~Dependencies`: Collection of package dependencies.
30+
- :py:class:`~Manifest`: The complete manifest model.
3131
3232
Functions:
33-
get_manifest: Load and parse a manifest from a repository path.
34-
get_manifest_from_bytes: Parse a manifest from raw bytes content.
33+
- :py:func:`~get_manifest`: Load and parse a manifest from a repository path.
34+
- :py:func:`~get_manifest_from_bytes`: Parse a manifest from raw bytes content.
3535
3636
Constants:
37-
MANIFEST_FILENAME: The default manifest filename ("proj.toml").
37+
- :py:const:`~MANIFEST_FILENAME`: The default manifest filename ("proj.toml").
3838
3939
Example:
4040
>>> from fastsandpm.manifest import get_manifest
@@ -157,7 +157,15 @@ class Dependencies(RootModel[list[ConcreteRequirement]]):
157157
The model validator automatically converts dictionary-style TOML
158158
dependencies into the correct dependency type based on the keys present.
159159
160-
Example:
160+
Example TOML:
161+
.. code-block:: toml
162+
163+
[dependencies]
164+
165+
my-lib = "1.0.0"
166+
other_lib = {git = "https://github.com/username/repo.git", tag = "v1.0.0"}
167+
168+
Example Usage:
161169
>>> deps = manifest.dependencies
162170
>>> for dep in deps:
163171
... print(dep.name)

src/fastsandpm/registries.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
various sources including git hosts, package indices, and local paths.
2323
2424
Classes:
25-
DependencyNotFoundError: Exception raised when a dependency cannot be found.
26-
GitRegistry: Registry for resolving dependencies from git hosts.
27-
PackageIndexRegistery: Registry for resolving dependencies from package indices.
28-
PathRegistry: Registry for resolving dependencies from local filesystem paths.
29-
Registries: Collection of registries used during dependency resolution.
25+
- :py:exc:`~DependencyNotFoundError`: Exception raised when a dependency cannot be found.
26+
- :py:class:`~GitRegistry`: Registry for resolving dependencies from git hosts.
27+
- :py:class:`~PackageIndexRegistery`: Registry for resolving dependencies from package indices.
28+
- :py:class:`~PathRegistry`: Registry for resolving dependencies from local filesystem paths.
29+
- :py:class:`~Registries`: Collection of registries used during dependency resolution.
3030
3131
Type Aliases:
32-
ConcreteRegistry: Union type of all concrete registry types.
32+
- :py:type:`~ConcreteRegistry`: Union type of all concrete registry types.
3333
"""
3434

3535
from __future__ import annotations
@@ -139,12 +139,12 @@ def parse_dependencies(cls, data: Any) -> Any:
139139
Returns:
140140
A list of registry dictionaries ready for model instantiation.
141141
142-
Examples:
143-
Input formats supported:
144-
- {"name": "foo", "remote": "url"} -> [{"name": "foo", ...}]
145-
- {"foo": "url"} -> [{"name": "foo", "remote": "url"}]
146-
- {"foo": {"remote": "url"}} -> [{"name": "foo", "remote": "url"}]
147-
- {"foo": {"path": "./path"}} -> [{"name": "foo", "path": "./path"}]
142+
Example Input formats supported:
143+
144+
- ``{"name": "foo", "remote": "url"} -> [{"name": "foo", ...}]``
145+
- ``{"foo": "url"} -> [{"name": "foo", "remote": "url"}]``
146+
- ``{"foo": {"remote": "url"}} -> [{"name": "foo", "remote": "url"}]``
147+
- ``{"foo": {"path": "./path"}} -> [{"name": "foo", "path": "./path"}]``
148148
"""
149149
if isinstance(data, dict):
150150
# Handle single dependency passed as dict with 'name' key

src/fastsandpm/versioning/__init__.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,21 @@
3333
- Comparison: ``">=1.0.0"``, ``"<2.0.0"``
3434
- Range: ``">=1.0.0,<2.0.0"``
3535
36-
Classes:
37-
PreReleaseStage: Enum for pre-release stages (ALPHA, BETA, RELEASE_CANDIDATE).
38-
LibraryVersion: Represents and compares semantic versions.
39-
VersionSpecifier: Abstract base class for version specifications.
40-
DirectVersionSpecifier: Matches a single version exactly.
41-
CaretVersionSpecifier: Matches semver-compatible versions (^x.y.z).
42-
ComparisonVersionSpecifier: Matches using comparison operators.
43-
RangeVersionSpecifier: Matches versions within a range.
36+
Included Classes:
37+
- :py:enim`~library_version.PreReleaseStage`: Enum for pre-release stages.
38+
- :py:class`~library_version.LibraryVersion`: Represents and compares semantic versions.
39+
- :py:class`~specifier.VersionSpecifier`: Abstract base class for version specifications.
40+
- :py:class`~specifier.DirectVersionSpecifier`: Matches a single version exactly.
41+
- :py:class`~specifier.CaretVersionSpecifier`: Matches semver-compatible versions (^x.y.z).
42+
- :py:class`~specifier.ComparisonVersionSpecifier`: Matches using comparison operators.
43+
- :py:class`~specifier.RangeVersionSpecifier`: Matches versions within a range.
4444
45-
Functions:
46-
meets_constraints: Check if a version meets specified constraints.
47-
find_compatible_version: Find the best matching version from available options.
48-
version_specifier_from_str: Parse a version specifier string.
45+
Included Functions:
46+
47+
- :py:func:`~specifier.meets_constraints`: Check if a version meets specified constraints.
48+
- :py:func:`~specifier.find_compatible_version`: Find the best matching version from
49+
a list of options.
50+
- :py:func:`~specifier.version_specifier_from_str`: Parse a version specifier string.
4951
5052
Example:
5153
>>> from fastsandpm.versioning import LibraryVersion, version_specifier_from_str

0 commit comments

Comments
 (0)