Skip to content

Commit 93f4994

Browse files
authored
Merge pull request #7 from mhabedan/yodaH5
Add support for yoda-H5
2 parents 799b6ea + 81eca5c commit 93f4994

File tree

8 files changed

+49
-45
lines changed

8 files changed

+49
-45
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,28 @@ jobs:
1515
strategy:
1616
matrix:
1717
runner: ['ubuntu-latest']
18-
python-version: [ '3.7', '3.8', '3.9', '3.10', '3.11' ]
18+
python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12', '3.13' ]
1919
include:
20-
- runner: 'ubuntu-20.04'
21-
python-version: '3.6'
20+
- runner: 'ubuntu-22.04'
21+
python-version: '3.7'
2222

2323
steps:
24-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@v5
2525
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v4
26+
uses: actions/setup-python@v5
2727
with:
2828
python-version: ${{ matrix.python-version }}
2929
- name: Install pip dependencies
3030
run: |
3131
pip install --upgrade pip setuptools coveralls
3232
pip install -e '.[tests]'
33+
hepdata-cli --help
3334
- name: Run tests
35+
if: startsWith(matrix.python-version, '3.12')
3436
run: |
3537
pytest --cov=hepdata_cli
3638
- name: Run coveralls
37-
if: startsWith(matrix.python-version, '3.11')
39+
if: startsWith(matrix.python-version, '3.12')
3840
env:
3941
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4042
COVERALLS_SERVICE_NAME: github
@@ -51,11 +53,11 @@ jobs:
5153
permissions:
5254
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
5355
steps:
54-
- uses: actions/checkout@v4
55-
- name: Set up Python 3.11
56-
uses: actions/setup-python@v4
56+
- uses: actions/checkout@v5
57+
- name: Set up Python 3.12
58+
uses: actions/setup-python@v5
5759
with:
58-
python-version: '3.11'
60+
python-version: '3.12'
5961
- name: Build PyPI package
6062
run: |
6163
pip install wheel

