Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

8 changes: 1 addition & 7 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down
18 changes: 0 additions & 18 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
************
Installation
************

Requirements
============

- `Python <http://www.python.org/>`_ 2.7 or 3.X (recommended >=3.5)

- `Numpy <http://www.numpy.org>`_ (>=1.1)

Optional requirement
--------------------

- `netCDF4 <https://pypi.python.org/pypi/netCDF4>`_, if you want to be able to export the data into netCDF files.

- `CoTeDe <http://cotede.castelao.net>`_, if you want to quality control your data with custom or pre-set group of checks.

Installing Seabird
==================

Expand Down
18 changes: 14 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ 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",
"Intended Audience :: Science/Research",
"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 = [
Expand All @@ -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"

Expand All @@ -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"]
2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

8 changes: 3 additions & 5 deletions seabird/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 10 additions & 16 deletions seabird/cnv.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 = {}
# ----
Expand Down Expand Up @@ -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()

Expand All @@ -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 (
Expand Down
Empty file added seabird/rules/__init__.py
Empty file.
16 changes: 7 additions & 9 deletions seabird/utils.py
Original file line number Diff line number Diff line change
@@ -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")


Expand Down Expand Up @@ -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())
Expand Down
16 changes: 7 additions & 9 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@
""" 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():
"""Try to read all 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