Skip to content

Commit

Permalink
general: set min python version to 3.9 and cleanup CI files
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Oct 24, 2024
1 parent ed12951 commit 5f0f5f5
Show file tree
Hide file tree
Showing 41 changed files with 188 additions and 166 deletions.
13 changes: 10 additions & 3 deletions .ci/run
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ if ! command -v sudo; then
}
fi

# --parallel-live to show outputs while it's running
tox_cmd='run-parallel --parallel-live'
if [ -n "${CI-}" ]; then
# install OS specific stuff here
case "$OSTYPE" in
Expand All @@ -21,7 +23,8 @@ if [ -n "${CI-}" ]; then
;;
cygwin* | msys* | win*)
# windows
:
# ugh. parallel stuff seems super flaky under windows, some random failures, "file used by other process" and crap like that
tox_cmd='run'
;;
*)
# must be linux?
Expand All @@ -40,5 +43,9 @@ if ! command -v python3 &> /dev/null; then
PY_BIN="python"
fi

"$PY_BIN" -m pip install --user tox
"$PY_BIN" -m tox --parallel --parallel-live "$@"

# TODO hmm for some reason installing uv with pip and then running
# "$PY_BIN" -m uv tool fails with missing setuptools error??
# just uvx directly works, but it's not present in PATH...
"$PY_BIN" -m pip install --user pipx
"$PY_BIN" -m pipx run uv tool run --with=tox-uv tox $tox_cmd "$@"
15 changes: 11 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
fail-fast: false
matrix:
platform: [ubuntu-latest, macos-latest] # todo enable windows-latest later -- need to fix a couple of tests first
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
# vvv just an example of excluding stuff from matrix
# exclude: [{platform: macos-latest, python-version: '3.6'}]

Expand Down Expand Up @@ -56,8 +56,15 @@ jobs:
- if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms
uses: actions/upload-artifact@v4
with:
name: .coverage.mypy_${{ matrix.platform }}_${{ matrix.python-version }}
path: .coverage.mypy/
include-hidden-files: true
name: .coverage.mypy-core_${{ matrix.platform }}_${{ matrix.python-version }}
path: .coverage.mypy-core/
- if: matrix.platform == 'ubuntu-latest' # no need to compute coverage for other platforms
uses: actions/upload-artifact@v4
with:
include-hidden-files: true
name: .coverage.mypy-misc_${{ matrix.platform }}_${{ matrix.python-version }}
path: .coverage.mypy-misc/


pypi:
Expand All @@ -70,7 +77,7 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: '3.8'
python-version: '3.10'

- uses: actions/checkout@v4
with:
Expand Down
5 changes: 2 additions & 3 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[mypy]
namespace_packages = True
pretty = True
show_error_context = True
show_error_codes = True
show_column_numbers = True
show_error_end = True
warn_redundant_casts = True
warn_unused_ignores = True
check_untyped_defs = True
enable_error_code = possibly-undefined
strict_equality = True
enable_error_code = possibly-undefined

# an example of suppressing
# [mypy-my.config.repos.pdfannots.pdfannots]
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dependencies = [
"appdirs" , # to keep state files
"atomicwrites", # to safely append data to a file
]
requires-python = ">= 3.9"

## these need to be set if you're planning to upload to pypi
description = "Converts data into org-mode"
Expand Down
12 changes: 7 additions & 5 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target-version = "py38" # NOTE: inferred from pyproject.toml if present
target-version = "py39" # NOTE: inferred from pyproject.toml if present

