Skip to content
This repository was archived by the owner on Dec 26, 2025. It is now read-only.

Commit bf62cbb

Browse files
committed
Switched to Makefile
1 parent 267d156 commit bf62cbb

8 files changed

Lines changed: 90 additions & 60 deletions

File tree

Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
PYTHON = python
2+
PIP = pip
3+
VENV_DIR = venv
4+
5+
VER = $(shell git describe --tags)
6+
VERSION = $(firstword $(subst -, ,$(VER)))
7+
ifeq ($(shell git diff --name-only),)
8+
UNCLEAN = "False"
9+
else
10+
UNCLEAN = "True"
11+
endif
12+
13+
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
14+
15+
ifeq ($(OS),Windows_NT)
16+
VENV_BIN = $(VENV_DIR)/Scripts
17+
PIP = $(VENV_BIN)/pip.exe
18+
FLAKE8 = $(VENV_BIN)/flake8.exe
19+
ifeq ($(shell if test -d $(VENV_DIR); then echo "exist";fi),exist)
20+
PYTHON = $(VENV_BIN)/python.exe
21+
endif
22+
else
23+
VENV_BIN = $(VENV_DIR)/bin
24+
PIP = $(VENV_BIN)/pip
25+
FLAKE8 = $(VENV_BIN)/flake8
26+
ifeq ($(shell if test -d $(VENV_DIR); then echo "exist";fi),exist)
27+
PYTHON = $(VENV_BIN)/python
28+
endif
29+
endif
30+
31+
NO_OBSOLETE=
32+
33+
all: src/adif_file/__version__.py
34+
35+
src/adif_file/__version__.py:
36+
echo __version__ = \'$(VERSION)\' > $@
37+
echo __version_str__ = \'$(VER)\' >> $@
38+
echo __branch__ = \'$(BRANCH)\' >> $@
39+
echo __unclean__ = $(UNCLEAN) >> $@
40+
41+
dist: clean all test
42+
$(PYTHON) -m pip install --upgrade pip;
43+
$(PYTHON) -m pip install --upgrade build;
44+
$(PYTHON) -m build;
45+
46+
release:
47+
$(PYTHON) -m pip install --upgrade twine;
48+
$(PYTHON) -m twine upload dist/*;
49+
50+
test: all
51+
$(FLAKE8) ./src --count --select=E9,F63,F7,F82 --show-source --statistics
52+
$(FLAKE8) ./src --count --max-complexity=15 --max-line-length=120 --statistics
53+
PYTHONPATH=./src $(PYTHON) -m unittest discover -s ./test
54+
55+
build_devenv:
56+
if [ ! -d $(VENV_DIR) ]; then \
57+
$(PYTHON) -m venv $(VENV_DIR); \
58+
$(PIP) install --upgrade pip setuptools wheel; \
59+
$(PIP) install -r requirements.txt; \
60+
else \
61+
echo "Virtualenv $(VENV_DIR) already exists"; \
62+
fi
63+
64+
.PHONY: src/adif_file/__version__.py test clean_devenv build_devenv
65+
66+
clean:
67+
rm -rf build
68+
rm -rf dist
69+
rm -f src/hamcc/__version__.py
70+
rm -f
71+
72+
clean_devenv:
73+
rm -r venv
74+

build.bat

Lines changed: 0 additions & 23 deletions
This file was deleted.

build.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

make.bat

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@echo off
2+
set PATH=C:\cygwin64\bin;%PATH%
3+
4+
echo Invoking make %* ...
5+
make.exe %*

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
xmlschema~=2.5.0
2-
xmltodict~=0.13.0
2+
xmltodict~=0.13.0
3+
flake8

src/adif_file/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Convert ADIF ADI/ADX content to dictionary and vice versa"""
22

3-
from adif_file.__version__ import __version__ as __version_str__
3+
from adif_file.__version__ import __version__, __version_str__ # noqa: F401
44

55
__author_name__ = 'Andreas Schawo, DF1ASC'
66
__author_email__ = 'andreas@schawo.de'
77
__copyright__ = 'Copyright 2023-2024 by Andreas Schawo,licensed under CC BY-SA 4.0'
88
__proj_name__ = 'PyADIF-File'
9-
__version__ = __version_str__[1:].split('-')[0]
9+
__version__ = __version__[1:]
1010
__description__ = 'Convert ADIF ADI/ADX content to dictionary and vice versa'

src/adif_file/adi.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import datetime
66
from collections.abc import Iterator
77

8-
from adif_file.__version__ import __version__ as __version_str__
9-
10-
__proj_name__ = 'PyADIF-File'
11-
__version__ = __version_str__[1:].split('-')[0]
8+
from . import __version_str__, __proj_name__
129

1310

1411
class TooMuchHeadersException(Exception):
@@ -215,7 +212,7 @@ def dumpi(data_dict: dict, comment: str = 'ADIF export by ' + __proj_name__,
215212
if 'HEADER' in data_dict:
216213
default = {'ADIF_VER': '3.1.4',
217214
'PROGRAMID': __proj_name__,
218-
'PROGRAMVERSION': __version__,
215+
'PROGRAMVERSION': __version_str__,
219216
'CREATED_TIMESTAMP': datetime.datetime.utcnow().strftime('%Y%m%d %H%M%S')
220217
# TODO: Fix deprication > 3.10: datetime.datetime.now(tz=datetime.UTC).strftime('%Y%m%d %H%M%S')
221218
}

src/adif_file/adx.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import xmlschema
1111
import xmltodict
1212

13-
from adif_file.__version__ import __version__ as __version_str__
14-
15-
__proj_name__ = 'PyADIF-File'
16-
__version__ = __version_str__[1:].split('-')[0]
13+
from . import __version_str__, __proj_name__
1714

1815
ADX_EXPORT_SCHEMA = xmlschema.XMLSchema(os.path.join(os.path.dirname(__file__), 'xsd/adx314.xsd'))
1916
ADX_IMPORT_SCHEMA = xmlschema.XMLSchema(os.path.join(os.path.dirname(__file__), 'xsd/adx314generic.xsd'))
@@ -55,10 +52,9 @@ def loads(adx_data: str, validate: bool = False) -> dict:
5552
raise MalformedValueException(f'Field "{exc.elem.tag}": {exc.reason}') from None
5653

5754
try:
58-
data_dict = xmltodict.parse(adx_data, cdata_key='$')
59-
data_dict = data_dict['ADX']
60-
if ('RECORDS' in data_dict and data_dict['RECORDS'] and
61-
'RECORD' in data_dict['RECORDS'] and data_dict['RECORDS']['RECORD']):
55+
data_dict = xmltodict.parse(adx_data, cdata_key='$')['ADX']
56+
if all(('RECORDS' in data_dict, bool(data_dict['RECORDS']),
57+
'RECORD' in data_dict['RECORDS'], bool(data_dict['RECORDS']['RECORD']))):
6258
data_dict['RECORDS'] = data_dict['RECORDS']['RECORD']
6359
else:
6460
data_dict['RECORDS'] = []
@@ -98,7 +94,7 @@ def dump(file_name: str, data_dict: dict, raise_exc=True) -> list[Exception]:
9894
header = {
9995
'ADIF_VER': '3.1.4',
10096
'PROGRAMID': __proj_name__,
101-
'PROGRAMVERSION': __version__,
97+
'PROGRAMVERSION': __version_str__,
10298
'CREATED_TIMESTAMP': datetime.datetime.utcnow().strftime('%Y%m%d %H%M%S')
10399
}
104100

0 commit comments

Comments
 (0)