Skip to content

Commit 9f9ab81

Browse files
committed
docs
1 parent e1e4717 commit 9f9ab81

File tree

7 files changed

+313
-7
lines changed

7 files changed

+313
-7
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ wheels/
2525
.installed.cfg
2626
*.egg
2727
.DS_Store
28+
_build/
2829

2930
# PyInstaller
3031
# Usually these files are written by a python script from a template

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = python -msphinx
7+
SPHINXPROJ = S3FS
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/conf.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# S3FS documentation build configuration file, created by
4+
# sphinx-quickstart on Sat Aug 5 12:55:45 2017.
5+
#
6+
# This file is execfile()d with the current directory set to its
7+
# containing dir.
8+
#
9+
# Note that not all possible configuration values are present in this
10+
# autogenerated file.
11+
#
12+
# All configuration values have a default; values that are commented out
13+
# serve to show the default.
14+
15+
# If extensions (or modules to document with autodoc) are in another directory,
16+
# add these directories to sys.path here. If the directory is relative to the
17+
# documentation root, use os.path.abspath to make it absolute, like shown here.
18+
#
19+
# import os
20+
# import sys
21+
# sys.path.insert(0, os.path.abspath('.'))
22+
23+
24+
import fs_s3fs
25+
26+
# -- General configuration ------------------------------------------------
27+
28+
# If your documentation needs a minimal Sphinx version, state it here.
29+
#
30+
# needs_sphinx = '1.0'
31+
32+
# Add any Sphinx extension module names here, as strings. They can be
33+
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
34+
# ones.
35+
extensions = ['sphinx.ext.autodoc']
36+
37+
# Add any paths that contain templates here, relative to this directory.
38+
templates_path = ['_templates']
39+
40+
# The suffix(es) of source filenames.
41+
# You can specify multiple suffix as a list of string:
42+
#
43+
# source_suffix = ['.rst', '.md']
44+
source_suffix = '.rst'
45+
46+
# The master toctree document.
47+
master_doc = 'index'
48+
49+
# General information about the project.
50+
project = u'S3FS'
51+
copyright = u'2017, Will McGugan'
52+
author = u'Will McGugan'
53+
54+
# The version info for the project you're documenting, acts as replacement for
55+
# |version| and |release|, also used in various other places throughout the
56+
# built documents.
57+
#
58+
# The short X.Y version.
59+
version = fs_s3fs.__version__
60+
# The full version, including alpha/beta/rc tags.
61+
release = fs_s3fs.__version__
62+
63+
# The language for content autogenerated by Sphinx. Refer to documentation
64+
# for a list of supported languages.
65+
#
66+
# This is also used if you do content translation via gettext catalogs.
67+
# Usually you set "language" from the command line for these cases.
68+
language = None
69+
70+
# List of patterns, relative to source directory, that match files and
71+
# directories to ignore when looking for source files.
72+
# This patterns also effect to html_static_path and html_extra_path
73+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
74+
75+
# The name of the Pygments (syntax highlighting) style to use.
76+
pygments_style = 'sphinx'
77+
78+
# If true, `todo` and `todoList` produce output, else they produce nothing.
79+
todo_include_todos = False
80+
81+
82+
# -- Options for HTML output ----------------------------------------------
83+
84+
# The theme to use for HTML and HTML Help pages. See the documentation for
85+
# a list of builtin themes.
86+
#
87+
html_theme = 'alabaster'
88+
89+
# Theme options are theme-specific and customize the look and feel of a theme
90+
# further. For a list of options available for each theme, see the
91+
# documentation.
92+
#
93+
# html_theme_options = {}
94+
95+
# Add any paths that contain custom static files (such as style sheets) here,
96+
# relative to this directory. They are copied after the builtin static files,
97+
# so a file named "default.css" will overwrite the builtin "default.css".
98+
html_static_path = ['_static']
99+
100+
101+
# -- Options for HTMLHelp output ------------------------------------------
102+
103+
# Output file base name for HTML help builder.
104+
htmlhelp_basename = 'S3FSdoc'
105+
106+
107+
# -- Options for LaTeX output ---------------------------------------------
108+
109+
latex_elements = {
110+
# The paper size ('letterpaper' or 'a4paper').
111+
#
112+
# 'papersize': 'letterpaper',
113+
114+
# The font size ('10pt', '11pt' or '12pt').
115+
#
116+
# 'pointsize': '10pt',
117+
118+
# Additional stuff for the LaTeX preamble.
119+
#
120+
# 'preamble': '',
121+
122+
# Latex figure (float) alignment
123+
#
124+
# 'figure_align': 'htbp',
125+
}
126+
127+
# Grouping the document tree into LaTeX files. List of tuples
128+
# (source start file, target name, title,
129+
# author, documentclass [howto, manual, or own class]).
130+
latex_documents = [
131+
(master_doc, 'S3FS.tex', u'S3FS Documentation',
132+
u'Will McGugan', 'manual'),
133+
]
134+
135+
136+
# -- Options for manual page output ---------------------------------------
137+
138+
# One entry per manual page. List of tuples
139+
# (source start file, name, description, authors, manual section).
140+
man_pages = [
141+
(master_doc, 's3fs', u'S3FS Documentation',
142+
[author], 1)
143+
]
144+
145+
146+
# -- Options for Texinfo output -------------------------------------------
147+
148+
# Grouping the document tree into Texinfo files. List of tuples
149+
# (source start file, target name, title, author,
150+
# dir menu entry, description, category)
151+
texinfo_documents = [
152+
(master_doc, 'S3FS', u'S3FS Documentation',
153+
author, 'S3FS', 'One line description of project.',
154+
'Miscellaneous'),
155+
]
156+
157+
158+