lint.extend-select = [
"F", # flakes rules -- default, but extend just in case
Expand All @@ -9,7 +9,7 @@ lint.extend-select = [
"C4", # flake8-comprehensions -- unnecessary list/map/dict calls
"COM", # trailing commas
"EXE", # various checks wrt executable files
# "I", # sort imports
"I", # sort imports
"ICN", # various import conventions
"FBT", # detect use of boolean arguments
"FURB", # various rules
Expand All @@ -30,6 +30,7 @@ lint.extend-select = [
"PTH", # pathlib migration
"ARG", # unused argument checks
"A", # builtin shadowing
"G", # logging stuff
# "EM", # TODO hmm could be helpful to prevent duplicate err msg in traceback.. but kinda annoying

# "ALL", # uncomment this to check for new rules!
Expand Down Expand Up @@ -63,10 +64,9 @@ lint.ignore = [
"E402", # Module level import not at top of file

### maybe consider these soon
# sometimes it's useful to give a variable a name even if we don't use it as a documentation
# on the other hand, often is a sign of error
# sometimes it's useful to give a variable a name even if we don't use it as a documentation
# on the other hand, often is a sign of error
"F841", # Local variable `count` is assigned to but never used
"F401", # imported but unused
###

"RUF100", # unused noqa -- handle later
Expand Down Expand Up @@ -127,6 +127,8 @@ lint.ignore = [

"TID252", # Prefer absolute imports over relative imports from parent modules

"UP038", # suggests using | (union) in isisntance checks.. but it results in slower code

## too annoying
"T20", # just complains about prints and pprints
"Q", # flake quotes, too annoying
Expand Down
10 changes: 9 additions & 1 deletion src/orger/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from typing import TYPE_CHECKING

from .org_view import Mirror, OrgWithKey, Queue, StaticView
from .org_view import Mirror, OrgWithKey, Queue

__all__ = [
'Mirror',
'OrgWithKey',
'Queue',
]


if not TYPE_CHECKING:
# TODO deprecate properly?
InteractiveView = Queue
StaticView = Mirror
19 changes: 10 additions & 9 deletions src/orger/atomic_append.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from __future__ import annotations

import logging
from os.path import lexists
from pathlib import Path
from typing import Union

PathIsh = Union[str, Path]

def atomic_append_raw(
path: PathIsh,
data: str,
path: Path | str,
data: str,
) -> None:
path = Path(path)
# https://stackoverflow.com/a/13232181
Expand All @@ -25,13 +25,13 @@ def assert_not_edited(path: Path) -> None:
emacs = '.#' + path.name
for x in [vim, emacs]:
lf = path.parent / x
if lexists(lf): # lexist is necessary because emacs uses symlink for lock file
if lexists(lf): # lexist is necessary because emacs uses symlink for lock file
raise RuntimeError(f'File is being edited: {lf}')


def atomic_append_check(
path: PathIsh,
data: str,
path: Path | str,
data: str,
) -> None:
"""
This is editor (emacs/vim)-aware and checks for existence of swap file first.
Expand All @@ -56,8 +56,9 @@ def test_atomic_append_check(tmp_path: Path) -> None:
of.touch()

from contextlib import contextmanager
from subprocess import PIPE, Popen, check_call
from subprocess import PIPE, Popen
from time import sleep

@contextmanager
def tmp_popen(*args, **kwargs):
with Popen(*args, **kwargs) as p:
Expand All @@ -70,7 +71,7 @@ def tmp_popen(*args, **kwargs):
atomic_append_check(of, 'data2')
assert of.read_text() == 'data1data2'

with tmp_popen(['vi', '-c', 'startinsert', str(of)], stdin=PIPE, stdout=PIPE, stderr=PIPE) as p: # enter insert mode
with tmp_popen(['vi', '-c', 'startinsert', str(of)], stdin=PIPE, stdout=PIPE, stderr=PIPE) as p: # enter insert mode
for _attempt in range(10):
# ugh, needs long pause for some reason
sleep(1)
Expand Down
9 changes: 7 additions & 2 deletions src/orger/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class settings:


_timezones = set() # type: ignore


def dt_heading(dt: datetime | None, heading: str) -> str:
"""
Helper to inline datetime in heading
Expand All @@ -27,7 +29,9 @@ def dt_heading(dt: datetime | None, heading: str) -> str:
tz = dt.tzinfo
# todo come up with a better way of reporting this..
if tz not in _timezones and len(_timezones) > 0:
warnings.warn(f"Seems that a mixture of timezones is used. Org-mode doesn't support timezones, so this might end up confusing: {_timezones} {tz} {heading}")
warnings.warn(
f"Seems that a mixture of timezones is used. Org-mode doesn't support timezones, so this might end up confusing: {_timezones} {tz} {heading}"
)
_timezones.add(tz)

return timestamp_with_style(dt=dt, style=settings.DEFAULT_TIMESTAMP_STYLE) + ' ' + heading
Expand Down Expand Up @@ -57,9 +61,10 @@ def todo(dt: datetime, **kwargs):

def orger_user_dir() -> Path:
import appdirs # type: ignore[import-untyped]

return Path(appdirs.user_config_dir('orger'))


if not TYPE_CHECKING:
# legacy imports for bwd compatibility
from .logging_helper import LazyLogger, setup_logger
from .logging_helper import LazyLogger, setup_logger # noqa: F401
7 changes: 1 addition & 6 deletions src/orger/inorganic.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
from __future__ import annotations

import logging
import os
import re
import textwrap
import warnings
from collections import OrderedDict
from collections.abc import Mapping, Sequence
from dataclasses import dataclass
from datetime import date, datetime
from enum import Enum
from pathlib import Path
from typing import (
TYPE_CHECKING,
Any,
Callable,
Mapping,
Sequence,
TypeVar,
Union,
)
Expand Down
14 changes: 7 additions & 7 deletions src/orger/modules/auto.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env python3
from __future__ import annotations

from orger import Mirror
from orger.inorganic import node, link, Quoted
from orger.common import dt_heading, error

import string
from collections.abc import Iterator
from datetime import datetime
from typing import Iterator, Any
from pprint import pformat
import string
from typing import Any

from more_itertools import bucket

from my.core.types import asdict

from orger import Mirror
from orger.common import dt_heading, error
from orger.inorganic import Quoted, node


def pp_item(i, **kwargs) -> str:
# annoying, pprint doesn't have dataclass support till 3.10 https://bugs.python.org/issue43080
Expand Down
8 changes: 4 additions & 4 deletions src/orger/modules/github.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
from orger import Mirror
from orger.inorganic import node, link
import my.github.all as github

from orger import Mirror, pandoc
from orger.common import dt_heading, error
from orger import pandoc
from orger.inorganic import link, node

import my.github.all as github
# todo use later: import my.github.ghexport as gh. also careful about using events() -- need to sort?
# I guess makes sense to generally expose get_ methods?

Expand Down
6 changes: 3 additions & 3 deletions src/orger/modules/hyp2org.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
so I can un/reschedule them if they don't require immediate attention.
"""

from my.hypothesis import Highlight, highlights

from orger import Queue
from orger.inorganic import node, link
from orger.common import todo

from my.hypothesis import highlights, Highlight
from orger.inorganic import link


def is_todo(e: Highlight) -> bool:
Expand Down
6 changes: 3 additions & 3 deletions src/orger/modules/hypothesis.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
import my.hypothesis as hypothesis

from orger import Mirror
from orger.inorganic import node, link
from orger.common import dt_heading, error

import my.hypothesis as hypothesis
from orger.inorganic import link, node


class HypView(Mirror):
Expand Down
6 changes: 3 additions & 3 deletions src/orger/modules/instapaper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
from my.instapaper import pages

from orger import Mirror
from orger.inorganic import node, link, Quoted
from orger.common import dt_heading

from my.instapaper import pages
from orger.inorganic import Quoted, link, node


class Instapaper(Mirror):
Expand Down
6 changes: 3 additions & 3 deletions src/orger/modules/ip2org.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
from my.instapaper import is_todo, pages

from orger import Queue
from orger.inorganic import node, link
from orger.common import todo

from my.instapaper import pages, is_todo
from orger.inorganic import link


class IpTodos(Queue):
Expand Down
6 changes: 3 additions & 3 deletions src/orger/modules/kobo.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
from my.kobo import Highlight, get_books_with_highlights

from orger import Mirror
from orger.inorganic import node, link, OrgNode
from orger.common import dt_heading

from my.kobo import get_books_with_highlights, Highlight
from orger.inorganic import OrgNode, node


class KoboView(Mirror):
Expand Down
5 changes: 2 additions & 3 deletions src/orger/modules/kobo2org.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env python3
from my.kobo import get_todos

from orger import Queue
from orger.inorganic import node, link
from orger.common import todo

from my.books.kobo import get_todos, Highlight


class KoboTodos(Queue):
def get_items(self) -> Queue.Results:
Expand Down
Loading

0 comments on commit 5f0f5f5

Please sign in to comment.