Skip to content

Commit

Permalink
Merge pull request #1 from rdimaio/main
Browse files Browse the repository at this point in the history
Add Belle II algorithms, permission, schema, GH workflow for building policy package
  • Loading branch information
rdimaio authored Nov 7, 2024
2 parents 50edd23 + d89a647 commit 7cc22fb
Show file tree
Hide file tree
Showing 13 changed files with 1,820 additions and 2 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Upload Python Package

on:
release:
types: [published]

permissions:
contents: read

jobs:
release-build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Build release distributions
run: |
python -m pip install build
python -m build
- name: Upload distributions
uses: actions/upload-artifact@v4
with:
name: release-dists
path: dist/
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# build directories
.coverage
build/
covhtml
dist/
examples/whip/results/
lib/rucio.egg-info/
cache/
changed_files.txt
docs/

# Backup and temp files
*.log
*.pyc
*.swp
*.swp
*~
.venv
lib/rucio/vcsversion.py
*.egg-info
pylint.out

# OS-specific
.DS_Store
11 changes: 11 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pypi:
image: docker.io/python:3
stage: deploy
cache: {}
script:
- pip install -U twine
- python -m pip install build
- python -m build
- twine upload dist/*
only:
- tags
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
hooks:
- id: ruff
args: [ --fix ]
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# temporary-belle2-policy-package
Temporary Belle II Policy package
# Temporary Belle II Rucio policy package

## Resources
- [Rucio documentation for policy packages](https://rucio.github.io/documentation/operator/policy_packages/)
Empty file added __init__.py
Empty file.
57 changes: 57 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "belleii_rucio_policy_package"
version = "0.0.2"
authors = [
{ name="Belle II", email="[email protected]" },
]
description = "Rucio policy package for the Belle II experiment"
requires-python = ">=3.9"
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
readme = "README.md"
license = {file = "LICENSE"}

[project.optional-dependencies]
dev = [
"rucio"
]

[tool.ruff]
line-length = 256


# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]
18 changes: 18 additions & 0 deletions src/belleii_rucio_policy_package/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import non_deterministic_pfn
import scope
import lfn2pfn

SUPPORTED_VERSION = ["35"] # Only use with Rucio >=35.1.0 - pending https://github.com/rucio/rucio/issues/7082

def get_algorithms():
return {
'non_deterministic_pfn': {
'belleii_non_deterministic_pfn': non_deterministic_pfn.BelleIINonDeterministicPFNAlgorithm.construct_non_deterministic_pfn_belleii
},
'lfn2pfn': {
'belleii_lfn2pfn': lfn2pfn.BelleIIRSEDeterministicTranslation.lfn2pfn_belleii
},
'scope': {
'belleii_extract_scope': scope.BelleIIScopeExtractionAlgorithm.extract_scope_belleii
}
}
48 changes: 48 additions & 0 deletions src/belleii_rucio_policy_package/lfn2pfn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from rucio.rse.translation import RSEDeterministicTranslation

class BelleIIRSEDeterministicTranslation(RSEDeterministicTranslation):

def __init__(self, rse=None, rse_attributes=None, protocol_attributes=None):
"""
Initialize a translator object from the RSE, its attributes, and the protocol-specific
attributes.
:param rse: Name of RSE for this translation.
:param rse_attributes: A dictionary of RSE-specific attributes for use in the translation.
:param protocol_attributes: A dictionary of RSE/protocol-specific attributes.
"""
super().__init__()
self.rse = rse
self.rse_attributes = rse_attributes if rse_attributes else {}
self.protocol_attributes = protocol_attributes if protocol_attributes else {}

@classmethod
def _module_init_(cls):
"""
Initialize the class object on first module load.
"""
cls.register(cls.lfn2pfn_belleii, "belleii")

@staticmethod
def lfn2pfn_belleii(scope, name, rse, rse_attrs, protocol_attrs):
"""
Given a LFN, convert it directly to a path using the mapping:
path -> path
This is valid only for the belleii convention where the scope can be determined
from the LFN using a determinitic function.
:param scope: Scope of the LFN.
:param name: File name of the LFN.
:param rse: RSE for PFN (ignored)
:param rse_attrs: RSE attributes for PFN (ignored)
:param protocol_attrs: RSE protocol attributes for PFN (ignored)
:returns: Path for use in the PFN generation.
"""
del scope
del rse
del rse_attrs
del protocol_attrs
return name

BelleIIRSEDeterministicTranslation._module_init_()
37 changes: 37 additions & 0 deletions src/belleii_rucio_policy_package/non_deterministic_pfn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from typing import Optional

from rucio.common.utils import NonDeterministicPFNAlgorithms


class BelleIINonDeterministicPFNAlgorithm(NonDeterministicPFNAlgorithms):
"""
Belle II specific non-deterministic PFN algorithm
"""

def __init__(self):
super().__init__()

@classmethod
def _module_init_(cls) -> None:
"""
Registers the included non-deterministic PFN algorithms
"""
cls.register('belleii', cls.construct_non_deterministic_pfn_belleii)

@staticmethod
def construct_non_deterministic_pfn_belleii(dsn: str, scope: Optional[str], filename: str) -> str:
"""
Defines relative PFN for Belle II specific replicas.
This method contains the Belle II convention.
To be used for non-deterministic Belle II sites.
DSN (or datablock in the Belle II naming) contains /
"""

fields = dsn.split("/")
nfields = len(fields)
if nfields == 0:
return '/other/%s' % (filename)
else:
return '%s/%s' % (dsn, filename)

BelleIINonDeterministicPFNAlgorithm._module_init_()
Loading

0 comments on commit 7cc22fb

Please sign in to comment.