Skip to content

Commit

Permalink
More debug output and code reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
titusz committed Oct 19, 2024
1 parent 92364fd commit 75c1877
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 52 deletions.
25 changes: 23 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,38 @@ jobs:

- name: Install Dependencies (Pure Python)
if: ${{ !matrix.cython }}
run: poetry install --without dev,docs
run: |
poetry install --without dev,docs
poetry run python -c "import sys; print('Python version:', sys.version)"
poetry run python -c "import iscc_core; print('iscc_core version:', iscc_core.__version__)"
- name: Install Dependencies (with Cython)
if: ${{ matrix.cython }}
run: poetry install --without dev,docs --extras cython
run: |
poetry install --without dev,docs --extras cython
poetry run python -c "import sys; print('Python version:', sys.version)"
poetry run python -c "import iscc_core; print('iscc_core version:', iscc_core.__version__)"
poetry run python -c "import iscc_core; print('Using Cython:', iscc_core.USING_CYTHON)"
poetry run python -c "import iscc_core; print('iscc_core file:', iscc_core.__file__)"
poetry run python -c "import iscc_core.cdc; print('cdc module:', iscc_core.cdc.__file__)"
- name: Run Tests
run: |
poetry run python -c "import iscc_core; print(f'Using Cython: {iscc_core.USING_CYTHON}')"
poetry run pytest -v tests
- name: Debug Info
if: failure()
run: |
echo "Current directory:"
pwd
echo "Directory contents:"
ls -R
echo "Python version:"
python --version
echo "Pip list:"
pip list
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: matrix.os == 'ubuntu-20.04' && matrix.python-version == '3.9' && !matrix.cython
Expand Down
13 changes: 9 additions & 4 deletions build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
# -*- coding: utf-8 -*-
import os
from setuptools import Extension


import os
import sys


def build(setup_kwargs):
print(f"Python version: {sys.version}")
print(f"Current working directory: {os.getcwd()}")
print(f"Contents of current directory: {os.listdir('.')}")
print(f"Contents of iscc_core directory: {os.listdir('iscc_core')}")

try:
from Cython.Build import cythonize

Expand Down Expand Up @@ -36,7 +44,4 @@ def build(setup_kwargs):
else:
print("Cython not available, using pure Python")

print(f"Current working directory: {os.getcwd()}")
print(f"Contents of current directory: {os.listdir('.')}")
print(f"Contents of iscc_core directory: {os.listdir('iscc_core')}")
print(f"Setup kwargs: {setup_kwargs}")
15 changes: 10 additions & 5 deletions iscc_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import sys


def _using_cython_modules():
def _using_cython_modules(): # pragma: no cover
modules = ["cdc", "minhash", "simhash", "dct", "wtahash"]
return any(
getattr(sys.modules.get(f"iscc_core.{module}"), "__file__", "").endswith((".so", ".pyd"))
for module in modules
)
cython_modules = []
for module in modules:
module_path = getattr(sys.modules.get(f"iscc_core.{module}"), "__file__", "")
if module_path.endswith((".so", ".pyd")):
cython_modules.append(module)
print(f"Module {module} path: {module_path}")
print(f"Cython modules: {cython_modules}")
return bool(cython_modules)


USING_CYTHON = _using_cython_modules()
print(f"USING_CYTHON: {USING_CYTHON}")

__version__ = "1.1.0"
from iscc_core.options import core_opts, conformant_options
Expand Down
2 changes: 1 addition & 1 deletion iscc_core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def type_id(self) -> str:
length = "".join([t.name[0] for t in mtypes]) + "DI"
else:
length = self.length
return f"{self.maintype.name}-" f"{self.subtype.name}-" f"{self.version.name}-" f"{length}"
return f"{self.maintype.name}-{self.subtype.name}-{self.version.name}-{length}"

@property
def explain(self) -> str:
Expand Down
79 changes: 53 additions & 26 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ pytest-cov = "*"

