Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed "core.mark" module to "core.hook" #44

Merged
merged 8 commits into from
Nov 15, 2023
Merged
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
129 changes: 63 additions & 66 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
test:
strategy:
matrix:
os: [ubuntu-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: ["3.8", "3.12"]
fail-fast: false
runs-on: ${{ matrix.os }}
Expand All @@ -39,52 +39,52 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Update build tools
run: python -m pip install --upgrade pip
run: python3 -m pip install --upgrade pip
- name: Install Package
run: python -m pip install -e .[test]
run: python3 -m pip install -e .[test] -e ./extras[test]
- name: Pytest
run: pytest -vvs ./fileformats
run: pytest -vvs --cov fileformats --cov-config .coveragerc --cov-report xml .
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

test-extras:
build:
needs: [test]
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.8", "3.12"]
fail-fast: false
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
pkg:
- ["main", "."]
- ["extras", "./extras"]
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Unset header
# checkout@v2 adds a header that makes branch protection report errors
# because the Github action bot is not a collaborator on the repo
run: git config --local --unset http.https://github.com/.extraheader
- name: Fetch tags
run: git fetch --prune --unshallow
- name: Disable etelemetry
run: echo "NO_ET=TRUE" >> $GITHUB_ENV
- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Update build tools
run: python -m pip install --upgrade pip
- name: Install Package
run: python -m pip install -e . -e ./extras[test]
- name: Pytest
run: pytest -vvs --cov fileformats --cov-config .coveragerc --cov-report xml .
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
python-version: '3.12'
- name: Install build tools
run: python3 -m pip install build twine
- name: Build source and wheel distributions
run: python3 -m build ${{ matrix.pkg[1] }}
- name: Check distributions
run: twine check ${{ matrix.pkg[1] }}/dist/*
- uses: actions/upload-artifact@v3
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
name: built-${{ matrix.pkg[0] }}
path: ${{ matrix.pkg[1] }}/dist

build-docs:
runs-on: ubuntu-latest

needs: [build]
steps:
- name: Checkout repository
uses: actions/checkout@v2
Expand All @@ -98,7 +98,7 @@ jobs:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python3 -m pip install --upgrade pip
pip install .[docs]
- name: Build documentation
run: |
Expand All @@ -111,30 +111,14 @@ jobs:
path: docs/build/html

deploy:
needs: [test, test-extras, build-docs]
needs: [build, build-docs]
runs-on: ubuntu-latest
strategy:
matrix:
pkg-dir: [".", "./extras"]
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Unset header
# checkout@v2 adds a header that makes branch protection report errors
# because the Github action bot is not a collaborator on the repo
run: git config --local --unset http.https://github.com/.extraheader
- name: Set up Python
uses: actions/setup-python@v4
- name: Download build
uses: actions/download-artifact@v3
with:
python-version: '3.12'
- name: Install build tools
run: python -m pip install build twine
- name: Build source and wheel distributions
run: python -m build ${{ matrix.pkg-dir }}
- name: Check distributions
run: twine check ${{ matrix.pkg-dir }}/dist/*
name: built-main
path: dist
- name: Check for PyPI token on tag
id: deployable
if: github.event_name == 'release'
Expand All @@ -147,25 +131,38 @@ jobs:
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
packages-dir: ${{ matrix.pkg-dir }}/dist

deploy-docs:
needs: [deploy]
deploy-extras:
needs: [build, deploy]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download build
uses: actions/download-artifact@v3
with:
submodules: recursive
fetch-depth: 0
- name: Unset header
# checkout@v2 adds a header that makes branch protection report errors
# because the Github action bot is not a collaborator on the repo
run: git config --local --unset http.https://github.com/.extraheader
name: built-extras
path: dist
- name: Check for PyPI token on tag
id: deployable
if: github.event_name == 'release'
env:
EXTRAS_PYPI_API_TOKEN: "${{ secrets.EXTRAS_PYPI_API_TOKEN }}"
run: if [ -n "$EXTRAS_PYPI_API_TOKEN" ]; then echo "DEPLOY=true" >> $GITHUB_OUTPUT; fi
- name: Upload to PyPI
if: steps.deployable.outputs.DEPLOY
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.EXTRAS_PYPI_API_TOKEN }}

deploy-docs:
needs: [build-docs, deploy]
runs-on: ubuntu-latest
steps:
- name: Download built docs
uses: actions/download-artifact@v3
with:
name: built-docs
path: docs/build/html
path: docs-build
- name: Check for PyPI token on tag
id: deployable
if: github.event_name == 'release'
Expand All @@ -177,7 +174,7 @@ jobs:
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GHPAGES_DEPLOY_KEY }}
publish_dir: docs/build/html
publish_dir: docs-build

# Deploy on tags if PYPI_API_TOKEN is defined in the repository secrets.
# Secrets are not accessible in the if: condition [0], so set an output variable [1]
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ FileFormats
.. image:: https://img.shields.io/pypi/v/fileformats.svg
:target: https://pypi.python.org/pypi/fileformats/
:alt: Latest Version
.. image:: https://img.shields.io/badge/docs-latest-brightgreen
.. image:: https://img.shields.io/badge/docs-latest-brightgreen.svg?style=flat
:target: https://arcanaframework.github.io/fileformats/
:alt: docs
:alt: Documentation Status


*Fileformats* provides a library of file-format types implemented as Python classes.
Expand Down
3 changes: 3 additions & 0 deletions extras/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ FileFormats Extras
:target: https://github.com/arcanaframework/fileformats-extras/actions/workflows/tests.yml
.. image:: https://codecov.io/gh/arcanaframework/fileformats-extras/branch/main/graph/badge.svg?token=UIS0OGPST7
:target: https://codecov.io/gh/arcanaframework/fileformats-extras
.. image:: https://img.shields.io/pypi/pyversions/fileformats-extras.svg
:target: https://pypi.python.org/pypi/fileformats-extras/
:alt: Supported Python versions
.. image:: https://img.shields.io/pypi/v/fileformats-extras.svg
:target: https://pypi.python.org/pypi/fileformats-extras/
:alt: Latest Version
Expand Down
26 changes: 13 additions & 13 deletions extras/fileformats/extras/application/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pydra.engine.specs
from fileformats.generic import FsObject
from fileformats.core.utils import set_cwd
from fileformats.core import mark, FileSet
from fileformats.core import hook, FileSet
from fileformats.application import Zip, Tar, TarGzip


Expand Down Expand Up @@ -47,10 +47,10 @@
Compressed = FileSet.type_var("Compressed")


@mark.converter(source_format=FsObject, target_format=Tar)
@mark.converter(source_format=FsObject, target_format=TarGzip, compression="gz")
@mark.converter(source_format=Compressed, target_format=Tar[Compressed])
@mark.converter(
@hook.converter(source_format=FsObject, target_format=Tar)
@hook.converter(source_format=FsObject, target_format=TarGzip, compression="gz")
@hook.converter(source_format=Compressed, target_format=Tar[Compressed])
@hook.converter(
source_format=Compressed, target_format=TarGzip[Compressed], compression="gz"
)
@pydra.mark.task
Expand Down Expand Up @@ -102,10 +102,10 @@ def create_tar(
return Path(out_file)


@mark.converter(source_format=Tar, target_format=FsObject)
@mark.converter(source_format=TarGzip, target_format=FsObject)
@mark.converter(source_format=Tar[Compressed], target_format=Compressed)
@mark.converter(source_format=TarGzip[Compressed], target_format=Compressed)
@hook.converter(source_format=Tar, target_format=FsObject)
@hook.converter(source_format=TarGzip, target_format=FsObject)
@hook.converter(source_format=Tar[Compressed], target_format=Compressed)
@hook.converter(source_format=TarGzip[Compressed], target_format=Compressed)
@pydra.mark.task
@pydra.mark.annotate({"return": {"out_file": Path}})
def extract_tar(
Expand Down Expand Up @@ -136,8 +136,8 @@ def extract_tar(
return extracted[0]


@mark.converter(source_format=FsObject, target_format=Zip)
@mark.converter(source_format=Compressed, target_format=Zip[Compressed])
@hook.converter(source_format=FsObject, target_format=Zip)
@hook.converter(source_format=Compressed, target_format=Zip[Compressed])
@pydra.mark.task
@pydra.mark.annotate(
{
Expand Down Expand Up @@ -198,8 +198,8 @@ def create_zip(
return Path(out_file)


@mark.converter(source_format=Zip, target_format=FsObject)
@mark.converter(source_format=Zip[Compressed], target_format=Compressed)
@hook.converter(source_format=Zip, target_format=FsObject)
@hook.converter(source_format=Zip[Compressed], target_format=Compressed)
@pydra.mark.task
@pydra.mark.annotate({"return": {"out_file": Path}})
def extract_zip(in_file: Zip, extract_dir: Path) -> Path:
Expand Down
6 changes: 3 additions & 3 deletions extras/fileformats/extras/application/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import yaml
import pydra.mark
import pydra.engine.specs
from fileformats.core import mark
from fileformats.core import hook
from fileformats.application import DataSerialization, Json, Yaml


@mark.converter(target_format=Json, output_format=Json)
@mark.converter(target_format=Yaml, output_format=Yaml)
@hook.converter(target_format=Json, output_format=Json)
@hook.converter(target_format=Yaml, output_format=Yaml)
@pydra.mark.task
@pydra.mark.annotate({"return": {"out_file": DataSerialization}})
def convert_data_serialization(
Expand Down
12 changes: 6 additions & 6 deletions extras/fileformats/extras/image/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import tempfile
import pydra.mark
import pydra.engine.specs
from fileformats.core import mark
from fileformats.core import hook
from fileformats.image.raster import RasterImage, Bitmap, Gif, Jpeg, Png, Tiff


@mark.converter(target_format=Bitmap, output_format=Bitmap)
@mark.converter(target_format=Gif, output_format=Gif)
@mark.converter(target_format=Jpeg, output_format=Jpeg)
@mark.converter(target_format=Png, output_format=Png)
@mark.converter(target_format=Tiff, output_format=Tiff)
@hook.converter(target_format=Bitmap, output_format=Bitmap)
@hook.converter(target_format=Gif, output_format=Gif)
@hook.converter(target_format=Jpeg, output_format=Jpeg)
@hook.converter(target_format=Png, output_format=Png)
@hook.converter(target_format=Tiff, output_format=Tiff)
@pydra.mark.task
@pydra.mark.annotate({"return": {"out_file": RasterImage}})
def convert_image(
Expand Down
1 change: 0 additions & 1 deletion extras/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ classifiers = [
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand Down
8 changes: 4 additions & 4 deletions fileformats/application/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import typing as ty
from random import Random
from pathlib import Path
from ..core import mark, DataType
from ..core import hook, DataType
from ..core.mixin import WithClassifiers
from ..generic import File
from ..core.exceptions import FormatMismatchError
Expand Down Expand Up @@ -41,12 +41,12 @@ class DataSerialization(WithClassifiers, File):

iana_mime = None

@mark.extra
@hook.extra
def load(self):
"""Load the contents of the file into a dictionary"""
raise NotImplementedError

@mark.extra
@hook.extra
def save(data):
"""Serialise a dictionary to a new file"""
raise NotImplementedError
Expand All @@ -68,7 +68,7 @@ class Json(DataSerialization):
ext = ".json"
allowed_classifiers = (JsonSchema, InformalSchema)

@mark.check
@hook.check
def load(self):
try:
with open(self.fspath) as f:
Expand Down
2 changes: 1 addition & 1 deletion fileformats/core/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def register_converter(
source_format: type,
converter_tuple: ty.Tuple[ty.Callable, ty.Dict[str, ty.Any]],
):
"""Registers a converter task within a class attribute. Called by the @fileformats.mark.converter
"""Registers a converter task within a class attribute. Called by the @fileformats.hook.converter
decorator.

Parameters
Expand Down
Loading
Loading