Skip to content

Commit

Permalink
Fix linting issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
yaph committed Nov 5, 2024
1 parent 50cf26d commit 33962ca
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 77 deletions.
1 change: 0 additions & 1 deletion logya/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
__author__ = 'Ramiro Gómez'
__email__ = '[email protected]'
__version__ = '5.2.0'
6 changes: 2 additions & 4 deletions logya/content.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from operator import itemgetter
from pathlib import Path
Expand All @@ -8,7 +7,6 @@
from logya.template import render
from logya.util import load_yaml, slugify


# Extensions of content files that will be processed.
process_extensions = {
'.css',
Expand Down Expand Up @@ -48,7 +46,7 @@ def create_url(path: Path) -> str:
suffix = ''
if path.suffix in remove_extensions:
suffix = '/'
if 'index' == path.stem:
if path.stem == 'index':
path = Path(path.parent)
else:
path = path.parent.joinpath(path.stem)
Expand Down Expand Up @@ -93,7 +91,7 @@ def read(path: Path, path_rel: Path, markdown_extensions: list) -> dict | None:
print(f'Error reading/parsing: {path}\n{err}')
return None

if 'markdown' == content_type(path):
if content_type(path) == 'markdown':
doc['body'] = markdown(doc['body'], extensions=markdown_extensions)

# Ensure doc has a title.
Expand Down
10 changes: 4 additions & 6 deletions logya/core.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-
import yaml

from collections import ChainMap
from os import walk
from pathlib import Path
from sys import exit
from typing import Dict

from logya.content import read, process_extensions
import yaml

from logya.content import process_extensions, read
from logya.template import init_env
from logya.util import load_yaml, paths, slugify

Expand All @@ -29,7 +27,7 @@ def __init__(self, dir_site: str = '.', verbose: bool = False) -> None:
exit('Error: The site configuration file site.yaml could not be parsed.')

# Initialize index and collections so scripts can generate indexed content before build.
self.doc_index: Dict[str, dict] = {}
self.doc_index: dict[str, dict] = {}
self.collections = self.settings.get('collections', {})
for coll in self.collections.values():
coll['index'] = {}
Expand Down
2 changes: 0 additions & 2 deletions logya/create.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
import shutil
import sys

from importlib import resources

from logya.util import paths
Expand Down
3 changes: 1 addition & 2 deletions logya/docparser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
import markdown

from yaml import load

try:
from yaml import CLoader as Loader
except ImportError:
Expand Down
5 changes: 1 addition & 4 deletions logya/encoder.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# -*- coding: utf-8 -*-
import datetime
import json


class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, datetime.datetime):
return obj.isoformat(sep=' ', timespec='seconds')
elif isinstance(obj, datetime.date):
if isinstance(obj, datetime.date | datetime.datetime):
return obj.isoformat(sep=' ', timespec='seconds')
elif isinstance(obj, datetime.timedelta):
return (datetime.datetime.min + obj).time().isoformat(sep=' ', timespec='seconds')
Expand Down
4 changes: 1 addition & 3 deletions logya/generate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
import shutil

from shutil import copytree

from logya.core import Logya
from logya.content import write_collection, write_page
from logya.core import Logya


