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

convert promnesia to a namespace package #225

Merged
merged 5 commits into from
Apr 14, 2021
Merged
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
2 changes: 1 addition & 1 deletion doc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
A more sophisticated example of config for Promnesia
'''

from promnesia import Source
from promnesia.common import Source


# now, let's import some indexers
Expand Down
8 changes: 3 additions & 5 deletions src/promnesia/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from pathlib import Path
from .common import PathIsh, Visit, Source, last, Loc, Results, DbVisit, Context, Res


def root() -> Path:
r = Path(__file__).absolute().parent.parent.parent
assert (r / 'src').exists()
return r
# add deprecation warning so eventually this may converted to a namespace package?
import warnings
warnings.warn("DEPRECATED! Please import directly from 'promnesia.common', e.g. 'from promnesia.common import Visit, Source, Results'", DeprecationWarning)
6 changes: 6 additions & 0 deletions src/promnesia/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ def get_system_tz() -> pytz.BaseTzInfo:
logger.error(f"Unknown time zone %s. Falling back to UTC. Please report this as a bug!", zone)
return pytz.utc

# used in misc/install_server.py
def root() -> Path:
r = Path(__file__).absolute().parent.parent.parent
assert (r / 'src').exists()
return r


def file_mtime(path: PathIsh) -> datetime:
tz = get_system_tz()
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/promnesia/misc/config_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from promnesia import Source
from promnesia.common import Source
from promnesia.sources import auto

'''
Expand Down
6 changes: 3 additions & 3 deletions src/promnesia/misc/install_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
UNSUPPORTED_SYSTEM = RuntimeError(f'Platform {SYSTEM} is not supported yet!')
NO_SYSTEMD = RuntimeError('systemd not detected, find your own way to start promnesia automatically')

from .. import root
from .. import server
from ..common import root
from ..server import setup_parser as server_setup_parser

SYSTEMD_TEMPLATE = '''
[Unit]
Expand Down Expand Up @@ -149,4 +149,4 @@ def setup_parser(p: argparse.ArgumentParser) -> None:

p.add_argument('--name', type=str, default=dflt, help='Systemd/launchd service name')
p.add_argument('--unit-name', type=str, dest='name', help='DEPRECATED, same as --name')
server.setup_parser(p)
server_setup_parser(p)
File renamed without changes.
2 changes: 1 addition & 1 deletion src/promnesia/sources/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Generates a sequence of fake evenly separated visits
'''

from .. import Results, Visit, Loc
from ..common import Results, Visit, Loc
from datetime import datetime, timedelta


Expand Down
11 changes: 6 additions & 5 deletions tests/config_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from more_itertools import ilen
from typing import Union, Iterable, List

from promnesia import Source
from promnesia.common import Source

from common import throw

Expand All @@ -11,6 +11,7 @@ def test_minimal() -> None:
'''
Example of a smallest possible config, using a 'demo' source
'''
# import directly from promnesia, not promnesia.common
cfg = make('''
from promnesia import Source
from promnesia.sources import demo
Expand All @@ -30,7 +31,7 @@ def test_sources_style() -> None:
Testing 'styles' of specifying sources
'''
cfg = make('''
from promnesia import Source
from promnesia.common import Source
from promnesia.sources import demo

SOURCES = [
Expand Down Expand Up @@ -79,7 +80,7 @@ def test_sources_style_more():
'''
cfg = make('''
from typing import Iterable
from promnesia import Visit, Source, Loc
from promnesia.common import Visit, Source, Loc

def my_indexer() -> Iterable[Visit]:
from datetime import datetime
Expand Down Expand Up @@ -126,7 +127,7 @@ def test_sources_lazy():
'''

cfg = make('''
from promnesia import Source
from promnesia.common import Source

def lazy():
from promnesia.sources import demo
Expand Down Expand Up @@ -200,7 +201,7 @@ def test_empty_sources():

def test_legacy():
cfg = make('''
from promnesia import Source
from promnesia.common import Source
from promnesia.sources import demo
INDEXERS = [
Source(demo.index, src='legacy name'),
Expand Down
4 changes: 2 additions & 2 deletions tests/indexer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ def test_hook() -> None:
import promnesia.sources.shellcmd as custom_gen
from promnesia.__main__ import iter_all_visits
with with_config('''
from promnesia import Source
from promnesia.common import Source
from promnesia.sources import demo

SOURCES = [
Source(demo.index, count=7, name='somename'),
]

from typing import Iterable
from promnesia import DbVisit, Loc, Res
from promnesia.common import DbVisit, Loc, Res

def HOOK(visit: Res[DbVisit]) -> Iterable[Res[DbVisit]]:
# NOTE: might be a good idea to check that the visit is an exception first and yield it intact?
Expand Down
8 changes: 4 additions & 4 deletions tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def make_visits():
delta=timedelta(seconds={delta.total_seconds()}),
)

from promnesia import Source
from promnesia.common import Source
SOURCES = [
Source(make_visits, name='demo'),
]
Expand Down Expand Up @@ -230,7 +230,7 @@ def test_index_many(tdir: Path) -> None:
cfg = tdir / 'test_config.py'
cfg.write_text(f"""
from datetime import datetime, timedelta
from promnesia import Source, Visit, Loc
from promnesia.common import Source, Visit, Loc
# TODO def need to allow taking in index function without having to wrap in source?
def index():
for i in range(100000):
Expand All @@ -255,7 +255,7 @@ def test_indexing_error(tdir: Path) -> None:
def bad_index():
import bad_import
yield from [] # dummy
from promnesia import Source
from promnesia.common import Source
from promnesia.sources import demo

SOURCES = [
Expand Down Expand Up @@ -297,7 +297,7 @@ def test_concurrent_indexing(tmp_path: Path, execution_number) -> None:
cfg_fast = tmp_path / 'config_fast.py'
cfg = dedent(f'''
OUTPUT_DIR = r'{tmp_path}'
from promnesia import Source
from promnesia.common import Source
from promnesia.sources import demo
SOURCES = [Source(demo.index, count=COUNT)]
''')
Expand Down
2 changes: 1 addition & 1 deletion tests/server_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def test_query_while_indexing(tmp_path: Path) -> None:
cfg.write_text(dedent(f'''
OUTPUT_DIR = r'{tmp_path}'

from promnesia import Source
from promnesia.common import Source
from promnesia.sources import demo
# index stupid amount of visits to increase time spent in database serialization
SOURCES = [Source(demo.index, count=100000)]
Expand Down