Skip to content

Commit

Permalink
Wrote some chapters of documentation, fixed some isort and flake8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
marazmiki committed Feb 13, 2019
1 parent b75eac2 commit 0d72248
Show file tree
Hide file tree
Showing 11 changed files with 431 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -30,6 +30,7 @@ install:
- pip install -e .

script:
- tox -- --cov=. --cov-branch --cov-append
- tox -- --isort --flake8 --cov=. --cov-branch --cov-append

after_success:
- coveralls
4 changes: 0 additions & 4 deletions README.rst
Expand Up @@ -26,10 +26,6 @@ django-selectel-storage

This application allows you easily save media and static files into Selectel cloud storage.

Dependencies
------------

* `requests <http://docs.python-requests.org/en/latest/>`_ library

Installation
------------
Expand Down
19 changes: 19 additions & 0 deletions docs/Makefile
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
43 changes: 32 additions & 11 deletions docs/source/changelog.rst
@@ -1,6 +1,12 @@
1.0
Changelog
=========

1.x
---

1.0
~~~

* Added support for Python 3.6x and 3.7;
* Dropped support for older Django versions (the oldest one we supporting is 1.10)
* Using ``tox`` and ``pytest`` utilities when developing
Expand All @@ -9,33 +15,48 @@
* License is MIT



0.3x
----

0.3.1
-----
~~~~~

Released at 2016-03-13

* Fix static storage settings

0.3
---
0.3.0
~~~~~

Released at 2016-02-07

* Drop older python verions support (vv 3.2, 3.3)
* Drop older Django version support (1.6)
* Use tox for testing


0.2x
----

0.2.2
-----
~~~~~

2015-05-23

* Update django head versions

0.2.1
-----
~~~~~

2015-05-02

* Update head django version


0.2
---
0.2.0
~~~~~

2015-04-04

* Added CHANGELOG :)
* Updated head Django versions (add 1.8x support)
* Wheel support
* 5ac502a 2014-10-03 | init? [Mikhail Porokhovnichenko]
112 changes: 112 additions & 0 deletions docs/source/conf.py
@@ -0,0 +1,112 @@
# flake8: noqa

import sys

sys.path.insert(0, '../..')

from django_selectel_storage import __version__ # isort:skip noqa: E731

project = 'django-selectel-storage'
copyright = '2018, Mikhail Porokhovnichenko'
author = 'Mikhail Porokhovnichenko'

# The short X.Y version
version = __version__

release = __version__


# -- General configuration ---------------------------------------------------

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
]

templates_path = ['_templates']

source_suffix = '.rst'

master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'django-selectel-storagedoc'


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc,
'django-selectel-storage',
'django-selectel-storage Documentation',
[author], 1)
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']

# -- Extension configuration -------------------------------------------------
108 changes: 108 additions & 0 deletions docs/source/configuration.rst
@@ -0,0 +1,108 @@
Configuration
=============

Here, we assume you already:

* `Have registered <https://kb.selectel.com/22063010.html>`_ an account on Selectel,
* `Spent some money <https://kb.selectel.com/27821850.html>`_ there,
* `Created a couple of containers <https://kb.selectel.com/23137040.html#BasicOverview-CreatingandConfiguringContainers>`_ and got credentials for it.

if you haven't yet, consider doing that right now.


A minimal installation
----------------------

To begin using Selectel storage as your storage, you should configure
your containers credentials:

.. code:: python
SELECTEL_STORAGES = {
'default': {
'USERNAME': 'xxxx_user',
'PASSWORD': 'p455w0rd',
'CONTAINER': 'my-data',
},
'yet_another_storage': 'selectel://xxxx_user:p455w0rd2@another-container',
}
As you already guessed, the dictionary means you can create as much configurations
as you want. Here, we have two schemas: ``default`` and ``yet_another_storage``.


**You're free to use any names for schema but strongly recommended to declare
a schema with name ``default``.**

Also, as you already guessed again, you can specify credentials either:

* As a dictionary with ``USERNAME``, ``PASSWORD`` or ``CONTAINER`` keys, or
* a URL-like string with schema ``selectel://``

Please see all available configuration options below.

.. attention::
Credentials in examples above are hardcoded. It really sucks, don't
do that in real life. Instead, you can store these variables in the
environment and extract it out of there, for example, via awesome
`python-decouple <https://pypi.org/project/python-decople/>`_ package.


Using django-selectel-storage as a default backend
--------------------------------------------------

If you want to use the storage by default, consider adding to your ``settings.py``:

.. code:: python
DEFAULT_FILE_STORAGE = 'django_selectel_storage.storage.SelectelStorage'
in this case, the ``default`` schema will be implicitly used. Please make sure
you defined it before.


Storage initialization
----------------------

If you want to explicitly instantiate a storage, you should write something like that:

.. code:: python
# models.py
from django.db import models
class Post(models.Model):
photo = models.ImageField(storage=storage_instance)
Wondering, what ``storage_instance`` is? Well, it would be one of:

.. code:: python
from django_selectel_storage.storage import SelectelStorage
storage_instance = SelectelStorage()
storage_instance = SelectelStorage('default')
storage_instance = SelectelStorage(storage='default')
Please pay attention: the last three lines of code do the same thing: creates
a ``SelectelStorage`` instance with using ``default`` schema. Of course, you
can choose any different schema (if you've defined it of course):

.. code:: python
storage_instance = SelectelStorage('yet_another_storage')
storage_instance = SelectelStorage(storage='yet_another_storage')
We even create an instance via DSN (it's useful somewhere in ``./manage.py shell``, please don't do that in production):

.. code:: python
storage_instance = SelectelStorage('selectel://user:password@container_name/')
storage_instance = SelectelStorage(storage='selectel://user:password@container_name/')
An interesting gotcha here: if you specify a DSN (a string begins with ``selectel://``) as a first positional argument, it would
act like a dsn rather as ``storage=``



22 changes: 22 additions & 0 deletions docs/source/index.rst
@@ -0,0 +1,22 @@
..
django-selectel-storage
#######################

.. toctree::
:maxdepth: 2
:caption: Contents:

introduction
install
usage
configuration
changelog


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

0 comments on commit 0d72248

Please sign in to comment.