def generate(dir_site: str, verbose: bool, keep: bool, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion logya/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse

from logya import __version__
Expand Down
6 changes: 2 additions & 4 deletions logya/server.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
import http.server
import socketserver

from shutil import copyfile
from urllib.parse import unquote, urlparse

from logya.core import Logya
from logya.content import read, write_collection, write_page
from logya.core import Logya
from logya.template import env


Expand Down Expand Up @@ -88,4 +86,4 @@ def serve(dir_site: str, verbose: bool, host: str, port: int, **kwargs) -> None:
socketserver.TCPServer.allow_reuse_address = True
with socketserver.TCPServer((host, port), HTTPRequestHandler) as httpd:
print(f'Serving on {base_url}')
httpd.serve_forever()
httpd.serve_forever()
2 changes: 0 additions & 2 deletions logya/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from operator import itemgetter
from pathlib import Path
Expand All @@ -10,7 +9,6 @@

from logya.util import cache, slugify


env = Environment(
lstrip_blocks=True,
trim_blocks=True
Expand Down
6 changes: 3 additions & 3 deletions logya/util.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
import re

from collections import namedtuple
from pathlib import Path
from string import punctuation, whitespace

from yaml import dump, load

try:
from yaml import CDumper as Dumper, CLoader as Loader
from yaml import CDumper as Dumper
from yaml import CLoader as Loader
except ImportError: # pragma: no cover
from yaml import Dumper, Loader # type: ignore

Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pathlib import Path

try:
Expand All @@ -9,7 +8,6 @@

from logya import __version__


setup(
name='logya',
version=__version__,
Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import unittest


Expand Down
14 changes: 6 additions & 8 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,32 @@
# -*- coding: utf-8 -*-
import subprocess

from shutil import rmtree


def run(command):
return subprocess.run(command, capture_output=True, shell=True, text=True)
return subprocess.run(command, capture_output=True, shell=True, text=True, check=False)


def test_generate():
out = run('python logya/main.py gen --dir-site logya/sites/docs')
assert 0 == out.returncode
assert out.returncode == 0
assert 'write pages' in out.stdout.lower()


def test_generate_wrong_dir():
out = run('python logya/main.py gen --dir-site .')
assert 1 == out.returncode
assert out.returncode == 1
assert 'error' in out.stderr.lower()


def test_create():
out = run('python logya/main.py create test_create_site --dir-site tests/fixtures/')
assert 0 == out.returncode
assert out.returncode == 0
assert 'site created' in out.stdout.lower()

# Second time must fail
out2 = run('python logya/main.py create test_create_site --dir-site tests/fixtures/')
assert 1 == out2.returncode
assert out2.returncode == 1
assert 'already exists' in out2.stderr.lower()

# Cleanup
rmtree('tests/fixtures/test_create_site')
rmtree('tests/fixtures/test_create_site')
12 changes: 4 additions & 8 deletions tests/test_content.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pytest

import logya.content

from pathlib import Path

import logya.content
from logya.util import paths


markdown_extensions = ['attr_list', 'def_list', 'fenced_code', 'toc']
site_root = 'tests/fixtures/site/'
site_paths = paths(site_root)
Expand Down Expand Up @@ -53,7 +49,7 @@ def test_filepath():
def test_parse_empty_body():
md = Path(site_root, 'content', 'empty-body.md')
doc = logya.content.read(md, md.relative_to(site_paths.content), markdown_extensions)
assert '' == doc['body']
assert doc['body'] == ''


def test_parse_error(capsys):
Expand All @@ -66,7 +62,7 @@ def test_parse_error(capsys):
def test_read_auto_url():
md = Path(site_root, 'content', 'separator.md')
doc = logya.content.read(md, md.relative_to(site_paths.content), markdown_extensions)
assert '/separator/' == doc['url']
assert doc['url'] == '/separator/'


def test_read_error(capsys):
Expand All @@ -80,4 +76,4 @@ def test_read_markdown():
md = Path(site_root, 'content', 'markdown.md')
doc = logya.content.read(md, md.relative_to(site_paths.content), markdown_extensions)
assert '<a href="/url/">Link</a>' in doc['body']
assert '<a class="foo bar" href="/url/" title="Some title!">Link with attributes</a>' in doc['body']
assert '<a class="foo bar" href="/url/" title="Some title!">Link with attributes</a>' in doc['body']
4 changes: 2 additions & 2 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pytest

import logya.core


@pytest.fixture
def L():
return logya.core.Logya(dir_site='logya/sites/base/')
Expand All @@ -13,4 +13,4 @@ def test_build(L):
L.build()

assert '/' in L.doc_index
assert '/404/' in L.doc_index
assert '/404/' in L.doc_index
18 changes: 0 additions & 18 deletions tests/test_stdlib.py

This file was deleted.

3 changes: 1 addition & 2 deletions tests/test_template.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pytest

import logya.core
Expand Down Expand Up @@ -49,7 +48,7 @@ def test_filesource():

def test_filesource_lines():
text = env_globals['filesource']('content/rss.xml', lines=1)
assert '---' == text
assert text == '---'


def test_filesource_image():
Expand Down
6 changes: 2 additions & 4 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# -*- coding: utf-8 -*-
import logya.util


site_root = 'tests/fixtures/site/'
site_paths = logya.util.paths(site_root)


def test_encode_content():
text = logya.util.encode_content({}, '')
assert 2 == text.count('---\n')
assert text.count('---\n') == 2


def test_slugify():
Expand All @@ -27,4 +25,4 @@ def test_slugify():


def test_paths():
assert site_paths.public.as_posix() == site_root + 'public'
assert site_paths.public.as_posix() == site_root + 'public'

0 comments on commit 33962ca

Please sign in to comment.