|
1 |
| -********* |
2 |
| -Fetchcode |
3 |
| -********* |
4 |
| -It is a library to reliably fetch code via HTTP, FTP and version control systems. |
| 1 | +FetchCode: Utilities to fetch code from purls, URLs and version control repos. |
| 2 | +================================================================================ |
5 | 3 |
|
6 |
| -Installation |
7 |
| -############ |
8 |
| -Clone the repo using |
| 4 | +FetchCode is a library to reliably fetch code via HTTP, FTP and version control |
| 5 | +systems. It can work using plain HTTP and FTP URLs, as well as |
| 6 | +`Package URLs <https://github.com/package-url>`_ and version control (VCS) URLs |
| 7 | +as used in Python pip and as specified in `SPDX Package Download Location |
| 8 | +<https://spdx.github.io/spdx-spec/3-package-information/#37-package-download-location>`_ |
9 | 9 |
|
10 |
| -:code:`git clone https://github.com/nexB/fetchcode` |
| 10 | +Homepage and support: https://github.com/nexB/fetchcode |
11 | 11 |
|
12 |
| -Then install all the requirements using |
13 | 12 |
|
14 |
| -:code:`pip3 install -r requirements.txt` |
| 13 | +Why FetchCode? |
| 14 | +-------------- |
15 | 15 |
|
16 |
| -Running test suite |
17 |
| -################## |
| 16 | +It is surprisingly difficult to have a simple API to consistently fetch code |
| 17 | +from package repositories, version control repositories and APIs: each site |
| 18 | +and each package manager has its own unique and peculiar ways. FetchCode goal |
| 19 | +is to abstract all these details and make it easy to fetch things reliably. |
18 | 20 |
|
19 |
| -To run test suite |
20 | 21 |
|
21 |
| -:code:`python3 -m pytest` |
| 22 | +Development installation |
| 23 | +-------------------------- |
22 | 24 |
|
23 |
| -Usage of API to fetch HTTP/S and FTP URLs |
24 |
| -######################################### |
| 25 | +Clone the repo:: |
25 | 26 |
|
26 |
| -.. code-block:: python |
| 27 | + git clone https://github.com/nexB/fetchcode |
27 | 28 |
|
28 |
| - from fetchcode import fetch |
29 |
| - url = 'A Http or FTP URL' |
30 |
| - # This returns a response object which has attributes |
31 |
| - # 'content_type' content type of the file |
32 |
| - # 'location' the absolute location of the files that was fetched |
33 |
| - # 'scheme' scheme of the URL |
34 |
| - # 'size' size of the retrieved content in bytes |
35 |
| - # 'url' fetched URL |
36 |
| - resp = fetch(url = url) |
| 29 | +Then install all the requirements using:: |
| 30 | + |
| 31 | + configure --dev |
| 32 | + |
| 33 | + |
| 34 | +Running tests |
| 35 | +---------------- |
| 36 | + |
| 37 | +To run test suite use:: |
| 38 | + |
| 39 | + pytest -vvs |
| 40 | + |
| 41 | + |
| 42 | +Usage |
| 43 | +-------- |
| 44 | + |
| 45 | +Fetch a code archive and get a ``fetchcode.fetch.Reposnse`` object back:: |
| 46 | + |
| 47 | + >>> from fetchcode import fetch |
| 48 | + >>> f = fetch('https://github.com/nexB/fetchcode/archive/ab65b2e645c889887227ea49eb3332d885fd0a54.zip') |
| 49 | + >>> f.location |
| 50 | + '/tmp/tmp_cm02xsg' |
| 51 | + >>> f.content_type |
| 52 | + 'application/zip' |
| 53 | + >>> f.url |
| 54 | + 'https://github.com/nexB/fetchcode/archive/ab65b2e645c889887227ea49eb3332d885fd0a54.zip' |
| 55 | + |
| 56 | +Fetch some package metadata and get a ``fetchcode.packagedcode_models.Package`` object back:: |
| 57 | + |
| 58 | + >>> from fetchcode import package |
| 59 | + >>> list(package.info('pkg:rubygems/files')) |
| 60 | + [Package(type='rubygems', namespace=None, name='files', version=None)] |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +License |
| 65 | +-------- |
| 66 | + |
| 67 | +- SPDX-License-Identifier: Apache-2.0 |
| 68 | + |
| 69 | +Copyright (c) nexB Inc. and others. |
0 commit comments