Difference between revisions of "Contribute code"

From Archivematica
Jump to navigation Jump to search
(→‎Code Style Guide For Archivematica: Update to reference external guidelines mostly)
Line 20: Line 20:
 
** Imports are sorted alphabetically within their grouping to reduce duplicate imports
 
** Imports are sorted alphabetically within their grouping to reduce duplicate imports
 
* [https://www.python.org/dev/peps/pep-0257/ PEP257] for docstring structure
 
* [https://www.python.org/dev/peps/pep-0257/ PEP257] for docstring structure
** Parameters and return values should be specified in Sphinx-style.
+
** Parameters and return values should be specified in [http://sphinx-doc.org/domains.html#info-field-lists Sphinx-style].
  
 
We encourage installing a Python linter to help with this. [https://pypi.python.org/pypi/flake8 flake8] is recommended because it wraps three common linters (pep8, pyflakes, mccabe).
 
We encourage installing a Python linter to help with this. [https://pypi.python.org/pypi/flake8 flake8] is recommended because it wraps three common linters (pep8, pyflakes, mccabe).
  
 
* Install instructions for [https://github.com/SublimeLinter/SublimeLinter-flake8 SublimeLinter-flake8]
 
* Install instructions for [https://github.com/SublimeLinter/SublimeLinter-flake8 SublimeLinter-flake8]
 +
 +
Example docstrings with Sphinx markup below. Other attributes that can be used in a docstring can be found [http://sphinx-doc.org/domains.html#the-python-domain on the Sphinx website].
 +
 +
<pre>def get_unit_status(unit_uuid, unit_type):
 +
    """
 +
    Get status for a SIP or Transfer.
 +
 +
    Returns a dict with status info.  Keys will always include 'status' and
 +
    'microservice', and may include 'sip_uuid'.
 +
 +
    Status is one of FAILED, REJECTED, USER_INPUT, COMPLETE or PROCESSING.
 +
    Microservice is the name of the current microservice.
 +
    SIP UUID is populated only if the unit_type was unitTransfer and status is
 +
    COMPLETE.  Otherwise, it is None.
 +
 +
    :param str unit_uuid: UUID of the SIP or Transfer
 +
    :param str unit_type: unitSIP or unitTransfer
 +
    :return: Dict with status info.
 +
    """</pre>
 +
 +
<pre>def each_child(path, file_group_identifier, base_path, base_path_name, sip_uuid):
 +
    """
 +
    Iterates over entries in a filesystem, beginning at `path`.
 +
 +
    At each entry in the filesystem, yields either a File model instance
 +
    (for files) or a string (for directories).
 +
 +
    When iterating, makes two passes: first iterating over files, then
 +
    directories. Does not iterate over directories; consumers should
 +
    call this function again on directory strings to recurse.
 +
 +
    :param string path: path to a directory on disk to recurse into.
 +
    :raises ValueError: if the specified path does not exist, or is not a directory.
 +
    """
 +
</pre>
  
 
=== File Structure ===
 
=== File Structure ===

Revision as of 15:07, 11 August 2015

Main Page > Development > Contribute code


Patches

If you find a bug in this project or would like to make an enhancement, please be encouraged to contribute a patch by following these instructions.

Commit access

Anyone can contribute code patches to this project. Project collaborators and regular patch contributors will be given access to commit directly to the git code repository.

Contributor's Agreement

In order to accept any patches or code commits, contributors must first sign the Archivematica Contributor's Agreement.

Standards

Code Style Guide For Archivematica

Archivematica follows common Python coding standards, notably

  • PEP8 for styling
    • Exception is line length, which should be wrapped at 79 characters or left long for the IDE to wrap.
    • Imports are sorted alphabetically within their grouping to reduce duplicate imports
  • PEP257 for docstring structure
    • Parameters and return values should be specified in Sphinx-style.

We encourage installing a Python linter to help with this. flake8 is recommended because it wraps three common linters (pep8, pyflakes, mccabe).

Example docstrings with Sphinx markup below. Other attributes that can be used in a docstring can be found on the Sphinx website.

def get_unit_status(unit_uuid, unit_type):
    """
    Get status for a SIP or Transfer.

    Returns a dict with status info.  Keys will always include 'status' and
    'microservice', and may include 'sip_uuid'.

    Status is one of FAILED, REJECTED, USER_INPUT, COMPLETE or PROCESSING.
    Microservice is the name of the current microservice.
    SIP UUID is populated only if the unit_type was unitTransfer and status is
    COMPLETE.  Otherwise, it is None.

    :param str unit_uuid: UUID of the SIP or Transfer
    :param str unit_type: unitSIP or unitTransfer
    :return: Dict with status info.
    """
def each_child(path, file_group_identifier, base_path, base_path_name, sip_uuid):
    """
    Iterates over entries in a filesystem, beginning at `path`.

    At each entry in the filesystem, yields either a File model instance
    (for files) or a string (for directories).

    When iterating, makes two passes: first iterating over files, then
    directories. Does not iterate over directories; consumers should
    call this function again on directory strings to recurse.

    :param string path: path to a directory on disk to recurse into.
    :raises ValueError: if the specified path does not exist, or is not a directory.
    """

File Structure

The file structure in Archivematica will comply with the Filesystem Hierarchy Standard (FHS).
More information on this standard is available at:
http://www.pathname.com/fhs/