README.md

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,18 @@ $ pip install --user hepdata-cli
2323
$ hepdata-cli --help
2424
```
2525

26-
With Python 3 (<3.7), if the `LANG` environment variable is not set, you might get an error like:
27-
28-
```
29-
RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment. Consult https://click.palletsprojects.com/python3/ for mitigation steps.
30-
```
31-
32-
In this case, you will need to export a Unicode locale as described in the
33-
[Click documentation](https://click.palletsprojects.com/en/7.x/python3/#python-3-surrogate-handling).
34-
3526
## Installation (for developers)
3627

3728
Install from GitHub in a [virtual environment](https://docs.python.org/3/tutorial/venv.html):
3829

3930
```code
4031
$ git clone https://github.com/HEPData/hepdata-cli.git
4132
$ cd hepdata-cli
42-
$ python3 -m venv ~/venv/hepdata-cli
43-
$ source ~/venv/hepdata-cli/bin/activate
44-
(hepdata-cli) $ pip install -e '.[tests]'
45-
(hepdata-cli) $ hepdata-cli --help
46-
(hepdata-cli) $ pytest --cov=hepdata_cli
33+
$ python3 -m venv venv
34+
$ source venv/bin/activate
35+
(venv) $ pip install -e '.[tests]'
36+
(venv) $ hepdata-cli --help
37+
(venv) $ pytest --cov=hepdata_cli
4738
```
4839

4940
## Usage
@@ -74,11 +65,11 @@ An exact match of the keyword is first attempted, otherwise partial matches are
7465

7566
The argument ```[-i/--ids IDTYPE]``` accepts ```IDTYPE``` equal to ```arxiv```, ```hepdata``` or```inspire```.
7667

77-
The argument ```[-f/--file-format FORMAT]``` accepts ```FORMAT``` equal to ```csv```, ```root```, ```yaml```, ```yoda```, ```yoda1```, or ```json```.
78-
In the first four cases a .tar.gz archive is downloaded and unpacked as a directory, whereas in the last case a .json file is downloaded.
68+
The argument ```[-f/--file-format FORMAT]``` accepts ```FORMAT``` equal to ```csv```, ```root```, ```yaml```, ```yoda```, ```yoda1```, ```yoda.h5```, or ```json```.
69+
In the first six cases a .tar.gz archive is downloaded and unpacked as a directory, whereas in the last case a .json file is downloaded.
7970

8071
The argument ```[-t/--table-name TABLE-NAME]``` accepts a string giving the table name as input.
81-
In this case only the specified table is downloaded as a .csv, .root, .yaml, .yoda, .yoda1 or .json file.
72+
In this case only the specified table is downloaded as a .csv, .root, .yaml, .yoda, .yoda1, .yoda.h5, or .json file.
8273

8374
The argument ```[-d/--download-dir DOWNLOAD-DIR]``` specifies the directory to download the files.
8475
If not specified, the default download directory is ```./hepdata-downloads```.

hepdata_cli/api.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# SITE_URL = "http://127.0.0.1:5000"
1414

1515
UPLOAD_MAX_SIZE = 52000000 # Upload limit in bytes
16+
ALLOWED_FORMATS = ['csv', 'root', 'yaml', 'yoda', 'yoda1', 'yoda.h5', 'json']
1617

1718
MAX_MATCHES, MATCHES_PER_PAGE = (10000, 10) if "pytest" not in sys.modules else (144, 12)
1819

@@ -82,7 +83,7 @@ def download(self, id_list, file_format=None, ids=None, table_name='', download_
8283
Downloads from the hepdata database the specified records.
8384
8485
:param id_list: list of ids to download. These can be obtained by the find function.
85-
:param file_format: accepts one of ('csv', 'root', 'yaml', 'yoda', 'yoda1', 'json'). Specifies the download file format.
86+
:param file_format: accepts one of ('csv', 'root', 'yaml', 'yoda', 'yoda1', 'yoda.h5', 'json'). Specifies the download file format.
8687
:param ids: accepts one of ('inspire', 'hepdata'). It specifies what type of ids have been passed.
8788
:param table_name: restricts download to specific tables.
8889
:param download_dir: defaults to ./hepdata-downloads. Specifies where to download the files.
@@ -139,13 +140,14 @@ def _build_urls(self, id_list, file_format, ids, table_name):
139140
if type(id_list) not in (tuple, list):
140141
id_list = id_list.split()
141142
assert len(id_list) > 0, 'Ids are required.'
142-
assert file_format in ['csv', 'root', 'yaml', 'yoda', 'yoda1', 'json'], "allowed formats are: csv, root, yaml, yoda, yoda1 and json."
143+
assert file_format in ALLOWED_FORMATS, f"allowed formats are: {ALLOWED_FORMATS}"
143144
assert ids in ['inspire', 'hepdata'], "allowed ids are: inspire and hepdata."
144145
if table_name == '':
145146
params = {'format': file_format}
146147
else:
147148
params = {'format': file_format, 'table': table_name}
148-
urls = [resilient_requests('get', SITE_URL + '/record/' + ('ins' if ids == 'inspire' else '') + id_entry, params=params).url for id_entry in id_list]
149+
urls = [resilient_requests('get', SITE_URL + '/record/' + ('ins' if ids == 'inspire' else '') + id_entry, params=params).url.replace('%2525', '%25') for id_entry in id_list]
150+
# TODO: Investigate root cause of double URL encoding (https://github.com/HEPData/hepdata-cli/issues/8).
149151
return urls
150152

151153
def _query(self, query, page, size):

hepdata_cli/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import click
44

55
from .version import __version__
6-
from .api import Client
6+
from .api import Client, ALLOWED_FORMATS
77

88

99
@click.group()
@@ -27,7 +27,7 @@ def find(client, query, keyword, ids):
2727

2828
@cli.command()
2929
@click.argument('id_list', nargs=-1, required=True, type=str)
30-
@click.option('-f', '--file-format', required=True, type=str, help='Specify file format (csv, root, yaml, yoda, yoda1, or json) to be downloaded.')
30+
@click.option('-f', '--file-format', required=True, type=str, help=f'Specify file format (from {ALLOWED_FORMATS}) to be downloaded.')
3131
@click.option('-i', '--ids', required=True, type=str, help='Specify which ids (hepdata or inspire) are given.')
3232
@click.option('-t', '--table-name', default='', type=str, help='Specify table to be downloaded.')
3333
@click.option('-d', '--download-dir', default='./hepdata-downloads', type=str, help='Specify where to download the files.')

hepdata_cli/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.2"
1+
__version__ = "0.2.3"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
install_requires=install_requirements,
4646
tests_require=test_requirements,
4747
extras_require=extras_require,
48-
python_requires='>=3.6',
48+
python_requires='>=3.7',
4949
entry_points={
5050
'console_scripts': [
5151
'hepdata-cli = hepdata_cli.cli:cli',

tests/test_download.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,25 @@ def cleanup(directory):
3333

3434
# arguments for testing
3535

36-
test_download_arguments = [
36+
test_api_download_arguments = [
3737
(["73322"], "json", "hepdata", ''),
3838
(["1222326", "1694381", "1462258", "1309874"], "csv", "inspire", ''),
3939
(["61434"], "yaml", "hepdata", "Table1"),
4040
(["1762350"], "yoda", "inspire", "Number density and Sum p_T pT>0.15 GeV/c"),
41+
(["2862529"], "yoda.h5", "inspire", "95% CL upper limit on XSEC times BF"),
42+
(["2862529"], "yoda.h5", "inspire", '')
43+
]
44+
45+
test_cli_download_arguments = [
46+
(["2862529"], "json", "inspire", ''),
47+
(["1222326", "1694381", "1462258", "1309874"], "root", "inspire", ''),
48+
(["61434"], "yaml", "hepdata", "Table2"),
4149
]
4250

4351

4452
# api testing
4553

46-
@pytest.mark.parametrize("id_list, file_format, ids, table", test_download_arguments)
54+
@pytest.mark.parametrize("id_list, file_format, ids, table", test_api_download_arguments)
4755
def test_api_download(id_list, file_format, ids, table):
4856
test_download_dir = './.pytest_downloads/'
4957
mkdir(test_download_dir)
@@ -56,7 +64,7 @@ def test_api_download(id_list, file_format, ids, table):
5664

5765
# cli testing
5866

59-
@pytest.mark.parametrize("id_list, file_format, ids, table", test_download_arguments)
67+
@pytest.mark.parametrize("id_list, file_format, ids, table", test_cli_download_arguments)
6068
def test_cli_download(id_list, file_format, ids, table):
6169
test_download_dir = './.pytest_downloads/'
6270
mkdir(test_download_dir)

tests/test_search.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010

1111
# arguments for testing
1212

13-
test_find_arguments = [
13+
test_api_find_arguments = [
1414
('reactions:"P P--> LQ LQ X"', None, None),
15-
('reactions:"P P --> gamma gamma"', None, None),
1615
('reactions:"P P--> LQ LQ"', 'year', None),
17-
('reactions:"P P--> LQ LQ"', 'arxiv', None),
18-
('reactions:"P P--> LQ LQ"', None, 'arxiv'),
19-
('reactions:"P P--> LQ LQ"', None, 'hepdata'),
20-
('reactions:"P P"', None, 'hepdata'),
16+
('phrases:"(diffractive AND elastic)"', None, 'arxiv'),
2117
]
2218

19+
test_cli_find_arguments = [
20+
('reactions:"P P --> gamma gamma"', 'arxiv', None),
21+
('abstract:"baryon production"', 'arxiv', 'hepdata'),
22+
('abstract:"charmed baryon production"', 'arxiv', 'arxiv'),
23+
]
2324

2425
# api test
2526

26-
@pytest.mark.parametrize("query, keyword, ids", test_find_arguments)
27+
@pytest.mark.parametrize("query, keyword, ids", test_api_find_arguments)
2728
def test_api_find(query, keyword, ids):
2829
client = Client(verbose=True)
2930
search_result = client.find(query, keyword, ids)
@@ -37,7 +38,7 @@ def test_api_find(query, keyword, ids):
3738

3839
# cli testing
3940

40-
@pytest.mark.parametrize("query, keyword, ids", test_find_arguments)
41+
@pytest.mark.parametrize("query, keyword, ids", test_cli_find_arguments)
4142
def test_cli_find(query, keyword, ids):
4243
runner = CliRunner()
4344
result = runner.invoke(cli, ['find', query, '-kw', keyword, '-i', ids])

0 commit comments

Comments
 (0)