@@ -64,22 +64,24 @@ Locating distributions
64
64
~~~~~~~~~~~~~~~~~~~~~~
65
65
66
66
It seems that the simplest API to locate a distribution would look like
67
- ``locate(requirement) ``, where ``requirement `` is a string giving the
68
- distribution name and optional version constraints. Given that we know that
69
- distributions can be found in different places, it's best to consider a
70
- : class: ` Locator ` class which has a :meth: `locate ` method with a corresponding
67
+ ``locate(requirement) ``, where ``requirement `` is a string giving the distribution
68
+ name and optional version constraints. Given that we know that distributions can be
69
+ found in different places, it's best to consider a :class: ` ~distlib.locators.Locator `
70
+ class which has a :meth: `~distlib.locators.Locator. locate ` method with a corresponding
71
71
signature, with subclasses for each of the different types of location that
72
- distributions inhabit. It's also reasonable to provide a default locator in
73
- a module attribute :attr: `default_locator `, and a module-level :func: `locate `
74
- function which calls the :meth: `locate ` method on the default locator.
75
-
76
- Since we'll often need to locate all the versions of a project before picking
77
- one, we can imagine that a locator would need a :meth: `get_project ` method for
78
- fetching all versions of a project; and since we will be likely to want to use
79
- caching, we can assume there will be a :meth: `_get_project ` method to do the
80
- actual work of fetching the version data, which the higher-level
81
- :meth: `get_project ` will call (and probably cache). So our locator base class
82
- will look something like this::
72
+ distributions inhabit. It's also reasonable to provide a default locator in a module
73
+ attribute :attr: `~distlib.locators.default_locator `, and a module-level
74
+ :func: `~distlib.locators.locate ` function which calls the
75
+ :meth: `~distlib.locators.Locator.locate ` method on the default locator.
76
+
77
+ Since we'll often need to locate all the versions of a project before picking one, we
78
+ can imagine that a locator would need a :meth: `~distlib.locators.Locator.get_project `
79
+ method for fetching all versions of a project; and since we will be likely to want to
80
+ use caching, we can assume there will be a
81
+ :meth: `~distlib.locators.Locator._get_project ` method to do the actual work of
82
+ fetching the version data, which the higher-level
83
+ :meth: `~distlib.locators.Locator.get_project ` will call (and probably cache). So our
84
+ locator base class will look something like this::
83
85
84
86
class Locator(object):
85
87
"""
@@ -114,20 +116,20 @@ will look something like this::
114
116
instance, or an empty dictionary if nothing was found.
115
117
"""
116
118
117
- When attempting to :meth: `locate `, it would be useful to pass requirement
118
- information to :meth: `get_project ` / :meth: ` _get_project `. This can be done in
119
- a :attr: ` matcher ` attribute which is normally `` None `` but set to a
120
- :class: ` distlib.version.Matcher ` instance when a :meth: ` locate ` call is in
121
- progress.
119
+ When attempting to :meth: `~distlib.locators.Locator. locate `, it would be useful to
120
+ pass requirement information to :meth: `~distlib.locators.Locator. get_project ` /
121
+ :meth: ` ~distlib.locators.Locator._get_project `. This can be done in a :attr: ` ~distlib.locators.Locator.matcher `
122
+ attribute which is normally `` None `` but set to a :class: ` ~distlib.version.Matcher `
123
+ instance when a :meth: ` ~distlib.locators.Locator.locate ` call is in progress.
122
124
123
125
Note that in order to work with legacy version numbers (those not complying with PEP
124
126
440), you need to pass ``scheme='legacy' `` to the initializer for a locator.
125
127
126
128
Finding dependencies
127
129
~~~~~~~~~~~~~~~~~~~~
128
130
129
- A dependency finder will depend on a locator to locate dependencies. A simple
130
- approach will be to consider a :class: `DependencyFinder ` class which takes a
131
+ A dependency finder will depend on a locator to locate dependencies. A simple approach
132
+ will be to consider a :class: `~distlib.locators. DependencyFinder ` class which takes a
131
133
locator as a constructor argument. It might look something like this::
132
134
133
135
class DependencyFinder(object):
@@ -195,17 +197,19 @@ A minimal solution
195
197
^^^^^^^^^^^^^^^^^^
196
198
197
199
The distutils approach was to have several separate command classes called
198
- ``register ``, ``upload `` and ``upload_doc ``, where really all that was needed
199
- was some methods. That's the approach ``distlib `` takes, by implementing a
200
- :class: `PackageIndex ` class with :meth: `register `, :meth: `upload_file ` and
201
- :meth: `upload_documentation ` methods. The :class: `PackageIndex ` class contains
202
- no user interface code whatsoever: that's assumed to be the domain of the
203
- packaging tool. The packaging tool is expected to get the required information
204
- from a user using whatever means the developers of that tool deem to be the
205
- most appropriate; the required attributes are then set on the
206
- :class: `PackageIndex ` instance. (Examples of this kind of information: user
207
- name, password, whether the user wants to save a default configuration, where
208
- the signing program and its keys live.)
200
+ ``register ``, ``upload `` and ``upload_doc ``, where really all that was needed was some
201
+ methods. That's the approach ``distlib `` takes, by implementing a
202
+ :class: `~distlib.index.PackageIndex ` class with
203
+ :meth: `~distlib.index.PackageIndex.register `,
204
+ :meth: `~distlib.index.PackageIndex.upload_file ` and
205
+ :meth: `~distlib.index.PackageIndex.upload_documentation ` methods. The
206
+ :class: `~distlib.index.PackageIndex ` class contains no user interface code whatsoever:
207
+ that's assumed to be the domain of the packaging tool. The packaging tool is expected
208
+ to get the required information from a user using whatever means the developers of
209
+ that tool deem to be the most appropriate; the required attributes are then set on the
210
+ :class: `~distlib.index.PackageIndex ` instance. (Examples of this kind of information:
211
+ user name, password, whether the user wants to save a default configuration, where the
212
+ signing program and its keys live.)
209
213
210
214
The minimal interface to provide the required functionality thus looks like
211
215
this::
@@ -245,8 +249,8 @@ this::
245
249
archiving the directory contents into a .zip file.
246
250
"""
247
251
248
- The following additional attributes can be identified on :class: ` PackageIndex `
249
- instances:
252
+ The following additional attributes can be identified on
253
+ :class: ` ~distlib.index.PackageIndex ` instances:
250
254
251
255
* ``username `` - the username to use for authentication.
252
256
* ``password `` - the password to use for authentication.
@@ -465,7 +469,7 @@ available via a file on the file system, we'll assume a simple caching
465
469
solution that saves any such resources to a local file system cache, and
466
470
returns the filename of the resource in the cache. We need to divide the
467
471
work between the finder and the cache. We'll deliver the cache function
468
- through a :class: `Cache ` class, which will have the following methods:
472
+ through a :class: `~distlib.util. Cache ` class, which will have the following methods:
469
473
470
474
* A constructor which takes an optional base directory for the cache. If
471
475
none is provided, we'll construct a base directory of the form::
@@ -477,36 +481,36 @@ through a :class:`Cache` class, which will have the following methods:
477
481
will be used as ``<rootdir> `` -- otherwise, the user's home directory
478
482
will be used.
479
483
480
- * A :meth: `get ` method which takes a ``Resource `` and returns a file system
481
- filename, such that the contents of that named file will be the contents
482
- of the resource.
483
-
484
- * An :meth: `is_stale ` method which takes a `` Resource `` and its corresponding
485
- file system filename, and returns whether the file system file is stale
486
- when compared with the resource. Knowing that cache invalidation is hard,
487
- the default implementation just returns ``True ``.
488
-
489
- * A :meth: `prefix_to_dir ` method which converts a prefix to a directory name.
490
- We'll assume that for the cache, a resource path can be divided into two
491
- parts: the *prefix * and the *subpath *. For resources in a .zip file, the
492
- prefix would be the pathname of the archive, while the subpath would be the
493
- path inside the archive. For a file system resource, since it is already in
494
- the file system, the prefix would be ``None `` and the subpath would be the
495
- absolute path name of the resource. The :meth: `prefix_to_dir ` method's job
496
- is to convert a prefix (if not ``None ``) to a subdirectory in the cache
497
- that holds the cached files for all resources with that prefix. We'll
498
- delegate the determination of a resource's prefix and subpath to its finder,
499
- using a :meth: `get_cache_info ` method on finders, which takes a `` Resource ``
500
- and returns a (``prefix ``, ``subpath ``) tuple.
501
-
502
- The default implementation will use :func: `os.splitdrive ` to see if there's
484
+ * A :meth: `~distlib.resources.ResourceCache. get ` method which takes a ``Resource `` and
485
+ returns a file system filename, such that the contents of that named file will be
486
+ the contents of the resource.
487
+
488
+ * An :meth: `~distlib.resources.ResourceCache. is_stale ` method which takes a
489
+ `` Resource `` and its corresponding file system filename, and returns whether the
490
+ file system file is stale when compared with the resource. Knowing that cache
491
+ invalidation is hard, the default implementation just returns ``True ``.
492
+
493
+ * A :meth: `~distlib.util.Cache. prefix_to_dir ` method which converts a
494
+ prefix to a directory name. We'll assume that for the cache, a resource path can be
495
+ divided into two parts: the *prefix * and the *subpath *. For resources in a .zip
496
+ file, the prefix would be the pathname of the archive, while the subpath would be
497
+ the path inside the archive. For a file system resource, since it is already in the
498
+ file system, the prefix would be ``None `` and the subpath would be the absolute path
499
+ name of the resource. The :meth: `~distlib.util.Cache. prefix_to_dir ` method's job is
500
+ to convert a prefix (if not ``None ``) to a subdirectory in the cache that holds the
501
+ cached files for all resources with that prefix. We'll delegate the determination of
502
+ a resource's prefix and subpath to its finder, using a
503
+ :meth: `~distlib.resources.ResourceFinder. get_cache_info ` method on finders, which
504
+ takes a `` Resource `` and returns a (``prefix ``, ``subpath ``) tuple.
505
+
506
+ The default implementation will use :func: `os.path. splitdrive ` to see if there's
503
507
a Windows drive, if present, and convert its ``':' `` to ``'---' ``. The rest
504
508
of the prefix will be converted by replacing ``'/' `` by ``'--' ``, and
505
509
appending ``'.cache' `` to the result.
506
510
507
511
The cache will be activated when the ``file_path `` property of a ``Resource ``
508
512
is accessed. This will be a cached property, and will call the cache's
509
- :meth: `get ` method to obtain the file system path.
513
+ :meth: `~distlib.resources.ResourceCache. get ` method to obtain the file system path.
510
514
511
515
The ``scripts `` API
512
516
-------------------
@@ -602,9 +606,9 @@ In addition, other methods suggest themselves for :class:`ScriptMaker`:
602
606
analysis tool, over all the installed files.
603
607
604
608
* The details of the callable specification can be encapsulated in a utility
605
- function, :func: `~distlib.util.get_exports_entry `. This would take a
606
- specification and return ``None ``, if the specification didn't match the
607
- callable format, or an instance of :class: `ExportEntry ` if it did match.
609
+ function, :func: `~distlib.util.get_export_entry `. This would take a specification
610
+ and return ``None ``, if the specification didn't match the callable format, or an
611
+ instance of :class: `~distlib.util. ExportEntry ` if it did match.
608
612
609
613
In addition, the following attributes on a ``ScriptMaker `` could be further used
610
614
to refine its behaviour:
@@ -863,11 +867,10 @@ each scheme are bundled into a simple :class:`VersionScheme` class::
863
867
Of course, the version class is also available through the matcher's
864
868
``version_class `` attribute.
865
869
866
- :class: `VersionScheme ` makes it easier to work with alternative version schemes.
867
- For example, say we decide to experiment with an "adaptive" version scheme,
868
- which is based on the PEP 386 scheme, but when handed a non-conforming version,
869
- automatically tries to convert it to a normalized version using
870
- :func: `suggest_normalized_version `. Then, code which has to deal with version
870
+ :class: `VersionScheme ` makes it easier to work with alternative version schemes. For
871
+ example, say we decide to experiment with an "adaptive" version scheme, which is based
872
+ on the PEP 386 scheme, but when handed a non-conforming version, automatically tries
873
+ to convert it to a normalized version. Then, code which has to deal with version
871
874
schemes just has to pick the appropriate scheme by name.
872
875
873
876
Creating the adaptive scheme is easy::
@@ -927,10 +930,10 @@ There are basically two operations which need to be performed on wheels:
927
930
A minimal solution
928
931
^^^^^^^^^^^^^^^^^^
929
932
930
- Since we're talking about wheels, it seems likely that a :class: `Wheel ` class
931
- would be part of the design. This allows for extensibility over a purely
932
- function-based API. The :class: `Wheel ` would be expected to have methods that
933
- support the required operations::
933
+ Since we're talking about wheels, it seems likely that a :class: `~distlib.wheel. Wheel `
934
+ class would be part of the design. This allows for extensibility over a purely
935
+ function-based API. The :class: `~distlib.wheel. Wheel ` would be expected to have
936
+ methods that support the required operations::
934
937
935
938
class Wheel(object):
936
939
def __init__(self, spec):
@@ -985,7 +988,7 @@ support the required operations::
985
988
"""
986
989
987
990
In addition to the above, the following attributes can be identified for a
988
- :class: `Wheel ` instance:
991
+ :class: `~distlib.wheel. Wheel ` instance:
989
992
990
993
* ``name `` -- the name of the distribution
991
994
* ``version `` -- the version of the distribution
0 commit comments