Documenting...

This commit is contained in:
Julien Palard 2017-04-25 23:17:19 +02:00
parent 23e86d3355
commit 43923ab4d8
7 changed files with 152 additions and 99 deletions

53
CONTRIBUTING.rst Normal file
View File

@ -0,0 +1,53 @@
.. highlight:: shell
============
Contributing
============
Contributions are welcome, and they are greatly appreciated! Every
little bit helps, and credit will always be given.
How to add a mis-detected license
---------------------------------
Known licenses are stored in
``src/licensename/known_licenses.py``. The structure is aimed to be
understandable by humans: it's a simple dict, each level of the dict
correspond to an unwrapped paragraph in the license, like::
"APPLE PUBLIC SOURCE LICENSE": {
"Version 1.0 - March 16, 1999": "APSL-1.0",
"Version 1.1 - April 19,1999": "APSL-1.1",
"Version 2.0 - August 6, 2003": "APSL-2.0"
},
"Academic Free License": {
"Version 1.1": "AFL-1.1",
"Version 1.2": "AFL-1.2"
}
reads like: If first paragraph one is "APPLE PUBLIC SOURCE LICENSE",
and the second paragraph is "Version 1.0 - March 16, 1999", it's an
"APSL-1.0" license.
In other worlds, first dict is for paragraph one, second level of dicts are
for paragraph two, etc… until as string is found instead of a dict, meaning
there's no longer need for disambiguation, and it's the license name.
Lines containing ``(c)``, ``(C)``, empty lines, or starting with
``Copyright`` are removed before paragraph parsing.
You can easily see how ``licensename`` sees paragraphs of a license
file by trying the ``--pretty-print`` option::
$ licensename --pretty-print tests/licenses/MIT~1.txt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
If your paragraphs are incorrectly parsed, you can fix it in the
`textunwrap
<https://textunwrap.readthedocs.io/en/latest/index.html>`__ project.

View File

@ -2,60 +2,18 @@
licensename
===========
Module or script to find a license name from a license text or file.
.. image:: https://img.shields.io/pypi/v/licensename.svg
:target: https://pypi.python.org/pypi/licensename
.. image:: https://img.shields.io/travis/JulienPalard/licensename.svg
:target: https://travis-ci.org/JulienPalard/licensename
.. image:: https://readthedocs.org/projects/licensename/badge/?version=latest
:target: https://licensename.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
Usage
=====
Module and script to find a license name from a license text or file.
This can be used as a script::
$ licensename tests/licenses/MIT.txt
MIT
$ licensename tests/licenses/BSD-2-Clause.txt
BSD-2-Clause
Or as a module::
>>> import licensename
>>> licensename.from_file('./tests/licenses/MIT.txt')
'MIT'
>>> licensename.from_file('./tests/licenses/BSD-2-Clause.txt')
'BSD-2-Clause'
>>> licensename.from_text("MIT License\nyadi yadi yada…")
'MIT'
Adding a license
================
Known licenses are stored in
``src/licensename/known_licenses.py``. The structure is aimed to be
understandable by humans: it's a simple dict, each level of the dict
correspond to a line in the license, like::
"The LaTeX Project Public License": {
"=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-": {
"LPPL Version 1.1 1999-07-10": "LPPL-1.1",
"LPPL Version 1.2 1999-09-03": "LPPL-1.2",
"LPPL Version 1.3a 2004-10-01": "LPPL-1.3a",
"LPPL Version 1.3c 2008-05-04": "LPPL-1.3c"
}
}
reads like: If line one is "The LaTeX Project Public License", and the
line two is "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-", and the line three is
"LPPL Version 1.1 1999-07-10", it's an "LPPL-1.1", and so on.
In other worlds, first dict is for line one, second level of dicts are
for line two, etc… until as string is found instead of a dict, meaning
there's no longer need for disambiguation, and it's the license name.
Lines containing ``(c)``, ``(C)``, empty lines, or starting with
``Copyright`` are ignored.
Note
====
This project has been set up using PyScaffold 2.5.7. For details and usage
information on PyScaffold see http://pyscaffold.readthedocs.org/.
* Documentation: https://licensename.readthedocs.io.

