Skip to content

Commit

Permalink
Autoformat on pre-commit (qgis#259)
Browse files Browse the repository at this point in the history
* Add pre-commit lint hook for local dev

* Add general formatting to pre-commit-config

* Add autoremove unused variables to pre-commit-config

* Add black formatter to pre-commit-config

* Apply pre-commit formatters on all files

Co-authored-by: Dimas Ciputra <[email protected]>
  • Loading branch information
faebebin and dimasciput authored Sep 8, 2022
1 parent 907eaaf commit a205eff
Show file tree
Hide file tree
Showing 243 changed files with 6,392 additions and 4,245 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ max-line-length = 79
# E12x continuation line indentation
# E251 no spaces around keyword / parameter equals
# E303 too many blank lines (3)
ignore = E121,E122,E123,E124,E125,E126,E127,E128,E251,E303,W503,W504,W60,F405
ignore = E121,E122,E123,E124,E125,E126,E127,E128,E251,E303,W503,W504,W60,F405,E501
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

exclude: 'static/'
repos:
# Fix end of files
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: mixed-line-ending
args:
- '--fix=lf'

# Remove unused imports/variables
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
- id: autoflake
args:
- "--in-place"
- "--remove-unused-variables"
# - "--remove-all-unused-imports"

# Sort imports
- repo: https://github.com/pycqa/isort
rev: "5.7.0"
hooks:
- id: isort
args: ["--profile", "black"]

# Black formatting
- repo: https://github.com/psf/black
rev: 20.8b1
hooks:
- id: black

# Lint files
- repo: https://gitlab.com/pycqa/flake8
rev: "3.9.0"
Expand Down
10 changes: 5 additions & 5 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ patent must be licensed for everyone's free use or not licensed at all.

The precise terms and conditions for copying, distribution and
modification follow.

GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

Expand Down Expand Up @@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
Expand Down Expand Up @@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
Expand Down Expand Up @@ -225,7 +225,7 @@ impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
Expand Down Expand Up @@ -278,7 +278,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS

In addition, as a special exception, the QGIS Development Team gives
permission to link the code of this program with the Qt library,
including but not limited to the following versions (both free and
Expand Down
12 changes: 6 additions & 6 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Follow these steps for setting up:
- Create new Group: `Authentication and Authorization > Groups > Add group`
- Set the options:
- **Name:** `Style Managers`
- **Permissions:**
- **Permissions:**
choose all styles | in **Available permissions** by typing `styles` in search input and click `Choose all`
- styles | style | Can add style
- styles | style | Can change style
Expand All @@ -134,15 +134,15 @@ Follow these steps for setting up:
- styles | style type | Can change style type
- styles | style type | Can delete style type
- styles | style type | Can view style type

---
## Backup and Restore

- Go to repo directory and run backup.sh
```bash
$ ./backup.sh
```
- You will find dumps file in backups directory
- You will find dumps file in backups directory
```bash
$ tree -L 3 backups
backups
Expand Down Expand Up @@ -174,7 +174,7 @@ backups
`
```

- Copy the dump file you wish to restore to dockerize/backups/latest.dmp file
- Copy the dump file you wish to restore to dockerize/backups/latest.dmp file
```bash
$ cp backups/2020/December/PG_QGIS_PLUGINS_gis.16-December-2020.dmp dockerize/backups/latest.dmp
```
Expand All @@ -198,9 +198,9 @@ $ make dbrestore
- In Containers tab, click on tripe-dot icon > `Execute Shell`
![image](https://user-images.githubusercontent.com/40058076/102454128-7352ee00-4078-11eb-80aa-f782c6ea9f6f.png)
Now you are inside the container and ready to deploy your update.
![image](https://user-images.githubusercontent.com/40058076/102455185-1ce6af00-407a-11eb-8318-3e084b24c095.png)
- Pull the latest commit: `git pull origin master`
- Run migration: `python manage.py migrate`
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ all:


run: kill_server
cd $(PRJ_DIR) && python manage.py runserver 0.0.0.0:8000
cd $(PRJ_DIR) && python manage.py runserver 0.0.0.0:8000

kill_server:
@if /usr/sbin/lsof -i :8000; then \
Expand Down
2 changes: 1 addition & 1 deletion REQUIREMENTS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ django-sortable-listview==0.43
django-user-map
djangorestframework==3.12.2
django-rest-auth==0.9.5
drf-yasg
drf-yasg
4 changes: 2 additions & 2 deletions apache/apache.virtenv.conf.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<VirtualHost *>
ServerAdmin [email protected]
ServerAdmin [email protected]
ServerName qgis-django.localhost
ServerAlias www.qgis-django.localhost
DocumentRoot /var/www
CustomLog /var/log/apache2/qgis-django.access.log combined
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
LogLevel debug
#warn
ErrorLog /var/log/apache2/qgis-django.error.log
ServerSignature Off
Expand Down
14 changes: 7 additions & 7 deletions apache/django.wsgi
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import os
import sys

ROOT_PROJECT_FOLDER = os.path.dirname(__file__)
path1 = os.path.abspath(os.path.join(ROOT_PROJECT_FOLDER, '..'))
path2 = os.path.abspath(os.path.join(ROOT_PROJECT_FOLDER, '..', 'qgis-app'))
path1 = os.path.abspath(os.path.join(ROOT_PROJECT_FOLDER, ".."))
path2 = os.path.abspath(os.path.join(ROOT_PROJECT_FOLDER, "..", "qgis-app"))

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
sys.path.append( path1 )
sys.path.append( path2 )
file("/tmp/log.txt","wt").write( str(sys.path) )

application = django.core.handlers.wsgi.WSGIHandler()
sys.path.append(path1)
sys.path.append(path2)
file("/tmp/log.txt", "wt").write(str(sys.path))
1 change: 0 additions & 1 deletion createdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ createdb qgis-django
createlang plpgsql qgis-django
psql qgis-django < /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql
psql qgis-django < /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql

3 changes: 1 addition & 2 deletions doc/APPS.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Tim Sutton 2010
%This document is in text2tags format. You can generate html, plain text and
%moinmoin formatted documentation by running txt2tags on this document. See the
%txt2tags home page for more details. Please insert manual line breaks in this
%document as it makes diffing for changes much easier. To do this in vim
%document as it makes diffing for changes much easier. To do this in vim
%automatically, select a section then issue (gq) command. Please dont
%apply vim formatting to the whole document as it screws up some formatting
%rather apply it selectively to paragraphs where needed.
Expand Down Expand Up @@ -46,4 +46,3 @@ Tim Sutton 2010
+ web links - a list of sites, articles etc. that feature QGIS prominantly
+ translate - a pootle instance for QGIS
+ user showcase - as simple way for users to highlight their use of QGIS without writing a full blown case study

2 changes: 1 addition & 1 deletion dockerize/plugins_mirror.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash

#First the database backups on the remote server
SOURCE=/mnt/HC_Volume_4113275
Expand Down
2 changes: 1 addition & 1 deletion qgis-app/REQUIREMENTS_plugins.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ sorl-thumbnail
django-extensions
django-debug-toolbar==1.11.1
whoosh
django-haystack
django-haystack
2 changes: 1 addition & 1 deletion qgis-app/api/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class ApiConfig(AppConfig):
name = 'api'
name = "api"
2 changes: 1 addition & 1 deletion qgis-app/api/permissions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import permissions

MANAGER_GROUP = 'Style Managers'
MANAGER_GROUP = "Style Managers"


class ReadOnly(permissions.BasePermission):
Expand Down
37 changes: 16 additions & 21 deletions qgis-app/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
from rest_framework import serializers
from sorl_thumbnail_serializer.fields import HyperlinkedSorlImageField

from base.validator import filesize_validator

from geopackages.models import Geopackage
from models.models import Model
from rest_framework import serializers
from sorl_thumbnail_serializer.fields import HyperlinkedSorlImageField
from styles.models import Style


class ResourceBaseSerializer(serializers.ModelSerializer):
creator = serializers.ReadOnlyField(source='get_creator_name')
creator = serializers.ReadOnlyField(source="get_creator_name")
resource_type = serializers.SerializerMethodField()
resource_subtype = serializers.SerializerMethodField()

# A thumbnail image, sorl options and read-only
thumbnail = HyperlinkedSorlImageField(
'128x128',
options={"crop": "center"},
source='thumbnail_image',
read_only=True
"128x128", options={"crop": "center"}, source="thumbnail_image", read_only=True
)

class Meta:
fields = [
'resource_type',
'resource_subtype',
'uuid',
'name',
'creator',
'upload_date',
'download_count',
'description',
'file',
'thumbnail',
"resource_type",
"resource_subtype",
"uuid",
"name",
"creator",
"upload_date",
"download_count",
"description",
"file",
"thumbnail",
]

def validate(self, attrs):
file = attrs.get('file')
file = attrs.get("file")
filesize_validator(file)
return attrs

Expand All @@ -61,7 +56,7 @@ def get_resource_subtype(self, obj):


class StyleSerializer(ResourceBaseSerializer):
resource_subtype = serializers.ReadOnlyField(source='get_style_type')
resource_subtype = serializers.ReadOnlyField(source="get_style_type")

class Meta(ResourceBaseSerializer.Meta):
model = Style
Loading

0 comments on commit a205eff

Please sign in to comment.