This document provides instructions for setting up pepys-import for development, along with contributers guidance on code style, testing and so on.
To prepare for running ensure Python 3.6 or later is installed on your system. You can check your Python 3 version with the following command:
$ python --version
Note: Depending on the set up on your computer, you may need to run python3
or python3.7
rather
than python
in this and all following commands.
If you don't have Python 3.6+ in your system, please download it from python.org
Pip is also necessary to install dependencies. If you don't have it in your system, please download it:
$ sudo apt-get install python3-pip
It is possible to verify pip installation with the following command:
$ pip --version
Note: Depending on the set up on your computer, you may need to run pip3
rather than pip
in
this and all following commands. Alternatively, you can run python -m pip
.
Once Python and pip are installed, follow the relevant instructions below for your platform:
Open a terminal and run the following command:
$ sudo apt install spatialite-bin $ sudo apt-get install -y libsqlite3-mod-spatialite
On Debian-based distributions the following libraries are necessary to run SpatiaLite:
$ sudo apt install zlib1g-dev libfreexl1 $ sudo apt-get install sqlite3 libsqlite3-dev $ sudo apt-get install -y libsqlite3-mod-spatialite $ sudo apt-get install binutils libproj-dev gdal-bin libgeos-dev libxml2-dev
After all libraries are installed, it is necessary to download and run the latest SpatiaLite version:
$ wget https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-X.Y.Z.tar.gz $ tar xaf libspatialite-X.Y.Z.tar.gz $ cd libspatialite-X.Y.Z $ ./configure $ make $ sudo make install
The best way to install PostGIS is running the codes as follows:
sudo apt-get install libpq-dev python-dev sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable sudo apt-get update sudo apt-get install postgis
Run the following command:
$ sudo apt install git
The easiest way to get the relevant libraries working on a M1 MacOS machine is to use the conda Python package manager which will install from the packages provided by conda-forge. This is different to the standard pip/virtualenv process, but works quite nicely alongside it. The conda package manager can be quite slow, so the instructions show how to install mamba instead, which is a faster fork.
These instructions are for Macs with a M1 (ARM) processor. A similar approach will work for x86 (Intel) Macs, but you will need to ensure that you install the Intel version of miniconda.
- Install Postgres.app, available from here, which is a self-contained installation of Postgres and PostGIS for MacOS.
- Once installed, add the Postgres bin directory to the PATH variable in your proefile. The bin directory will be _inside_ the Postgres.app file you've just installed, and the path will be something
like
/Applications/Postgres.app/Contents/Versions/14/bin
. - Install the ARM version of mambaforge, which is available here, following
- all the instructions to the end (including setting up integration with your shell)
- Create a new environment (like conda's equivalent of a virtualenv) by running:
mamba create -n pepys python=3.9 libspatialite psycopg2
. This will install Python 3.9 and libspatialite in a new environment calledpepys
. - Activate the environment by running
mamba activate pepys
- Install the other Pepys dependencies by running
pip install -r requirements.txt -r requirements_dev.txt
- Install the Pepys package itself in 'editable mode' by running
pip install -e .
- Important: Skip to the :ref:`Run the unit tests` section without following the intermediate steps of the guide.
- Create a
pepys
folder, which contains alib
folder. - Download the 64-bit sqlite3 DLL from https://www.sqlite.org/download.html
- Unzip that DLL to
lib\sqlite-python
- Navigate to the
<python installation directory>\DLLs
folder, copy_sqlite3.pyd
tolib\sqlite-python
- Add the
lib\sqlite-python
folder to your %PYTHONPATH% environment variable (create the variable if necessary) - Download spatialite from http://www.gaia-gis.it/gaia-sins/windows-bin-NEXTGEN-amd64/mod_spatialite-NG-win-amd64.7z
- Unzip and put the folder
mod_spatialite-NG-win-amd64
inside the lib folder - Add that folder to your
%PATH%
variable - Install PostreSQL by downloading version 12.2 for Windows x86-64 from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
- Go through the installation wizard, accepting the default settings and choosing to load the Stack Builder application after installation
- Use the StackBuilder application to install PostGIS, and follow the wizard through to the end.
12. Add the Postgres bin directory to the %PATH%
- eg. C:\Program Files\PostgreSQL\12\bin\
- but make
sure it comes after the mod_spatialite
folder (hint: using
Rapid Environment Editor makes it easy to re-arrange entries in the PATH)
- Install Git from https://git-scm.com/downloads.
Clone the pepys-import repository into a folder of your choice by running:
$ git clone https://github.com/debrief/pepys-import.git
(If preferred, you can clone using SSH by running git clone [email protected]:debrief/pepys-import.git
).
Following best practice, a Python virtual environment will be used to run the project. To create a virtual environment, move to the folder in which you cloned the repository, and run:
$ python -m venv venv
This will create a virtual environment in a folder called venv
.
When environment is created successfully, please run the following commands to activate the environment and install the Python dependencies:
$ source venv/bin/activate # Linux and OS X $ .\venv\Scripts\activate.bat # Windows $ pip install -r requirements.txt $ pip install -r requirements_dev.txt
Alembic, which is used for Database migration, is in the requirements of the project. However, there is one post-installation step to run it without any problem. You should install the pepys-import project in an editable mode. Please run the following command in the root of the cloned repository:
$ pip install -e .
To run the unittests run:
$ pytest tests/
To run the unittests excluding the tests that require PostgreSQL (for example, if you couldn't install PostgreSQL earlier):
$ pytest tests/ -m "not postgres"
To view the coverage of the test suite, run:
$ coverage run -m pytest tests/
and then view the report with:
$ coverage report
Development is conducted using Feature Branches
Essentially each new piece of work (whether it be a fix or a new feature) is developed in its own branch.
Here is the flow:
- unless you have a very good reason (minor cosmetic documentation update), the process starts with an issue. Create the issue, if necessary, documenting the problem that is being solved, and the strategy for solving it
- open your git client (command-line or graphical, the GitHub client integrates very well)
- switch to the develop branch
- Pull to update the develop branch
- create a new branch, including the issue number and brief description in the title, eg: 433_solitaire_feature
- checkout the new branch
- use commits as necessary to break down the workflow
- once you're confident in your progress Push the branch to the repo (so we can create a draft/tracking PR)
- in GitHub, switch to Pull Requests. You should see a yellow banner with the title of your branch
- Click on the link in the yellow banner, to create a Pull Request (PR)
- Give the PR a nice neat title
- Mark the PR as Draft
- In the PR description, if this PR will resolve the issue, start with Fixes #433. If it won't resolve it, but will help it, write Supports #433
- Continue with branch, pushing commits as necessary. If you want early feedback, just ask for support via a PR URL in the team Slack channel
- Once you're happy the PR is complete, and have completed the PR checklist, mark it as Ready for review, and add one or more reviewers
- Reviewers provide feedback as comments on the PR Conversation tab, or alongside code in the Files changed tab.
- Ultimately a project admin will Merge the code
Other tips:
- try to avoid large-scale reformatting within a PR, since it obfuscates the logic changes. So, please do large scale reformatting in its own PR, for separate review.
- don't forget to regularly click on Update branch to ensure your code is up to date with develop
- these other things help with PR reviews: 1. if the change is graphical a screenshot is useful 2. if something dynamic is happening, a video recording helps (maybe via an app like Gyazo Pro)
The following tips/steps allow use of GitHub codespaces for Pepys dev.
CodeSpaces aren't universally available, though @IanMayo has them available by registering for the Beta Program.
- In GitHub (GH) select the branch (or create a new one)
- In the
Code
drop-down selectNew CodeSpace
- The CodeSpace will open, and
pip install
will run, to load the dependencies
4. Run this code to check an import works: python -m pepys_import.cli --path tests/sample_data/track_files/rep_data/ --db test.db --resolver default
4. Run this code to check things are installed: pytest tests/test_data_store_api_spatialite.py