1
docs/contributing.rst Normal file
View File

@ -0,0 +1 @@
.. include:: ../CONTRIBUTING.rst

View File

@ -1,53 +1,16 @@
===========
licensename
===========
Welcome to the licensename's documentation!
===========================================
This is the documentation of **licensename**.
.. note::
This is the main page of your project's `Sphinx <http://sphinx-doc.org/>`_
documentation. It is formatted in `reStructuredText
<http://sphinx-doc.org/rest.html>`__. Add additional pages by creating
rst-files in ``docs`` and adding them to the `toctree
<http://sphinx-doc.org/markup/toctree.html>`_ below. Use then
`references <http://sphinx-doc.org/markup/inline.html>`__ in order to link
them from this page, e.g. :ref:`authors <authors>` and :ref:`changes`.
It is also possible to refer to the documentation of other Python packages
with the `Python domain syntax
<http://sphinx-doc.org/domains.html#the-python-domain>`__. By default you
can reference the documentation of `Sphinx <http://sphinx.pocoo.org>`__,
`Python <http://docs.python.org/>`__, `NumPy
<http://docs.scipy.org/doc/numpy>`__, `SciPy
<http://docs.scipy.org/doc/scipy/reference/>`__, `matplotlib
<http://matplotlib.sourceforge.net>`__, `Pandas
<http://pandas.pydata.org/pandas-docs/stable>`__, `Scikit-Learn
<http://scikit-learn.org/stable>`__. You can add more by
extending the ``intersphinx_mapping`` in your Sphinx's ``conf.py``.
The pretty useful extension `autodoc
<http://www.sphinx-doc.org/en/stable/ext/autodoc.html>`__ is activated by
default and lets you include documentation from docstrings. Docstrings can
be written in `Google
<http://google.github.io/styleguide/pyguide.html#Comments>`__
(recommended!), `NumPy
<https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt>`__
and `classical
<http://www.sphinx-doc.org/en/stable/domains.html#info-field-lists>`__
style.
Contents
========
Contents:
.. toctree::
:maxdepth: 2
License <license>
Authors <authors>
Changelog <changes>
Module Reference <api/modules>
readme
installation
usage
contributing
authors
Indices and tables

52
docs/installation.rst Normal file
View File

@ -0,0 +1,52 @@
.. highlight:: shell
============
Installation
============
Stable release
--------------
To install licensename, run this command in your terminal:
.. code-block:: console
$ python3 -m pip install licensename
This is the preferred method to install licensename, as it will always
install the most recent stable release.
If you don't have `pip`_ installed, this `Python installation guide`_ can guide
you through the process.
.. _pip: https://pip.pypa.io
.. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/
From sources
------------
The sources for licensename can be downloaded from the `Github repo`_.
You can either clone the public repository:
.. code-block:: console
$ git clone git://github.com/JulienPalard/licensename
Or download the `tarball`_:
.. code-block:: console
$ curl -OL https://github.com/JulienPalard/licensename/tarball/master
Once you have a copy of the source, you can install it with:
.. code-block:: console
$ python3 setup.py install
.. _Github repo: https://github.com/JulienPalard/licensename
.. _tarball: https://github.com/JulienPalard/licensename/tarball/master

1
docs/readme.rst Normal file
View File

@ -0,0 +1 @@
.. include:: ../README.rst

25
docs/usage.rst Normal file
View File

@ -0,0 +1,25 @@
=====
Usage
=====
To find the license name of a license file, this package can be used
as a script:
.. code-block:: shell-session
$ licensename tests/licenses/MIT.txt
MIT
$ licensename tests/licenses/BSD-2-Clause.txt
BSD-2-Clause
Or as a module::
.. code-block:: pycon
>>> import licensename
>>> licensename.from_file('./tests/licenses/MIT.txt')
'MIT'
>>> licensename.from_file('./tests/licenses/BSD-2-Clause.txt')
'BSD-2-Clause'
>>> licensename.from_text("MIT License\nyadi yadi yada…")
'MIT'