![Magency Logo](http://magencydigital.com/wp-content/themes/magency/library/images/logo-magency.png "Magency")

# MHR Server

## Getting Started
- Clone the project: `git clone git@github.com:magencydigital/mhr.git && cd mhr`
- Setup the virtualenv:

	```sh
	mkvirtualenv mtp --python=`which python3.4`
	# or with pyenv (https://github.com/pyenv/pyenv-virtualenvwrapper)
	pyenv install << cat .python-version
	mkvirtualenv mtp --python=`pyenv which python`
	# add ENVs
	echo "source '`pwd`/conf/local_env.sh'" >> $VIRTUAL_ENV/bin/postactivate
	# add mtp path to python path
	echo "`pwd`/mtp" > $VIRTUAL_ENV/lib/python3.4/site-packages/mtp.pth
	# reload
	workon mhr
	```

- Install the requirements: `pip install -r requirements/dev.txt`
- Create the postgreSQL database: `createdb mtp`
- Run the migrations: `django-admin migrate`
- Create or update the fixtures: `django-admin create_or_update_fixtures`
- Run the dev server: `django-admin runserver`

### Prerequisities
- [python 3.4](https://www.python.org/download/releases/3.4.0/)
- [PostgreSQL 9.3](https://www.postgresql.org/download/)
- [virtalenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/)

### Running the tests

#### Unit test
We use [py.test](http://doc.pytest.org/en/latest/) to run our tests.
You can run the tests by typing `py.test mtp`
- To create a new test database: `py.test mtp --create-db`
- To create a new test database and skip the migrations: `TESTS_SKIP_MIGRATIONS="True" py.test mtp --create-db`

#### Linter
We use [Pylint](https://www.pylint.org/)
You can run pylint by typing `pylint mtp`

### Contributing

Please follow the following **coding conventions** as much as possible:
- [PEP8](https://www.python.org/dev/peps/pep-0008/)
- [Docstrings](http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html)
- [Imports](https://github.com/magencydigital/mhr/wiki/Imports-Guidelines)

#### Pull requests
We use [git-flow](http://nvie.com/posts/a-successful-git-branching-model/) as our branching model.
Please write [good commit message](http://chris.beams.io/posts/git-commit/)
Additionally, you must prefix your commits/PR title with theses tags, accordingly to your commit/PR content:
- [+MIGR]: Your PR/commit contains one or multiple database migrations
- [+REQ]: Your PR/commit contains one or multiple requirements changes
- [+i18n]: Your PR/commit contains one or multiple string to translate

#### Continuous integration
[Jenkins url](http://jenkins.magency.fr/)
[Jenkins mtp scripts documentation](https://github.com/magencydigital/mhr/blob/develop/ci/jenkins/README.md)

### Versioning
We use [SemVer](http://semver.org/) for versioning.

#### Creating a new release
- Update the `master` and `develop` branches: `git pull`
- Start the release: `git-flow release start <release_name>`
- Update the version of the mtp app in the `mtp/__init__.py` file
- Commit this file and make some others commits (last minutes fixes) if necessary
- Finish the release: `git-flow release finish <release_name>`
- When git-flow will be asking for a tag for this release, please use this pattern: `<release_name>: short-resume-on-one-line + empty_line + details`
- `git checkout master && git pull origin master && git push --tags && git checkout develop && git push origin develop`

Note: instead of doing `git push --tags`, that will always push all tags, you can do `git push origin <release_name>` (with release tag the exact tag to push)

#### Publishing a new release
- `python setup.py sdist && upload_release.sh <release_name>`
