Skip to content

Commit

Permalink
Merge pull request #22 from sarnold/add-reuse
Browse files Browse the repository at this point in the history
Add reuse config and cleanup; includes bug fix for #23
  • Loading branch information
sarnold authored Dec 15, 2024
2 parents 22c8c28 + 6aaa882 commit 9ae7240
Showing 8 changed files with 58 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -45,6 +45,6 @@ jobs:
- name: Run tests
run: |
tox
tox -- no
env:
PLATFORM: ${{ matrix.os }}
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
9 changes: 9 additions & 0 deletions LICENSES/MIT.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -101,6 +101,10 @@ adjustable via environment variables, and the following "extra" features:
* environment values are checked first; if not set, fallback to defaults
* logging using daemon package logger config

.. note:: The XDG runtime path may not exist in a console environment;
if so, the fallback is XDG user cache path.


Sample environment display with tox overrides, ie, inside a Tox_ venv::

Python version: 3.11.4 (main, Jul 5 2023, 16:15:04) [GCC 12.3.1 20230526]
26 changes: 26 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version = 1

[[annotations]]
path = [
"README.*",
"setup.py",
"setup.cfg",
"**/server.py",
]
SPDX-FileCopyrightText = [
"Copyright 2019 dheerajmpai and saenews",
"2022-2024 Stephen Arnold <sarnold@vctlabs.com>",
]
SPDX-License-Identifier = "MIT"

[[annotations]]
path = "toxfile.py"
SPDX-FileCopyrightText = "Copyright (c) 2023 Masen Furer"
SPDX-License-Identifier = "MIT"

[[annotations]]
path = "**"
SPDX-FileCopyrightText = [
"2022-2024 Stephen Arnold <sarnold@vctlabs.com>",
]
SPDX-License-Identifier = "MIT"
14 changes: 7 additions & 7 deletions src/pyserv/settings.py
Original file line number Diff line number Diff line change
@@ -18,8 +18,10 @@ def get_userdirs():
:return tuple: logdir, piddir, docdir as Path objs
"""
dirs = PlatformDirs(appname='pyserv', appauthor='nerdboy')
run_check = Path('/run/user').exists()
run_path = dirs.user_runtime_path if run_check else dirs.user_cache_path
logdir = dirs.user_log_path
piddir = dirs.user_runtime_path
piddir = run_path
docdir = Path(os.getcwd())
return logdir, piddir, docdir

@@ -35,13 +37,12 @@ def init_dirs(dirs):
usr_path.mkdir(parents=True, exist_ok=True)


def platform_check():
def platform_check() -> bool:
"""
Check to see if we think we are POSIX.
:return bool: True if POSIX, else False
:return we_are_posix: true if system is posix
"""
valid_os = []
myname = sys.platform
is_posix = os.name == 'posix'
posix_list = [
@@ -50,9 +51,8 @@ def platform_check():
'openbsd',
'freebsd',
]
valid_os = [x for x in posix_list if x in myname and is_posix]

return valid_os
we_are_posix = myname in posix_list and is_posix
return we_are_posix


def show_uservars():
11 changes: 8 additions & 3 deletions tests/test_extras.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
def test_get_userdirs():
"""We should get Path objs"""
logdir, piddir, docdir = get_userdirs()
print(f'PID dir: {piddir}')

for thing in logdir, piddir, docdir:
assert isinstance(thing, Path)
@@ -31,7 +32,7 @@ def test_get_userdirs():
else:
assert logdir.name == 'log'

assert piddir.name == 'pyserv'
assert piddir.name == 'pyserv' or 'Cache'
assert docdir.name == Path.cwd().name


@@ -47,10 +48,14 @@ def test_init_dirs(tmp_path):
assert thing.is_dir()


@pytest.mark.skipif(sys.platform == 'win32', reason="daemon not supported on Windows")
def test_platform_check():
"""Test for POSIX platform"""
assert platform_check()
iam_posix = platform_check()
if WIN32:
assert iam_posix is False
else:
assert iam_posix
print(f'posix check: {iam_posix}')


def test_show_uservars():
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ deps =
-e .[test,cov]

commands =
python -m pytest -v tests/ --capture=fd --cov=pyserv --cov-branch --cov-report term-missing
python -m pytest -v tests/ --capture={posargs:fd} --cov=pyserv --cov-branch --cov-report term-missing

[testenv:coverage]
basepython =
@@ -300,6 +300,7 @@ deps =
{[base]deps}
-r requirements.txt
pylint
reuse

commands =
pylint --fail-under=9.70 src/ scripts/

0 comments on commit 9ae7240

Please sign in to comment.