Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions .github/workflows/flake8.yml → .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: "Code formatting"

on:
push:
branches: [ master, 4.* ]
branches: [ master, 5.* ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master, 4.* ]
branches: [ master, 5.* ]

jobs:
validate:
Expand All @@ -27,15 +27,10 @@ jobs:
with:
python-version: ${{matrix.python-version}}

- name: Install flake8 & black
run: pip install $(grep -E '"(flake8|black)==[^"]+"' pyproject.toml | sed -E 's/^[^"]*"//; s/".*$//; s/,//')
- name: Install ruff
run: pip install $(grep "ruff==" pyproject.toml | sed -E 's/^[^"]*"//; s/".*$//; s/,//')

- name: "Check: flake8"
- name: "Check: ruff"
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 geonode --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 geonode --count --statistics

- name: "Check: black"
run: black --check geonode
ruff check
2 changes: 1 addition & 1 deletion geonode/base/management/commands/lib/gn20_to_24.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def decode(self, json_string):
obj['fields']['thumbnail_url'] = ''

if 'distribution_url' in obj['fields']:
if not obj['fields']['distribution_url'] is None and 'layers' in obj['fields']['distribution_url']:
if obj['fields']['distribution_url'] is not None and 'layers' in obj['fields']['distribution_url']:

obj['fields']['polymorphic_ctype'] = ["layers", "layer"]

Expand Down
2 changes: 1 addition & 1 deletion geonode/base/management/commands/lib/gn24_to_24.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def decode(self, json_string):
obj['fields']['owner'] = [self.owner]

