Skip to content

Commit 280166e

Browse files
committed
Misc improvements
1 parent 8b9649b commit 280166e

File tree

4 files changed

+80
-278
lines changed

4 files changed

+80
-278
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
[🎓 **Documentation**](https://huggingface.co/docs/datasets/) [🕹 **Colab tutorial**](https://colab.research.google.com/github/huggingface/datasets/blob/main/notebooks/Overview.ipynb)
3939

40-
[🔎 **Find a dataset in the Hub**](https://huggingface.co/datasets) [🌟 **Add a new dataset to the Hub**](https://huggingface.co/docs/datasets/share.html)
40+
[🔎 **Find a dataset in the Hub**](https://huggingface.co/datasets) [🌟 **Share a dataset on the Hub**](https://huggingface.co/docs/datasets/share)
4141

4242
<h3 align="center">
4343
<a href="https://hf.co/course"><img src="https://raw.githubusercontent.com/huggingface/datasets/main/docs/source/imgs/course_banner.png"></a>
@@ -155,9 +155,7 @@ If you are familiar with the great TensorFlow Datasets, here are the main differ
155155

156156
# Disclaimers
157157

158-
Similar to TensorFlow Datasets, 🤗 Datasets is a utility library that downloads and prepares public datasets. We do not host or distribute most of these datasets, vouch for their quality or fairness, or claim that you have license to use them. It is your responsibility to determine whether you have permission to use the dataset under the dataset's license.
159-
160-
Moreover 🤗 Datasets may run Python code defined by the dataset authors to parse certain data formats or structures. For security reasons, we ask users to:
158+
🤗 Datasets may run Python code defined by the dataset authors to parse certain data formats or structures. For security reasons, we ask users to:
161159
- check the dataset scripts they're going to run beforehand and
162160
- pin the `revision` of the repositories they use.
163161

convert_dataset.sh

Lines changed: 0 additions & 185 deletions
This file was deleted.

tests/test_dataset_scripts.py

Lines changed: 0 additions & 67 deletions
This file was deleted.

utils/release.py

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,94 @@
1313
# limitations under the License.
1414

1515
import argparse
16+
import os
17+
import re
1618

19+
import packaging.version
1720

18-
CUSTOM_JS_FILE = "docs/source/_static/js/custom.js"
1921

22+
REPLACE_PATTERNS = {
23+
"init": (re.compile(r'^__version__\s+=\s+"([^"]+)"\s*$', re.MULTILINE), '__version__ = "VERSION"\n'),
24+
"setup": (re.compile(r'^(\s*)version\s*=\s*"[^"]+",', re.MULTILINE), r'\1version="VERSION",'),
25+
}
26+
REPLACE_FILES = {
27+
"init": "src/datasets/__init__.py",
28+
"setup": "setup.py",
29+
}
30+
README_FILE = "README.md"
2031

21-
def update_custom_js(version):
22-
"""Update the version table in the custom.js file."""
23-
with open(CUSTOM_JS_FILE, encoding="utf-8", newline="\n") as f:
24-
lines = f.readlines()
25-
index = 0
2632

27-
# First let's put the right version
28-
while not lines[index].startswith("const stableVersion ="):
29-
index += 1
30-
lines[index] = f'const stableVersion = "v{version}"\n'
33+
def update_version_in_file(fname, version, pattern):
34+
"""Update the version in one file using a specific pattern."""
35+
with open(fname, "r", encoding="utf-8", newline="\n") as f:
36+
code = f.read()
37+
re_pattern, replace = REPLACE_PATTERNS[pattern]
38+
replace = replace.replace("VERSION", version)
39+
code = re_pattern.sub(replace, code)
40+
with open(fname, "w", encoding="utf-8", newline="\n") as f:
41+
f.write(code)
3142

32-
# Then update the dictionary
33-
while not lines[index].startswith("const versionMapping = {"):
34-
index += 1
3543

36-
# We go until the end
37-
while not lines[index].startswith("}"):
38-
index += 1
39-
# We add the new version at the end
40-
lines[index - 1] += f' "v{version}": "v{version}",\n'
44+
def global_version_update(version, patch=False):
45+
"""Update the version in all needed files."""
46+
for pattern, fname in REPLACE_FILES.items():
47+
update_version_in_file(fname, version, pattern)
4148

42-
with open(CUSTOM_JS_FILE, "w", encoding="utf-8", newline="\n") as f:
43-
f.writelines(lines)
49+
50+
def get_version():
51+
"""Reads the current version in the __init__."""
52+
with open(REPLACE_FILES["init"], "r") as f:
53+
code = f.read()
54+
default_version = REPLACE_PATTERNS["init"][0].search(code).groups()[0]
55+
return packaging.version.parse(default_version)
56+
57+
58+
def pre_release_work(patch=False):
59+
"""Do all the necessary pre-release steps."""
60+
# First let's get the default version: base version if we are in dev, bump minor otherwise.
61+
default_version = get_version()
62+
if patch and default_version.is_devrelease:
63+
raise ValueError("Can't create a patch version from the dev branch, checkout a released version!")
64+
if default_version.is_devrelease:
65+
default_version = default_version.base_version
66+
elif patch:
67+
default_version = f"{default_version.major}.{default_version.minor}.{default_version.micro + 1}"
68+
else:
69+
default_version = f"{default_version.major}.{default_version.minor + 1}.0"
70+
71+
# Now let's ask nicely if that's the right one.
72+
version = input(f"Which version are you releasing? [{default_version}]")
73+
if len(version) == 0:
74+
version = default_version
75+
76+
print(f"Updating version to {version}.")
77+
global_version_update(version, patch=patch)
78+
79+
80+
def post_release_work():
81+
"""Do all the necesarry post-release steps."""
82+
# First let's get the current version
83+
current_version = get_version()
84+
dev_version = f"{current_version.major}.{current_version.minor + 1}.0.dev0"
85+
current_version = current_version.base_version
86+
87+
# Check with the user we got that right.
88+
version = input(f"Which version are we developing now? [{dev_version}]")
89+
if len(version) == 0:
90+
version = dev_version
91+
92+
print(f"Updating version to {version}.")
93+
global_version_update(version)
4494

4595

4696
if __name__ == "__main__":
4797
parser = argparse.ArgumentParser()
48-
parser.add_argument("--version", help="Release version.")
98+
parser.add_argument("--post_release", action="store_true", help="Whether this is pre or post release.")
99+
parser.add_argument("--patch", action="store_true", help="Whether or not this is a patch release.")
49100
args = parser.parse_args()
50-
update_custom_js(args.version)
101+
if not args.post_release:
102+
pre_release_work(patch=args.patch)
103+
elif args.patch:
104+
print("Nothing to do after a patch :-)")
105+
else:
106+
post_release_work()

0 commit comments

Comments
 (0)