docs/index.rst

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
.. S3FS documentation master file, created by
2+
sphinx-quickstart on Sat Aug 5 12:55:45 2017.
3+
You can adapt this file completely to your liking, but it should at least
4+
contain the root `toctree` directive.
5+
6+
S3FS
7+
====
8+
9+
S3FS is a `PyFilesystem interface
10+
<https://docs.pyfilesystem.org/en/latest/reference/base.html>`_ to
11+
Amazon S3 cloud storage.
12+
13+
As a PyFilesystem concrete class, S3FS allows you to work with S3 in the
14+
same as any other supported filesystem.
15+
16+
17+
Installing
18+
==========
19+
20+
S3FS may be installed from pip with the following command::
21+
22+
pip install fs-s3fs
23+
24+
This will install the most recent stable version.
25+
26+
Alternatively, if you want the cutting edge code, you can check out
27+
the GitHub repos at https://github.com/pyfilesystem/s3fs
28+
29+
30+
Opening an S3 Filesystem
31+
========================
32+
33+
There are two options for constructing a :ref:`s3fs` instance. The simplest way
34+
is with an *opener*, which is a simple URL like syntax. Here is an example::
35+
36+
from fs import open_fs
37+
s3fs = S3FS('s3://mybucket/')
38+
39+
For more granular control, you may import the S3FS class and construct
40+
it explicitly::
41+
42+
from fs_s3fs import S3FS
43+
s3fs = S3FS('mybucket')
44+
45+
46+
Authentication
47+
==============
48+
49+
If you don't supply any credentials, then S3FS will use the access key
50+
and secret key configured on your system. You may also specify when
51+
creating the filesystem instance. Here's how you would do that with an
52+
opener::
53+
54+
s3fs = open_fs('s3://<access key>:<secret key>/mybucket')
55+
56+
Here's how you specify credentials with the constructor::
57+
58+
s3fs = S3FS(
59+
'mybucket'
60+
aws_access_key_id=<access key>,
61+
aws_secret_access_key=<secret key>
62+
)
63+
64+
.. note::
65+
66+
Amazon recommends against specifying credentials explicitly like
67+
this in production.
68+
69+
70+
S3 Info
71+
=======
72+
73+
You can retrieve S3 info via the ``s3`` namespace. Here's an example:
74+
75+
>>> info = s.getinfo(u'foo', namespaces=['s3'])
76+
>>> info.raw['s3']
77+
{u'content_length': 3, u'restore': None, u'sse_customer_key_md5': None, u'content_language': None, u'replication_status': None, u'server_side_encryption': None, u'parts_count': None, u'sse_customer_algorithm': None, u'missing_meta': None, u'delete_marker': None, u'content_encoding': None, u'accept_ranges': 'bytes', u'cache_control': None, u'metadata': {}, u'request_charged': None, u'e_tag': '"37b51d194a7513e45b56f6524f2d51f2"', u'expires': None, u'version_id': None, u'last_modified': 1501935315, u'content_type': 'binary/octet-stream', u'website_redirect_location': None, u'ssekms_key_id': None, u'content_disposition': None, u'storage_class': None, u'expiration': None}
78+
79+
80+
URLs
81+
====
82+
83+
You can use the ``geturl`` method to generate an externally accessible
84+
URL from an S3 object. Here's an example:
85+
86+
>>> s3fs.geturl('foo')
87+
'https://fsexample.s3.amazonaws.com//foo?AWSAccessKeyId=AKIAIEZZDQU72WQP3JUA&Expires=1501939084&Signature=4rfDuqVgmvILjtTeYOJvyIXRMvs%3D'
88+
89+
.. toctree::
90+
:maxdepth: 2
91+
:caption: Contents:
92+
93+
s3fs.rst
94+
95+
96+
More Information
97+
================
98+
99+
See the `PyFilesystem Docs <https://docs.pyfilesystem.org>`_ for full
100+
details.
101+
102+
103+
Indices and tables
104+
==================
105+
106+
* :ref:`genindex`
107+
* :ref:`modindex`
108+
* :ref:`search`