if 'distribution_url' in obj['fields']:
if not obj['fields']['distribution_url'] is None and 'layers' in obj['fields']['distribution_url']:
if obj['fields']['distribution_url'] is not None and 'layers' in obj['fields']['distribution_url']:
try:
p = '(?P<protocol>http.*://)?(?P<host>[^:/ ]+).?(?P<port>[0-9]*)(?P<details_url>.*)'
m = re.search(p, obj['fields']['distribution_url'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging

import django.contrib.gis.db.models.fields
from django.contrib.gis.geos import Polygon

from django.db import migrations

Expand Down
2 changes: 1 addition & 1 deletion geonode/base/migrations/0082_remove_dialogos_comment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 3.2.12 on 2022-04-11 22:56

from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from django.db import migrations
from django.db.models import Q
from django.conf import settings
from django.contrib.auth import get_user_model
from django.urls import reverse

Expand Down
2 changes: 1 addition & 1 deletion geonode/documents/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def clean_doc_file(self):
"""
doc_file = self.cleaned_data.get("doc_file")

if doc_file and not os.path.splitext(doc_file.name)[1].lower()[1:] in settings.ALLOWED_DOCUMENT_TYPES:
if doc_file and os.path.splitext(doc_file.name)[1].lower()[1:] not in settings.ALLOWED_DOCUMENT_TYPES:
logger.debug("This file type is not allowed")
raise forms.ValidationError(_("This file type is not allowed"))

Expand Down
2 changes: 1 addition & 1 deletion geonode/documents/migrations/0032_auto_20180412_0822.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion geonode/groups/migrations/0027_auto_20180105_1631.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 2.2.16 on 2021-04-28 11:47

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by Django 3.2.4 on 2021-06-23 17:19

from django.db import migrations, models
import geonode.harvesting.models


class Migration(migrations.Migration):
Expand Down
1 change: 0 additions & 1 deletion geonode/layers/migrations/24_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import migrations, models
import datetime
from django.conf import settings
from django.utils.timezone import now
import django.core.files.storage
Expand Down
3 changes: 1 addition & 2 deletions geonode/layers/migrations/26_to_27.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import migrations, models
from django.db.models import F
from django.db import migrations

def copy_typename(apps, schema_editor):
Layer = apps.get_model('layers', 'layer')
Expand Down
2 changes: 1 addition & 1 deletion geonode/maps/migrations/0029_auto_20180412_0822.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion geonode/notifications_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def get_notification_recipients(notice_type_label, exclude_user=None, resource=N
try:
if not user.is_superuser and not user.has_perm("view_resourcebase", resource.get_self_resource()):
exclude_users_ids.append(user.id)
if user.pk == resource.owner.pk and not notice_type_label.split("_")[-1] in (
if user.pk == resource.owner.pk and notice_type_label.split("_")[-1] not in (
"updated",
"rated",
"approved",
Expand Down
6 changes: 3 additions & 3 deletions geonode/security/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ def attributes_sats_refresh(request):
layer.srid = "EPSG:4326"
layer.set_ll_bbox_polygon([ll_bbox[0], ll_bbox[2], ll_bbox[1], ll_bbox[3]])
layer.save()
except Exception as e:
# traceback.print_exc()
except Exception:
logger.exception("Exception occurred while refreshing attributes/stats for resource uuid=%s", uuid)
return HttpResponse(
json.dumps({"success": "false", "message": f'Exception occurred: "{str(e)}"'}),
json.dumps({"success": "false", "message": 'Exception occurred please see the logs"'}),
status=302,
content_type="text/plain",
)
Expand Down
2 changes: 1 addition & 1 deletion geonode/services/migrations/0028_auto_20171201_0640.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion geonode/services/migrations/0029_auto_20171203_1624.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion geonode/services/migrations/0038_auto_20180412_0822.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.db import migrations, models
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion geonode/upload/handlers/common/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ def upsert_validation(self, files, execution_id, **kwargs: dict) -> Tuple[bool,
if "authority" in field and not skip_geom_eval:
if db_value := target_field.model_schema.as_model().objects.first():
skip_geom_eval = True
if not str(db_value.geom.srid) in field["authority"]:
if str(db_value.geom.srid) not in field["authority"]:
errors.append(
f"The file provided have a different authority ({field['authority']}) compared to the one in the DB: {db_value}"
)
Expand Down
5 changes: 3 additions & 2 deletions geonode/upload/handlers/xml/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ def is_valid(files, user=None, **kwargs):
try:
with open(files.get("base_file")) as _xml:
dlxml.fromstring(_xml.read().encode())
except Exception as err:
raise InvalidXmlException(f"Uploaded document is not XML or is invalid: {str(err)}")
except Exception:
logger.warning("Invalid XML upload validation error", exc_info=True)
raise InvalidXmlException("Uploaded document is not XML or is invalid.")
return True

def handle_metadata_resource(self, _exec, dataset, original_handler):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from django.db import migrations
import logging
from django.db import ProgrammingError
from django.db import connections

logger = logging.getLogger("importer")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 4.2.9 on 2024-09-06 14:46

from django.db import migrations, models
from django.db import migrations
from django.db import connection
from geonode.upload.models import ResourceHandlerInfo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def dataset_migration(apps, _):
execution_id=None
)
else:
logger.debug(f"resourcehandler info already exists for the resource")
logger.debug("resourcehandler info already exists for the resource")


class Migration(migrations.Migration):
Expand Down
67 changes: 48 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ dependencies = [
# tests
"coverage==7.5.1",
"requests-toolbelt==1.0.0",
"flake8==7.3.0",
"black==24.4.2",
"pytest==8.4.2",
"pytest-bdd==7.1.2",
"splinter==0.21.0",
Expand All @@ -161,13 +159,12 @@ dependencies = [
# dependency for XLSX handler
"python-calamine==0.6.2",
"python-magic==0.4.27",
"ruff==0.15.14",
]

[project.optional-dependencies]
dev = [
"pytest==8.4.2",
"flake8==7.3.0",
"black==24.4.2",
"coverage==7.5.1",
]
docs = [
Expand All @@ -191,18 +188,50 @@ include = ["geonode*"]
[tool.setuptools.dynamic]
version = {attr = "geonode.__version__"}

[tool.black]
line-length = 120
target-version = ['py310', 'py311']
exclude = '''
/(
geonode/.*/migrations/.*
| geonode/.*/settings.py
| management
| scripts
| docs
| static
| migrations
| node_modules
)/
'''

[tool.ruff]

exclude = [
"geonode/*/migrations/*",
"geonode/**/settings.py",
"management",
"scripts",
"docs",
"static",
"migrations",
"node_modules",
]

# Same as Black.
line-length = 88
indent-width = 4

target-version = "py312"


[tool.ruff.lint]
# E and F are the standard Flake8 rules
select = ["E4", "E7", "E9", "F"]
ignore = ["E203", "E731"]
fixable = ["ALL"]
unfixable = []

dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.lint.isort]
# This makes it behave like modern Black-compatible isort
combine-as-imports = true
lines-after-imports = 2

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _is_valid_ip(ip):
try:
ipaddress.IPv4Address(ip)
return True
except Exception as e:
except Exception:
return False


Expand Down
Loading