Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting and tweaks #477

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
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
12 changes: 10 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
[*.py]
max_line_length = 119
root = true

[*.html]
charset = utf-8
indent_size = 4
indent_style = space
max_line_length = 119

[*.py]
charset = utf-8
indent_size = 4
indent_style = space
max_line_length = 119
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..base import BlockchainBase
from .base import EXPECTED_LOCK_EXCEPTION, LOCKED_EXCEPTION, FileBlockchainBaseMixin # noqa: I101
from .block_chunk.base import BlockChunkFileBlockchainMixin
from .blockchain_state.base import BlochainStateFileBlockchainMixin
from .blockchain_state.base import BlockchainStateFileBlockchainMixin

logger = logging.getLogger(__name__)

Expand All @@ -24,7 +24,7 @@ def copytree_safe(source, destination):


class FileBlockchain(
BlockChunkFileBlockchainMixin, BlochainStateFileBlockchainMixin, FileBlockchainBaseMixin, BlockchainBase
BlockChunkFileBlockchainMixin, BlockchainStateFileBlockchainMixin, FileBlockchainBaseMixin, BlockchainBase
):

def __init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
logger = logging.getLogger(__name__)


class BlochainStateFileBlockchainMixin(FileBlockchainBaseMixin):
class BlockchainStateFileBlockchainMixin(FileBlockchainBaseMixin):

def get_blockchain_state_storage(self):
raise NotImplementedError('Must be implemented in child class')
Expand Down Expand Up @@ -54,6 +54,7 @@ def _load_blockchain_state(self, filename):
return blockchain_state

storage = self.get_blockchain_state_storage()

assert storage.is_finalized(filename)
blockchain_state = BlockchainState.from_messagepack(storage.load(filename))

Expand Down
8 changes: 6 additions & 2 deletions thenewboston_node/business_logic/storages/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(
temp_dir='.tmp',
use_atomic_write=True
):
self.base_path = Path(base_path).resolve()
self.base_path = Path(base_path).absolute()
self.compressors = compressors
self.temp_dir = self.base_path / temp_dir
self.use_atomic_write = use_atomic_write
Expand Down Expand Up @@ -165,11 +165,15 @@ def is_finalized(self, file_path: Union[str, Path]):
def _get_absolute_path(self, file_path: Union[str, Path]) -> Path:
base_path = self.base_path
path = Path(file_path)
abs_path = (base_path / path).resolve()
abs_path = (base_path / path).absolute()
norm_path = os.path.normpath(abs_path)

if path.is_absolute():
raise ValueError(f"Cannot use absolute path: '{path}'")

if norm_path != str(abs_path):
raise ValueError(f"Normalized path '{norm_path}' must match absolute path '{abs_path}'")

if not abs_path.is_relative_to(base_path):
raise ValueError(f"Path '{abs_path}' is not relative to '{base_path}'")

Expand Down
10 changes: 6 additions & 4 deletions thenewboston_node/business_logic/tests/test_docs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess
from sys import platform

from thenewboston_node.business_logic.docs.impl import get_signed_change_request_message_child_models
from thenewboston_node.business_logic.docs.samples import SamplesFactory
Expand All @@ -24,7 +25,8 @@ def test_get_sample_blocks():


def test_can_generate_docs():
result = subprocess.run(['make', 'docs-html-test'], capture_output=True, text=True)
print(result.stdout)
print(result.stderr)
assert result.returncode == 0
if platform in ['linux', 'linux2']:
result = subprocess.run(['make', 'docs-html-test'], capture_output=True, text=True)
print(result.stdout)
print(result.stderr)
assert result.returncode == 0
6 changes: 5 additions & 1 deletion thenewboston_node/core/tests/test_file_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def unlocked_method(self):
pass


def get_locked_method(lock_filename, notify_event, wait_event):
return Example(lock_filename, notify_event, wait_event).locked_method()


def test_file_lock_is_exclusive_for_threads():
lock_filename = tempfile.mktemp()
notify_event = threading.Event()
Expand All @@ -61,7 +65,7 @@ def test_file_lock_is_exclusive_for_processes():
notify_event = multiprocessing.Event()
wait_event = multiprocessing.Event()

process = multiprocessing.Process(target=lambda: Example(lock_filename, notify_event, wait_event).locked_method())
process = multiprocessing.Process(target=get_locked_method, args=(lock_filename, notify_event, wait_event))
process.start()

notify_event.wait(timeout=1)
Expand Down
40 changes: 0 additions & 40 deletions thenewboston_node/project/settings/base.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
"""
Django settings for project project.

Generated by 'django-admin startproject' using Django 3.1.7.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
# We do not set a valid default value for `SECRET_KEY` to force people to have their own values for security reasons
SECRET_KEY = NotImplemented

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

# TODO(dmu) MEDIUM: Consider a more strict ALLOWED_HOSTS
ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
Expand Down Expand Up @@ -78,9 +55,6 @@

WSGI_APPLICATION = 'thenewboston_node.project.wsgi.application'

# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
Expand All @@ -92,9 +66,6 @@
}
}

# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
Expand All @@ -110,22 +81,11 @@
},
]

# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
27 changes: 8 additions & 19 deletions thenewboston_node/project/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
"""project URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
Expand All @@ -30,9 +15,13 @@
path('admin/', admin.site.urls),
path('', include(thenewboston_node.web.urls)),

# local apps
# Third party
path(API_PREFIX + 'doc/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger'),
path(API_PREFIX + 'schema/', SpectacularAPIView.as_view(), name='schema'),

# Apps
path(API_PREFIX + 'v1/', include(thenewboston_node.accounts.urls)),
path(API_PREFIX + 'v1/', include(thenewboston_node.blockchain.urls)),
path(API_PREFIX + 'schema/', SpectacularAPIView.as_view(), name='schema'),
path(API_PREFIX + 'doc/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger'),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
]

urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
29 changes: 16 additions & 13 deletions thenewboston_node/web/templates/web/index.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
{% load static node %}
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no,width=device-width">
<link rel="icon" href="{% static 'web/img/favicon.ico' %}"/>
<title>thenewboston node {% node_identifier %}</title>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,user-scalable=no,width=device-width">
<link rel="icon" href="{% static 'web/img/favicon.ico' %}"/>
<title>thenewboston node {% node_identifier %}</title>
</head>

<body>
<h3>Navigation</h3>
<ul>
<h3>Navigation</h3>
<li>
<a href="{% url 'swagger' %}">API documentation</a>
</li>
<li>
<a href="{% url 'admin:index' %}">Admin panel</a>
</li>
<!-- __LINKS_STUB__ -->
<li>
<a href="{% url 'swagger' %}">API documentation</a>
</li>
<li>
<a href="{% url 'admin:index' %}">Admin panel</a>
</li>
<!-- __LINKS_STUB__ -->
</ul>

</body>

</html>