Skip to content

Commit 984f871

Browse files
authored
89 use tox and tox env change to supporting 38 (#91)
* tox updates * test updates * rm old log files * update tests * recover unicode compare test * refactor * tests * logging * logging * rm old test dir * update Makefile * windows testing * logging * docs * Last 0.2.7b1 commit
1 parent 2192ae8 commit 984f871

36 files changed

Lines changed: 1940 additions & 278640 deletions

CHANGES.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ v0.0.6:
1010
2018-10-04 -- Improve dateticks.py
1111
2018-10-04 -- Add hapi_demo.ipynb
1212
2018-10-04 -- Other documentation improvements
13-
v0.0.7:
13+
v0.0.7:
1414
2018-10-06 -- Improve documentation
1515
2018-10-06 -- Add reader tests
1616
2018-10-23 -- Improve dateticks and tests
@@ -107,4 +107,7 @@ v0.2.6:
107107
v0.2.7b1:
108108
2025-03-01 -- Unrecognized ISO 8601 time format: '00:00:00.Z' https://github.com/hapi-server/client-python/issues/76
109109
2025-03-01 -- 'infer_datetime_format' is deprecated ... https://github.com/hapi-server/client-python/issues/78
110-
2026-04-08 -- Improve NaN handling https://github.com/hapi-server/client-python/issues/88
110+
2026-04-08 -- Improve NaN handling https://github.com/hapi-server/client-python/issues/88
111+
2026-05-02 -- Logging and testing https://github.com/hapi-server/client-python/issues/89
112+
0.2.7:
113+
2026--05-02-- Support for Python 2.7 dropped. This is last release with support for 3.5 through 3.8.

Makefile

Lines changed: 80 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
# Test hapi() data read functions using repository code:
1+
# Test in Conda virtual environments (to be deprecated):
22
# make repository-test PYTHON=_PYTHON_ # Test using _PYTHON_ (e.g, python3.6)
33
# make repository-test-all # Test on all versions in $(PYTHONVERS) var below
44
#
5+
# Test using tox (See also README.md for additional instructions):
6+
# tox
7+
#
58
# Beta releases:
6-
# 1. Run make repository-test-all
9+
# 1. tox
10+
# 2. make repository-test-all # (To be deprecated)
711
# 2. For non-doc/formatting changes, update version in CHANGES.txt.
812
# 3. run `make version-update` if version changed in CHANGES.txt.
913
# 4. Commit and push
@@ -45,24 +49,30 @@ PYTHON=python3.8
4549
PYTHON_VER=$(subst python,,$(PYTHON))
4650

4751
# Python versions to test
48-
PYTHONVERS=python3.13 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7 python3.6 python3.5
52+
PYTHONVERS=python3.14 python3.13 python3.12 python3.11 python3.10 python3.9 python3.8 python3.7 python3.6
4953

5054
# VERSION is updated in "make version-update" step and derived
5155
# from CHANGES.txt. Do not edit.
5256
VERSION=0.2.7b1
5357
SHELL:= /bin/bash
54-
#SHELL:= /c/Windows/system32/cmd
5558

5659
LONG_TESTS=false
5760

58-
CONDA=$(PWD)/anaconda3
61+
CONDA=$(CURDIR)/anaconda3
5962

6063
ifeq ($(OS),Windows_NT)
61-
CONDA=C:/Users/weigel/git/client-python/anaconda3
62-
TMP=tmp/
64+
CONDA=$(CURDIR)/anaconda3
6365
endif
66+
#TOS1=conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
67+
#TOS2=conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
6468
CONDA_ACTIVATE=source $(CONDA)/etc/profile.d/conda.sh; conda activate
6569

70+
ifeq ($(OS),Windows_NT)
71+
CONDA_RUN=$(CONDA)/Scripts/conda.exe run -n $(PYTHON)
72+
else
73+
CONDA_RUN=$(CONDA_ACTIVATE) $(PYTHON);
74+
endif
75+
6676
################################################################################
6777
install: $(CONDA)/envs/$(PYTHON)
6878
$(CONDA_ACTIVATE) $(PYTHON); pip install --editable .
@@ -73,26 +83,6 @@ install: $(CONDA)/envs/$(PYTHON)
7383
test:
7484
make repository-test-all
7585

76-
####################################################################
77-
# Tox notes
78-
#
79-
# Ideally local tests would use same commands as .tox.ini and .travis.yml.
80-
#
81-
# To use tox -e short-test, it seems we need to install and activate
82-
# each version of python. So using tox locally does not seem to make
83-
# things much simpler than `make repository-test`, which installs
84-
# conda and virtual enviornments and runs tests.
85-
#
86-
# However, Travis tests use tox-travis and it seems creation of
87-
# virtual environment is done automatically.
88-
#
89-
#repository-test-all-tox:
90-
# tox -e short-test
91-
#repository-test-tox:
92-
# # Does not work
93-
# tox -e py$(subst .,,$(PYTHON_VER)) short-test
94-
####################################################################
95-
9686
# Test contents in repository using different Python versions
9787
repository-test-all:
9888
@make clean
@@ -104,63 +94,86 @@ repository-test-all:
10494
repository-test:
10595
@make clean
10696
make condaenv PYTHON=$(PYTHON)
107-
$(CONDA_ACTIVATE) $(PYTHON); pip install pytest deepdiff; pip install .
97+
$(CONDA_RUN) pip install pytest deepdiff
98+
$(CONDA_RUN) pip install .
10899

109-
ifeq (LONG_TESTS,true)
110-
$(CONDA_ACTIVATE) $(PYTHON); python -m pytest --tb=short -v -m 'long' hapiclient/test/test_hapi.py
100+
ifeq ($(LONG_TESTS),true)
101+
$(CONDA_RUN) python -m pytest -m "long" test
111102
else
112-
$(CONDA_ACTIVATE) $(PYTHON); python -m pytest --tb=short -v -m 'short' hapiclient/test/test_hapi.py
103+
$(CONDA_RUN) python -m pytest -m "not long" test
113104
endif
114-
115-
$(CONDA_ACTIVATE) $(PYTHON); python -m pytest -v hapiclient/test/test_chunking.py
116-
$(CONDA_ACTIVATE) $(PYTHON); python -m pytest -v hapiclient/test/test_hapitime2datetime.py
117-
$(CONDA_ACTIVATE) $(PYTHON); python -m pytest -v hapiclient/test/test_datetime2hapitime.py
118-
$(CONDA_ACTIVATE) $(PYTHON); python -m pytest -v hapiclient/test/test_hapitime_reformat.py
119105
################################################################################
120106

121107
################################################################################
122108
# Anaconda install
109+
ifeq ($(OS),Windows_NT)
110+
CONDA_PKG=Miniconda3-latest-Windows-x86_64.exe
111+
CONDA_PKG_PATH=C:/tmp/$(CONDA_PKG)
112+
else
113+
UNAME_S:=$(shell uname -s)
114+
UNAME_M:=$(shell uname -m)
115+
116+
ifeq ($(UNAME_S),Linux)
123117
CONDA_PKG=Miniconda3-latest-Linux-x86_64.sh
124-
CONDA_PKG_PATH=/tmp/$(CONDA_PKG)
125-
ifeq ($(shell uname -s),Darwin)
126-
CONDA_PKG=Miniconda3-latest-MacOSX-x86_64.sh
127-
CONDA_PKG_PATH=/tmp/$(CONDA_PKG)
118+
ifeq ($(UNAME_M),aarch64)
119+
CONDA_PKG=Miniconda3-latest-Linux-aarch64.sh
128120
endif
129-
ifeq ($(OS),Windows_NT)
130-
CONDA_PKG=Miniconda3-latest-Windows-x86_64.exe
131-
CONDA_PKG_PATH=C:/tmp/$(CONDA_PKG)
121+
endif
122+
123+
ifeq ($(UNAME_S),Darwin)
124+
CONDA_PKG=Miniconda3-latest-MacOSX-x86_64.sh
125+
ifeq ($(UNAME_M),arm64)
126+
CONDA_PKG=Miniconda3-latest-MacOSX-arm64.sh
127+
endif
128+
endif
129+
130+
CONDA_PKG_PATH=/tmp/$(CONDA_PKG)
132131
endif
133132

134133
activate:
135134
@echo "On command line enter:"
136135
@echo "$(CONDA_ACTIVATE) $(PYTHON)"
137136

138137
condaenv:
139-
make $(CONDA)/envs/$(PYTHON) PYTHON=$(PYTHON)
138+
$(MAKE) $(CONDA)/envs/$(PYTHON) PYTHON=$(PYTHON)
140139

141140
$(CONDA)/envs/$(PYTHON): $(CONDA)
142141
ifeq ($(OS),Windows_NT)
143-
$(CONDA_ACTIVATE); \
144-
$(CONDA)/Scripts/conda \
145-
create -y --name $(PYTHON) python=$(PYTHON_VER)
142+
$(CONDA)/Scripts/conda.exe tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main
143+
$(CONDA)/Scripts/conda.exe tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r
144+
$(CONDA)/Scripts/conda.exe tos accept --override-channels --channel https://repo.anaconda.com/pkgs/msys2
145+
$(CONDA)/Scripts/conda.exe create -y --name $(PYTHON) python=$(PYTHON_VER)
146146
else
147147
$(CONDA_ACTIVATE); \
148+
$(CONDA)/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/main; \
149+
$(CONDA)/bin/conda tos accept --override-channels --channel https://repo.anaconda.com/pkgs/r; \
148150
$(CONDA)/bin/conda \
149151
create -y --name $(PYTHON) python=$(PYTHON_VER)
150152
endif
151153

152-
$(CONDA): $(CONDA_PKG_PATH)
153154
ifeq ($(OS),Windows_NT)
154-
# Not working; path is not set
155-
#start "$(CONDA_PKG_PATH)" /S /D=$(CONDA)
156-
echo "!!! Install miniconda3 into $(CONDA) manually by executing 'start $(PWD)/anaconda3'. Then re-execute make command."
157-
exit 1
155+
$(CONDA):
156+
@powershell -NoProfile -Command "$$ErrorActionPreference='Stop'; \
157+
$$pkg = '$(CONDA_PKG)'; \
158+
if ([string]::IsNullOrWhiteSpace($$pkg)) { $$pkg = 'Miniconda3-latest-Windows-x86_64.exe' }; \
159+
$$tempDir = [System.IO.Path]::GetTempPath(); \
160+
if ([string]::IsNullOrWhiteSpace($$tempDir)) { $$tempDir = 'C:\\Windows\\Temp' }; \
161+
New-Item -ItemType Directory -Force -Path $$tempDir | Out-Null; \
162+
$$installer = Join-Path $$tempDir $$pkg; \
163+
$$url = 'https://repo.anaconda.com/miniconda/' + $$pkg; \
164+
$$condaExe = Join-Path '$(CONDA)' 'Scripts/conda.exe'; \
165+
if (Test-Path $$condaExe) { exit 0 }; \
166+
if (!(Test-Path $$installer)) { Invoke-WebRequest -Uri $$url -OutFile $$installer }; \
167+
$$target = [System.IO.Path]::GetFullPath('$(CONDA)').Replace('/','\\'); \
168+
Start-Process -FilePath $$installer -ArgumentList '/InstallationType=JustMe','/RegisterPython=0','/AddToPath=0','/S',('/D=' + $$target) -Wait -NoNewWindow; \
169+
if (!(Test-Path $$condaExe)) { throw 'Miniconda install failed.' }"
158170
else
171+
$(CONDA): $(CONDA_PKG_PATH)
159172
test -d anaconda3 || bash $(CONDA_PKG_PATH) -b -p $(CONDA)
160-
endif
161173

162174
$(CONDA_PKG_PATH):
163-
curl https://repo.anaconda.com/miniconda/$(CONDA_PKG) > $(CONDA_PKG_PATH)
175+
curl -L -o $(CONDA_PKG_PATH) https://repo.anaconda.com/miniconda/$(CONDA_PKG)
176+
endif
164177
################################################################################
165178

166179
################################################################################
@@ -265,17 +278,23 @@ test-clean:
265278
################################################################################
266279

267280
clean:
268-
- @find . -name __pycache__ | xargs rm -rf {}
269-
- @find . -name *.pyc | xargs rm -rf {}
270-
- @find . -name *.DS_Store | xargs rm -rf {}
271-
- @find . -type d -name __pycache__ | xargs rm -rf {}
272-
- @find . -name *.pyc | xargs rm -rf {}
281+
282+
ifeq ($(OS),Windows_NT)
283+
- @powershell -NoProfile -Command "Get-ChildItem -Path . -Recurse -Directory -Filter '__pycache__' -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue"
284+
- @powershell -NoProfile -Command "Get-ChildItem -Path . -Recurse -File -Include '*.pyc','*.DS_Store' -ErrorAction SilentlyContinue | Remove-Item -Force -ErrorAction SilentlyContinue"
285+
- @powershell -NoProfile -Command "Remove-Item -Path '*~' -Force -ErrorAction SilentlyContinue"
286+
- @powershell -NoProfile -Command "Remove-Item -Path '#*#' -Force -ErrorAction SilentlyContinue"
287+
- @powershell -NoProfile -Command "Remove-Item -Path 'env','dist','.pytest_cache','hapiclient.egg-info' -Recurse -Force -ErrorAction SilentlyContinue"
288+
- @powershell -NoProfile -Command "Remove-Item -Path '/c/tools/miniconda3/envs/python3.6/Scripts/wheel.exe*','/c/tools/miniconda3/envs/python3.6/vcruntime140.dll.*' -Force -ErrorAction SilentlyContinue"
289+
else
290+
- @find . -type d -name __pycache__ -exec rm -rf {} +
291+
- @find . -type f -name '*.pyc' -exec rm -f {} +
292+
- @find . -type f -name '*.DS_Store' -exec rm -f {} +
273293
- @rm -f *~
274294
- @rm -f \#*\#
275295
- @rm -rf env
276296
- @rm -rf dist
277297
- @rm -f MANIFEST
278298
- @rm -rf .pytest_cache/
279299
- @rm -rf hapiclient.egg-info/
280-
- @rm -rf /c/tools/miniconda3/envs/python3.6/Scripts/wheel.exe*
281-
- @rm -rf /c/tools/miniconda3/envs/python3.6/vcruntime140.dll.*
300+
endif

README.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ start = '2003-09-01T00:00:00'
3939
stop = '2003-12-01T00:00:00'
4040
parameters = 'DST1800'
4141
opts = {'logging': True}
42+
# See misc/hapi_logging_demo.py for example of using conventional Python logging.
4243

4344
# Get data
4445
data, meta = hapi(server, dataset, parameters, start, stop, **opts)
@@ -81,7 +82,41 @@ returns the [Numpy N-D array](https://docs.scipy.org/doc/numpy-1.15.1/user/quick
8182

8283
The HAPI client data model is intentionally basic. There is an ongoing discussion of a data model for Heliophysics data among the [PyHC community](https://heliopython.org/). When this data model is complete, a function that converts `data` and `meta` to that data model will be included in the `hapiclient` package.
8384

84-
# Development
85+
# Development and Testing
86+
87+
## Testing Python versions available with tox-env
88+
89+
As of 2026-04-14, Python 3.8+ is available with tox-env.
90+
91+
```bash
92+
git clone https://github.com/hapi-server/client-python
93+
cd client-python; python -m pip install -e .
94+
95+
# Run a specific test on current Python version (default is log_level=INFO
96+
# for hapiclient logger and test logger when executed this way).
97+
python test/test_hapi_data_requests.py
98+
99+
# Run a specific test on a specific Python version with all logging
100+
tox -e py311 -- test/test_hapi_data_requests.py
101+
# Set log level for test logger
102+
tox -e py311 -- test/test_hapi_data_requests.py --log-level=INFO
103+
104+
# Run a specific test on all Python versions set by tox.ini `envlist`
105+
tox -- test/test_hapi_data_requests.py
106+
107+
# Run all tests in ./test
108+
tox
109+
110+
# Run long-running tests
111+
tox -e long-test
112+
113+
# Run long-running tests on a specific Python version
114+
tox -e long-test --override testenv:long-test.basepython=python3.11
115+
```
116+
117+
## Testing Python versions available with Anaconda
118+
119+
As of 2026-04-14, Python 3.5+ is available with Anaconda.
85120

86121
```bash
87122
git clone https://github.com/hapi-server/client-python
@@ -106,12 +141,13 @@ make repository-test
106141

107142
To run an individual unit test in a Python session, use, e.g.,
108143

109-
```python
110-
from hapiclient.test.test_hapi import test_reader_short
111-
test_reader_short()
144+
```bash
145+
cd test; python test_hapitime_reformat.py
112146
```
113147

114148
# Contact
115149

116150
Submit bug reports and feature requests on the [repository issue
117151
tracker](https://github.com/hapi-server/client-python/issues>).
152+
153+
Before submitting a pull request, please post an issue with the proposed changes for discussion prior to developing the pull request.

0 commit comments

Comments
 (0)