[tool.poetry.group.dev.dependencies]
poethepoet = "*"
black = "^23.1"
bandit = "^1.7"
black = "*"
ruff = "*"
bandit = "*"

[tool.poetry.group.docs.dependencies]
mkdocs-material = "^9.0"
Expand All @@ -78,9 +79,10 @@ mdformat_tables = "*"
griffe = "<0.27.4"

[tool.black]
skip-string-normalization = false
line-length = 100
target-version = ['py37']
preview = true
enable-unstable-feature = ["string_processing"]
target-version = ['py39']

[tool.poe.tasks]
gentests = { cmd = "poetry run python -m tests.build_test_data", help = "Generate conformance test data" }
Expand Down
16 changes: 13 additions & 3 deletions tests/build_docs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Copy README.md to documentation index.md"""

from os.path import abspath, dirname, join


Expand All @@ -13,9 +14,18 @@ def main():
"""Copy root files to documentation site."""
with open(SRC, "rt", encoding="utf-8") as infile:
text = infile.read()
m = "![ISCC Architecture](https://raw.githubusercontent.com/iscc/iscc-core/master/docs/images/iscc-codec-light.png)\n"
r1 = "![ISCC Architecture](https://raw.githubusercontent.com/iscc/iscc-core/master/docs/images/iscc-codec-light.png#only-light)\n"
r2 = "![ISCC Architecture](https://raw.githubusercontent.com/iscc/iscc-core/master/docs/images/iscc-codec-dark.png#only-dark)\n"
m = (
"![ISCC"
" Architecture](https://raw.githubusercontent.com/iscc/iscc-core/master/docs/images/iscc-codec-light.png)\n"
)
r1 = (
"![ISCC"
" Architecture](https://raw.githubusercontent.com/iscc/iscc-core/master/docs/images/iscc-codec-light.png#only-light)\n"
)
r2 = (
"![ISCC"
" Architecture](https://raw.githubusercontent.com/iscc/iscc-core/master/docs/images/iscc-codec-dark.png#only-dark)\n"
)
text = text.replace(m, r1 + r2)
with open(DST, "wt", encoding="utf-8", newline="\n") as outf:
outf.write(text)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_code_content_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_code_text_c_256_bits():


def test_normalize_text():
txt = " Iñtërnâtiôn\nàlizætiøn☃💩 – is a tric\t ky \u00A0 thing!\r"
txt = " Iñtërnâtiôn\nàlizætiøn☃💩 – is a tric\t ky \u00a0 thing!\r"

normalized = iscc_core.code_content_text.text_collapse(txt)
assert normalized == "internationalizætiøn☃💩isatrickything"
Expand Down
5 changes: 3 additions & 2 deletions tests/test_code_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ def test_clean_text_markdowsn():
More Text
"""

assert ic.text_clean(text) == (
"# Document\n"
assert (
ic.text_clean(text)
== "# Document\n"
"\n"
"*Subtitle*\n"
"\n"
Expand Down
10 changes: 6 additions & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,13 @@ def test_hamming_distance_raises():


def test_multi_hash_blake3():
assert ic.multi_hash_blake3(b"") == (
"1e20af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262"
assert (
ic.multi_hash_blake3(b"")
== "1e20af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262"
)
assert ic.multi_hash_blake3(b"hello world") == (
"1e20d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24"
assert (
ic.multi_hash_blake3(b"hello world")
== "1e20d74981efa70a0c880b8d8c1985d075dbcbf679b99a5f9914e5aaf96b831a9e24"
)


Expand Down
1 change: 1 addition & 0 deletions tools/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Inspect full iscc_core api"""

import inspect
from pprint import pprint
import iscc_core
Expand Down
1 change: 1 addition & 0 deletions tools/lf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Convert line endings to LF"""

import pathlib

HERE = pathlib.Path(__file__).parent.parent.absolute()
Expand Down

0 comments on commit 75c1877

Please sign in to comment.