Skip to content

Commit a1ac82e

Browse files
authored
Initial import (#1)
* Scaffolding + ~ import from transformers * move more things around * Fixes/deletes from copy/pastes * GH Actions
1 parent 1884eff commit a1ac82e

File tree

19 files changed

+1725
-0
lines changed

19 files changed

+1725
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Python quality
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
8+
jobs:
9+
check_code_quality:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
- name: Set up Python
15+
uses: actions/setup-python@v2
16+
with:
17+
python-version: 3.9
18+
- name: Install dependencies
19+
run: |
20+
pip install --upgrade pip
21+
pip install .[dev]
22+
- run: black --check tests src
23+
- run: isort --check-only tests src
24+
- run: flake8 tests src

.github/workflows/python-tests.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Python tests
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
python-version: ["3.7", "3.8", "3.9"]
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
22+
- run: |
23+
git config --global user.email "[email protected]"
24+
git config --global user.name "ci"
25+
26+
- name: Install dependencies
27+
run: |
28+
pip install --upgrade pip
29+
pip install .[testing]
30+
- name: pytest
31+
run: RUN_GIT_LFS_TESTS=1 pytest -sv ./tests/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,4 @@ dmypy.json
127127

128128
# Pyre type checker
129129
.pyre/
130+
.vscode/

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.PHONY: quality style test
2+
3+
4+
check_dirs := tests src
5+
6+
7+
quality:
8+
black --check $(check_dirs)
9+
isort --check-only $(check_dirs)
10+
flake8 $(check_dirs)
11+
12+
style:
13+
black $(check_dirs)
14+
isort $(check_dirs)
15+
16+
test:
17+
pytest -sv ./tests/
18+

README.md

Whitespace-only changes.

setup.cfg

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[isort]
2+
default_section = FIRSTPARTY
3+
ensure_newline_before_comments = True
4+
force_grid_wrap = 0
5+
include_trailing_comma = True
6+
known_first_party = huggingface_hub
7+
known_third_party =
8+
absl
9+
conllu
10+
datasets
11+
elasticsearch
12+
fairseq
13+
faiss-cpu
14+
fastprogress
15+
fire
16+
fugashi
17+
git
18+
h5py
19+
matplotlib
20+
nltk
21+
numpy
22+
packaging
23+
pandas
24+
PIL
25+
psutil
26+
pytest
27+
pytorch_lightning
28+
rouge_score
29+
sacrebleu
30+
seqeval
31+
sklearn
32+
streamlit
33+
tensorboardX
34+
tensorflow
35+
tensorflow_datasets
36+
timeout_decorator
37+
torch
38+
torchtext
39+
torchvision
40+
torch_xla
41+
tqdm
42+
43+
line_length = 88
44+
lines_after_imports = 2
45+
multi_line_output = 3
46+
use_parentheses = True
47+
48+
[flake8]
49+
ignore = E203, E501, E741, W503, W605
50+
max-line-length = 88

setup.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
from setuptools import find_packages, setup
2+
3+
4+
def get_version() -> str:
5+
rel_path = "src/huggingface_hub/__init__.py"
6+
with open(rel_path, "r") as fp:
7+
for line in fp.read().splitlines():
8+
if line.startswith("__version__"):
9+
delim = '"' if '"' in line else "'"
10+
return line.split(delim)[1]
11+
raise RuntimeError("Unable to find version string.")
12+
13+
14+
install_requires = [
15+
"filelock",
16+
"requests",
17+
"tqdm",
18+
]
19+
20+
extras = {}
21+
22+
extras["testing"] = [
23+
"pytest",
24+
]
25+
26+
extras["quality"] = [
27+
"black>=20.8b1",
28+
"isort>=5.5.4",
29+
"flake8>=3.8.3",
30+
]
31+
32+
extras["all"] = extras["testing"] + extras["quality"]
33+
34+
extras["dev"] = extras["all"]
35+
36+
37+
setup(
38+
name="huggingface_hub",
39+
version=get_version(),
40+
author="Hugging Face, Inc.",
41+
author_email="[email protected]",
42+
description="Client library to download and publish models on the huggingface.co hub",
43+
long_description=open("README.md", "r", encoding="utf-8").read(),
44+
long_description_content_type="text/markdown",
45+
keywords="model-hub machine-learning models natural-language-processing deep-learning pytorch pretrained-models",
46+
license="Apache",
47+
url="https://github.com/huggingface/huggingface_hub",
48+
package_dir={"": "src"},
49+
packages=find_packages("src"),
50+
extras_require=extras,
51+
entry_points={
52+
"console_scripts": [
53+
"huggingface-cli=huggingface_hub.commands.huggingface_cli:main"
54+
]
55+
},
56+
python_requires=">=3.6.0",
57+
install_requires=install_requires,
58+
classifiers=[
59+
"Intended Audience :: Developers",
60+
"Intended Audience :: Education",
61+
"Intended Audience :: Science/Research",
62+
"License :: OSI Approved :: Apache Software License",
63+
"Operating System :: OS Independent",
64+
"Programming Language :: Python :: 3",
65+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
66+
],
67+
)

src/huggingface_hub/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# flake8: noqa
2+
# There's no way to ignore "F401 '...' imported but unused" warnings in this
3+
# module, but to preserve other warnings. So, don't check this module at all.
4+
5+
# Copyright 2020 The HuggingFace Team. All rights reserved.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
__version__ = "0.1.0"
20+
21+
from .file_download import HUGGINGFACE_CO_URL_TEMPLATE, cached_download, hf_hub_url
22+
from .hf_api import HfApi, HfFolder
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2020 The HuggingFace Team. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from abc import ABC, abstractmethod
16+
from argparse import ArgumentParser
17+
18+
19+
class BaseHuggingfaceCLICommand(ABC):
20+
@staticmethod
21+
@abstractmethod
22+
def register_subcommand(parser: ArgumentParser):
23+
raise NotImplementedError()
24+
25+
@abstractmethod
26+
def run(self):
27+
raise NotImplementedError()
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
# Copyright 2020 The HuggingFace Team. All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
from argparse import ArgumentParser
17+
18+
from huggingface_hub.commands.lfs import LfsCommands
19+
from huggingface_hub.commands.user import UserCommands
20+
21+
22+
def main():
23+
parser = ArgumentParser(
24+
"huggingface-cli", usage="huggingface-cli <command> [<args>]"
25+
)
26+
commands_parser = parser.add_subparsers(help="huggingface-cli command helpers")
27+
28+
# Register commands
29+
UserCommands.register_subcommand(commands_parser)
30+
LfsCommands.register_subcommand(commands_parser)
31+
32+
# Let's go
33+
args = parser.parse_args()
34+
35+
if not hasattr(args, "func"):
36+
parser.print_help()
37+
exit(1)
38+
39+
# Run
40+
service = args.func(args)
41+
service.run()
42+
43+
44+
if __name__ == "__main__":
45+
main()

0 commit comments

Comments
 (0)