Skip to content

Commit a781ca5

Browse files
authored
Merge pull request #11 from European-XFEL/refactor/duplicate-find-proposal
refactor: remove duplicate find_proposal function
2 parents 43d91f2 + 8afe6d6 commit a781ca5

4 files changed

Lines changed: 24 additions & 34 deletions

File tree

extra_proposal/mymdc.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
import json
2-
import os
3-
from glob import iglob
4-
from pathlib import Path
52
from urllib.parse import urljoin
63

74
import yaml
85
import requests
96
from oauth2_xfel_client import Oauth2ClientBackend
107

8+
from .utils import find_proposal
9+
1110
MYMDC_BASE_URL = "https://in.xfel.eu/metadata"
1211
ZWOP_BASE_URL = "https://exfldadev01.desy.de/zwop"
1312

14-
# Copied from extra-data
15-
def find_proposal(propno):
16-
root_dir = Path(os.environ.get('EXTRA_DATA_DATA_ROOT', '/gpfs/exfel/exp'))
17-
for d in iglob(str(root_dir / f'*/*/{propno}')):
18-
return Path(d)
19-
20-
raise Exception(f"Couldn't find proposal dir for {propno!r}")
21-
2213

2314
class MyMdcAccess:
2415
_oauth_cache = {} # Keyed by client ID

extra_proposal/proposal.py

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
11
import fnmatch
22
import glob
33
import logging
4-
import os
54
import re
65
from datetime import datetime
76
from functools import wraps
87
from itertools import count, groupby
9-
from pathlib import Path
108
from typing import Any, Optional
119

1210
import numpy as np
1311

1412
from .mymdc import MyMdcAccess
13+
from .utils import data_root_dir, find_proposal
1514

1615
logger = logging.getLogger(__name__)
1716

1817

19-
class ProposalNotFoundError(Exception):
20-
"""
21-
Raised when the proposal is not found.
22-
"""
23-
24-
pass
25-
26-
27-
def data_root_dir():
28-
return Path(os.environ.get('EXTRA_DATA_DATA_ROOT', '/gpfs/exfel/exp'))
29-
30-
31-
# Copied from extra-data
32-
def find_proposal(propno):
33-
for d in data_root_dir().glob(f'*/*/{propno}'):
34-
return d
35-
36-
raise ProposalNotFoundError(f"Proposal {propno!r} was not found")
37-
38-
3918
class RunReference:
4019
def __init__(self, proposal: 'Proposal', run_num: int):
4120
self.proposal = proposal

extra_proposal/utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import os
2+
from pathlib import Path
3+
4+
class ProposalNotFoundError(Exception):
5+
"""
6+
Raised when the proposal is not found.
7+
"""
8+
pass
9+
10+
11+
def data_root_dir():
12+
return Path(os.environ.get('EXTRA_DATA_DATA_ROOT', '/gpfs/exfel/exp'))
13+
14+
15+
# Copied from extra-data
16+
def find_proposal(propno):
17+
for d in data_root_dir().glob(f'*/*/{propno}'):
18+
return d
19+
20+
raise ProposalNotFoundError(f"Proposal {propno!r} was not found")

tests/test_mymdc_proposal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import matplotlib.pyplot as plt
77

88
from extra_proposal import Proposal
9-
from extra_proposal.proposal import ProposalNotFoundError
9+
from extra_proposal.utils import ProposalNotFoundError
1010

1111

1212
# Helper function to mock requests.get() for different endpoints

0 commit comments

Comments
 (0)