diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 93e4569..25ddccf 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -4,37 +4,33 @@ on:
push:
branches: [ main ]
pull_request:
- branches: [ main ]
schedule:
- cron: "7 18 * * 0"
jobs:
build:
-
+ name: unit-test py${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
- python-version: ["3.7", "3.8", "3.9", "3.10"]
+ python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
+
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v4
with:
fetch-depth: 0
- - name: Set up Python ${{ matrix.python-version }}
- uses: actions/setup-python@v4
+ - name: "Set up Python ${{ matrix.python-version }}"
+ uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
-
+
- name: Install dependencies
run: |
- python -m pip install --upgrade pip
- pip install flake8 pytest
- if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- pip install -e .[test]
+ pip install .[test]
- name: Test with pytest
- run: |
- pytest tests
+ run: pytest
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 8d89d41..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,40 +0,0 @@
-language: python
-
-sudo: false
-
-python:
- - "2.7"
- - "3.5"
- - "3.6"
- - "3.7"
-
-before_install:
- - if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
- wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
- else
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
- fi
- - bash miniconda.sh -b -p $HOME/miniconda
- - export PATH="$HOME/miniconda/bin:$PATH"
- - hash -r
- - conda config --set always_yes yes --set changeps1 no
- - conda update -q conda
- # Useful for debugging any issues with conda
- - conda info -a
-
-install:
- - conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION pip numpy pytest
- - source activate test-environment
- - pip install -r requirements_dev.txt
- - pip install codecov pytest-cov
- - python setup.py install
-
-before_script:
- # Download the required sample data files.
- - python -c "import seabird.utils; seabird.utils.sampledata()"
-
-script:
- - py.test --cov --cov-report=term-missing -vv
-
-after_success:
- - codecov
diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index a017c16..72a49b7 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -66,13 +66,7 @@ Ready to contribute? Here's how to set up `seabird` for local development.
a. Using Conda (assuming you already have it installed)
- I. Python 2::
-
- $ conda create --name seabird python=2
-
- II. Or, Python 3::
-
- $ conda create --name seabird python=3
+ $ conda create --name seabird python=3.10
Activate your conda environment, and take advantage of conda::
diff --git a/docs/source/install.rst b/docs/source/install.rst
index afcd5be..076325f 100644
--- a/docs/source/install.rst
+++ b/docs/source/install.rst
@@ -1,21 +1,3 @@
-************
-Installation
-************
-
-Requirements
-============
-
-- `Python `_ 2.7 or 3.X (recommended >=3.5)
-
-- `Numpy `_ (>=1.1)
-
-Optional requirement
---------------------
-
-- `netCDF4 `_, if you want to be able to export the data into netCDF files.
-
-- `CoTeDe `_, if you want to quality control your data with custom or pre-set group of checks.
-
Installing Seabird
==================
diff --git a/pyproject.toml b/pyproject.toml
index becf56d..eb309d8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -12,8 +12,9 @@ name="seabird"
dynamic = ["version"]
description="Parser for Sea-Bird's CTD and TSG"
readme = "README.rst"
-requires-python = ">=3.6"
+requires-python = ">=3.9"
keywords = ["oceanography", "ocean data", "CTD", "TSG", "SeaBird", "hydrography", "parser"]
+license = {file = "LICENSE.rst"}
classifiers=[
"Development Status :: 5 - Production/Stable",
"Natural Language :: English",
@@ -21,11 +22,11 @@ classifiers=[
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
- "Programming Language :: Python :: 3.6",
- "Programming Language :: Python :: 3.7",
- "Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
+ "Programming Language :: Python :: 3.11",
+ "Programming Language :: Python :: 3.12",
+ "Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering"
]
dependencies = [
@@ -51,6 +52,8 @@ QC = ["cotede>=0.20.2"]
[project.urls]
repository = "https://github.com/castelao/seabird"
+documentation = "https://seabird.readthedocs.io"
+
[project.scripts]
"seabird" = "seabird.cli:cli"
@@ -60,3 +63,10 @@ line-length = 88
[tool.setuptools_scm]
write_to = "seabird/version.py"
git_describe_command = "git describe --dirty --tags --long --match 'v*' --first-parent"
+
+[tool.pytest.ini_options]
+minversion = "6.0"
+testpaths = [
+ "tests",
+]
+filterwarnings = ["error"]
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index 68b129e..0000000
--- a/requirements.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-numpy>=1.14
-Click>=6.6
diff --git a/seabird/__init__.py b/seabird/__init__.py
index 4172e67..9c6b7ad 100644
--- a/seabird/__init__.py
+++ b/seabird/__init__.py
@@ -3,15 +3,13 @@
from .cnv import CNV, fCNV
from .exceptions import CNVError
+import importlib.metadata
# __all__ = ['CNV', 'fCNV']
-
-from pkg_resources import get_distribution, DistributionNotFound
-
try:
- __version__ = get_distribution(__name__).version
-except DistributionNotFound:
+ __version__ = importlib.metadata.version(__name__)
+except Exception:
try:
from .version import version as __version__
except ImportError:
diff --git a/seabird/cnv.py b/seabird/cnv.py
index a7c3244..1f6c5c2 100644
--- a/seabird/cnv.py
+++ b/seabird/cnv.py
@@ -1,20 +1,13 @@
from datetime import datetime, timedelta
import re
-import pkg_resources
+import importlib.resources
import os
import logging
import struct
import json
+from . import rules
+import hashlib
-try:
- import hashlib
-
- md5 = hashlib.md5
-except ImportError:
- # for Python << 2.5
- import md5
-
- md5 = md5.new
# import codecs
import numpy as np
@@ -53,7 +46,7 @@ def __init__(self, raw_text, defaults=None):
module_logger.debug("Initializing CNV class")
# Clean empty lines first
- self.raw_text = re.sub("\n\s*(?=\n)", "", raw_text)
+ self.raw_text = re.sub(r"\n\s*(?=\n)", "", raw_text)
self.defaults = defaults
self.attrs = {}
# ----
@@ -150,9 +143,9 @@ def get_attrs(self):
# ----
# Temporary solution. Failsafe MD5
try:
- self.attrs["md5"] = md5(self.raw_text.encode("utf-8")).hexdigest()
+ self.attrs["md5"] = hashlib.md5(self.raw_text.encode("utf-8")).hexdigest()
except:
- self.attrs["md5"] = md5(
+ self.attrs["md5"] = hashlib.md5(
self.raw_text.decode("latin1", "replace").encode("utf-8")
).hexdigest()
@@ -162,9 +155,10 @@ def prepare_data(self):
self.data = []
self.ids = []
# ----
- rule_file = "rules/refnames.json"
- text = pkg_resources.resource_string(__name__, rule_file)
- refnames = json.loads(text.decode("utf-8"))
+
+ with importlib.resources.open_text(rules, "refnames.json") as file:
+ text = file.read()
+ refnames = json.loads(text)
# ---- Parse fields
if ("attributes" in self.rule) and (
diff --git a/seabird/rules/__init__.py b/seabird/rules/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/seabird/utils.py b/seabird/utils.py
index 476f450..0d3bfdf 100644
--- a/seabird/utils.py
+++ b/seabird/utils.py
@@ -1,13 +1,13 @@
import os
import re
import logging
-import pkg_resources
+import importlib.resources
import json
-# import codecs
-
+from seabird import rules
from seabird.exceptions import CNVError
+
module_logger = logging.getLogger("seabird.utils")
@@ -74,14 +74,12 @@ def load_rule(raw_text):
It should try all available rules, one by one, and use the one
which fits.
"""
- rules_dir = "rules"
- rule_files = pkg_resources.resource_listdir(__name__, rules_dir)
+ rule_files = [entry.name for entry in importlib.resources.files(rules).iterdir() if entry.is_file()]
rule_files = [f for f in rule_files if re.match(r"^cnv.*\.json$", f)]
for rule_file in rule_files:
- text = pkg_resources.resource_string(
- __name__, os.path.join(rules_dir, rule_file)
- )
- rule = json.loads(text.decode("utf-8"))
+ with importlib.resources.files(rules).joinpath(rule_file).open('r') as file:
+ text = file.read()
+ rule = json.loads(text)
# Should I load using codec, for UTF8?? Do I need it?
# f = codecs.open(rule_file, 'r', 'utf-8')
# rule = yaml.load(f.read())
diff --git a/tests/test_rules.py b/tests/test_rules.py
index 8d514d1..745af23 100644
--- a/tests/test_rules.py
+++ b/tests/test_rules.py
@@ -3,11 +3,10 @@
""" Check the rules
"""
-import os
-import pkg_resources
+import importlib.resources
import json
import re
-import seabird
+from seabird import rules
def test_load_available_rules():
@@ -15,14 +14,13 @@ def test_load_available_rules():
https://github.com/castelao/seabird/issues/7
"""
- rules_dir = "rules"
- rule_files = pkg_resources.resource_listdir(seabird.__name__, rules_dir)
+ rules_dir_path = importlib.resources.files(rules)
+ rule_files = [entry.name for entry in rules_dir_path.iterdir() if entry.is_file()]
rule_files = [f for f in rule_files if re.match("^(?!refnames).*json$", f)]
for rule_file in rule_files:
print("loading rule: %s", (rule_file))
- text = pkg_resources.resource_string(
- seabird.__name__, os.path.join(rules_dir, rule_file)
- )
- rule = json.loads(text.decode("utf-8"))
+ with importlib.resources.files(rules).joinpath(rule_file).open('r') as file:
+ text = file.read()
+ rule = json.loads(text)
assert type(rule) == dict
assert len(rule.keys()) > 0