Skip to content

Commit 2f3f29f

Browse files
Merge branch 'develop'
Release 3.3.9
2 parents b1ecd1c + 7aeaed0 commit 2f3f29f

File tree

4 files changed

+84
-14
lines changed

4 files changed

+84
-14
lines changed

.github/workflows/publish.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Publish a new version to PyPI when a new release is published
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
pypi-publish:
9+
name: Publish release to PyPI
10+
runs-on: ubuntu-latest
11+
environment:
12+
name: pypi
13+
url: https://pypi.org/p/dnaStreaming
14+
permissions:
15+
id-token: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: "3.8"
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install setuptools wheel build
26+
- name: Build package
27+
run: |
28+
python -m build
29+
- name: Publish package distributions to PyPI
30+
uses: pypa/gh-action-pypi-publish@release/v1

README.rst

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ To set your subscription ID, simply set an environment variable named 'SUBSCRIPT
4141
export SUBSCRIPTION_ID="ABC1234567889"
4242
4343
44-
The code above is the command line expression for setting this environment variable on Mac OSX. Other operating systems might have a slightly different techniques for setting environment variables on the command line.
44+
To set your log folder path, simply set this folder variable named 'LOG_PATH' like so
45+
46+
.. code-block::
47+
48+
export LOG_PATH="/your/custom/log/path"
49+
50+
4551
4652
2. Using the configuration file.
4753
###################################################################
@@ -121,7 +127,25 @@ You may want to listen messages asynchronously like so:
121127
Log Files
122128
_________
123129

124-
Very minimal logging is written to the module's path 'logs/dj-dna-streaming-python.log'. To keep maintenance simple this log is overwritten every time the app starts.
130+
131+
Minimal logging is written to a file named `dj-dna-streaming-python.log`.
132+
133+
By default, logs are written to the first available directory from the following list:
134+
135+
1. A custom path set via the environment variable `LOG_PATH`.
136+
2. A `logs/` folder located within the package installation directory.
137+
3. A fallback directory: `~/.dj-dna-streaming-python/logs/`.
138+
139+
The first writable location found is selected. A message like `Will log to: /your/custom/log/path` is printed to the console on startup.
140+
141+
💡 The log file is overwritten each time the application starts to keep maintenance simple.
142+
143+
You can specify:
144+
145+
- **Absolute paths**: For example, `/var/log/dna-streaming`.
146+
- **Relative paths**: For example, `./logs`, relative to the current working directory at runtime.
147+
148+
The code verifies that the specified path is writable. If it isn’t, it automatically falls back to the next available option.
125149

126150

127151
Testing

dnaStreaming/__init__.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,37 @@
55
import logging
66

77

8-
BASE_DIR = os.path.dirname(__file__)
8+
def get_log_path():
9+
env_log_path = os.getenv("LOG_PATH")
10+
fallback_log_dir = os.path.expanduser('~/.dj-dna-streaming-python/logs')
11+
base_dir = os.path.dirname(__file__)
12+
default_path = os.path.join(base_dir, 'logs')
13+
14+
candidates = [env_log_path, default_path, fallback_log_dir]
15+
16+
for path in candidates:
17+
if path:
18+
try:
19+
os.makedirs(path, exist_ok=True)
20+
testfile = os.path.join(path, '.write_test')
21+
with open(testfile, 'w') as f:
22+
f.write('test')
23+
os.remove(testfile)
24+
return path
25+
except Exception as e:
26+
print(f"WARNING: Cannot write to '{path}': {e}")
27+
28+
raise RuntimeError("ERROR: Could not find a writable log directory.")
29+
30+
31+
log_path = get_log_path()
32+
print("Will log to: {}".format(log_path))
933

34+
# Logging setup
1035
logging.basicConfig(level=logging.WARN)
11-
1236
logger = logging.getLogger()
1337

14-
log_path = os.path.join(BASE_DIR, 'logs')
15-
16-
print("Will log to: {}".format(log_path))
17-
18-
if not os.path.exists(log_path):
19-
os.mkdir(log_path)
20-
21-
fileHandler = logging.FileHandler("{0}/{1}.log".format(log_path, 'dj-dna-streaming-python'))
22-
38+
fileHandler = logging.FileHandler(os.path.join(log_path, 'dj-dna-streaming-python.log'))
2339
logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")
2440
fileHandler.setFormatter(logFormatter)
2541
logger.addHandler(fileHandler)

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# and then run "tox" from this directory.
55

66
[tox]
7-
envlist = py37
7+
envlist = py38
88

99
[testenv]
1010
commands = py.test

0 commit comments

Comments
 (0)