docs/s3fs.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. _s3fs:
2+
3+
S3FS
4+
====
5+
6+
Construct a `PyFilesystem interface <https://docs.pyfilesystem.org/en/latest/reference/base.html>`_ to an Amazon S3 'bucket'.
7+
8+
Here's a silly example::
9+
10+
from fs_s3fs import S3FS
11+
s3fs = S3FS('mybucket')
12+
with s3fs.open('foo.txt', 'wt') as fh:
13+
fh.write('Writing a file to the cloud!')
14+
print(s3fs.listdir(u'/'))
15+
16+
17+
S3FS Constructor
18+
----------------
19+
20+
.. autoclass:: fs_s3fs.S3FS
21+
:members:

fs_s3fs/_s3fs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ def __repr__(self):
5656

5757

5858
class S3File(io.IOBase):
59+
"""Proxy for a S3 file."""
5960

6061
@classmethod
6162
def factory(cls, filename, mode, on_close):
63+
"""Create a S3File backed with a temporary file."""
6264
_temp_file = tempfile.TemporaryFile()
6365
proxy = cls(_temp_file, filename, mode, on_close=on_close)
6466
return proxy
@@ -193,7 +195,7 @@ def s3errors(path):
193195
@six.python_2_unicode_compatible
194196
class S3FS(FS):
195197
"""
196-
An Amazon S3 filesystem for
198+
Construct an Amazon S3 filesystem for
197199
`PyFilesystem <https://pyfilesystem.org>`_
198200
199201
:param str bucket_name: The S3 bucket name.
@@ -465,6 +467,7 @@ def openbin(self, path, mode="r", buffering=-1, **options):
465467
_key = self._path_to_key(_path)
466468

467469
if _mode.create:
470+
468471
def on_close(s3file):
469472
try:
470473
s3file.raw.seek(0)
@@ -589,7 +592,7 @@ def exists(self, path):
589592
return True
590593
_key = self._path_to_dir_key(_path)
591594
try:
592-
obj = self._get_object(path, _key)
595+
self._get_object(path, _key)
593596
except errors.ResourceNotFound:
594597
return False
595598
else:

fs_s3fs/opener.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,4 @@ def open_fs(self, fs_url, parse_result, writeable, create, cwd):
2828
aws_access_key_id=parse_result.username or None,
2929
aws_secret_access_key=parse_result.password or None,
3030
)
31-
s3fs = (
32-
s3fs.opendir(dir_path, factory=ClosingSubFS)
33-
if dir_path else
34-
s3fs
35-
)
3631
return s3fs

0 commit comments

Comments
 (0)