Skip to content

Various fix for your PR #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .github/__init__.py
Empty file.
65 changes: 39 additions & 26 deletions .github/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ def normalize(name):
return re.sub(r"[-_.]+", "-", name).lower()


def normalize_version(version):
version = version.lower()
return version[1:] if version.startswith("v") else version


def is_stable(version):
return not ("dev" in version or "a" in version or "b" in version or "rc" in version)


def package_exists(soup, package_name):
package_ref = package_name + "/"
for anchor in soup.find_all('a'):
Expand All @@ -55,18 +64,19 @@ def register(pkg_name, version, author, short_desc, homepage):
with open(INDEX_FILE) as html_file:
soup = BeautifulSoup(html_file, "html.parser")
norm_pkg_name = normalize(pkg_name)
norm_version = normalize_version(version)

if package_exists(soup, norm_pkg_name):
raise ValueError("Package {} seems to already exists".format(norm_pkg_name))
raise ValueError(f"Package {norm_pkg_name} seems to already exists")

# Create a new anchor element for our new package
placeholder_card = BeautifulSoup(INDEX_CARD_HTML, 'html.parser')
placeholder_card = placeholder_card.find('a')
new_package = copy.copy(placeholder_card)
new_package['href'] = "{}/".format(norm_pkg_name)
new_package['href'] = f"{norm_pkg_name}/"
new_package.contents[0].replace_with(pkg_name)
spans = new_package.find_all('span')
spans[1].string = version # First span contain the version
spans[1].string = norm_version # First span contain the version
spans[2].string = short_desc # Second span contain the short description

# Add it to our index and save it
Expand All @@ -79,12 +89,12 @@ def register(pkg_name, version, author, short_desc, homepage):
template = temp_file.read()

template = template.replace("_package_name", pkg_name)
template = template.replace("_version", version)
template = template.replace("_link", "{}#egg={}-{}".format(link, norm_pkg_name, version))
template = template.replace("_version", norm_version)
template = template.replace("_link", f"{link}#egg={norm_pkg_name}-{norm_version}")
template = template.replace("_homepage", homepage)
template = template.replace("_author", author)
template = template.replace("_long_description", long_desc)
template = template.replace("_latest_main", version)
template = template.replace("_latest_main", norm_version)

os.mkdir(norm_pkg_name)
package_index = os.path.join(norm_pkg_name, INDEX_FILE)
Expand All @@ -97,50 +107,53 @@ def update(pkg_name, version):
with open(INDEX_FILE) as html_file:
soup = BeautifulSoup(html_file, "html.parser")
norm_pkg_name = normalize(pkg_name)
norm_version = normalize_version(version)

if not package_exists(soup, norm_pkg_name):
raise ValueError("Package {} seems to not exists".format(norm_pkg_name))
raise ValueError(f"Package {norm_pkg_name} seems to not exists")

# Change the version in the main page
anchor = soup.find('a', attrs={"href": "{}/".format(norm_pkg_name)})
spans = anchor.find_all('span')
spans[1].string = version
with open(INDEX_FILE, 'wb') as index:
index.write(soup.prettify("utf-8"))
# Change the version in the main page (only if stable)
if is_stable(version):
anchor = soup.find('a', attrs={"href": f"{norm_pkg_name}/"})
spans = anchor.find_all('span')
spans[1].string = norm_version
with open(INDEX_FILE, 'wb') as index:
index.write(soup.prettify("utf-8"))

# Change the package page
index_file = os.path.join(norm_pkg_name, INDEX_FILE)
with open(index_file) as html_file:
soup = BeautifulSoup(html_file, "html.parser")

# Extract the URL from the onclick attribute
button = soup.find('a', id='repoHomepage')
button = soup.find('button', id='repoHomepage')
if button:
link = button.get("href")
link = button.get("onclick")[len("location.href='"):-1]
else:
raise Exception("Homepage URL not found")

# Create a new anchor element for our new version
original_div = soup.find('section', class_='versions').findAll('div')[-1]
new_div = copy.copy(original_div)
anchors = new_div.find_all('a')
new_div['onclick'] = "load_readme('{}', scroll_to_div=true)".format(version)
new_div['id'] = version
anchor = new_div.find('a')
anchor['onclick'] = f"load_readme('{version}', scroll_to_div=true)"
new_div['id'] = norm_version
new_div['class'] = ""
if 'dev' in version:
if not is_stable(version):
new_div['class'] += "prerelease"
else:
# replace the latest main version
main_version_span = soup.find('span', id='latest-main-version')
main_version_span.string = version
anchors[0].string = version
anchors[1]['href'] = "git+{}@{}#egg={}-{}".format(link,version,norm_pkg_name,version)
main_version_span.string = norm_version
anchor.string = norm_version
anchor['href'] = f"git+{link}@{version}#egg={norm_pkg_name}-{norm_version}"

# Add it to our index
original_div.insert_after(new_div)

# Change the latest version
soup.html.body.div.section.find_all('span')[1].contents[0].replace_with(version)
# Change the latest version (if stable)
if is_stable(version):
soup.html.body.div.section.find_all('span')[1].contents[0].replace_with(norm_version)

# Save it
with open(index_file, 'wb') as index:
Expand All @@ -154,13 +167,13 @@ def delete(pkg_name):
norm_pkg_name = normalize(pkg_name)

if not package_exists(soup, norm_pkg_name):
raise ValueError("Package {} seems to not exists".format(norm_pkg_name))
raise ValueError(f"Package {norm_pkg_name} seems to not exists")

# Remove the package directory
shutil.rmtree(norm_pkg_name)

# Find and remove the anchor corresponding to our package
anchor = soup.find('a', attrs={"href": "{}/".format(norm_pkg_name)})
anchor = soup.find('a', attrs={"href": f"{norm_pkg_name}/"})
anchor.extract()
with open(INDEX_FILE, 'wb') as index:
index.write(soup.prettify("utf-8"))
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/register.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
required: true
type: string
version:
description: 'Version of the package'
description: 'Version of the package (tag name)'
required: true
type: string
author:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
required: true
type: string
version:
description: New version of the package
description: New version of the package (tag name)
required: true
type: string

Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ <h6 class="text-header">
<span>
</span>
<span class="version">
3.0
3.0.0
</span>
<br/>
<span class="description">
Expand Down
14 changes: 5 additions & 9 deletions mydependency/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,20 @@
<b>
Project links :
</b>
<a href="https://github.com/astariul/mydependency" target="_blank" id="repoHomepage">
<button>
Github Repository
</button>
</a>
<button onclick="location.href='https://github.com/astariul/mydependency'" id="repoHomepage">
Homepage
</button>
<p class="elem">
<b>
Author :
</b>
Nicolas Remond
</p>
<section class="versions" id="versions">
<div onclick="load_readme('1.0', scroll_to_div=true)" id="1.0">
<a>
<div id="1.0">
<a href="git+https://github.com/astariul/mydependency@v1.0#egg=mydependency-1.0" onclick="load_readme('1.0', scroll_to_div=true)">
1.0
</a>
<a href="git+https://github.com/astariul/mydependency@1.0#egg=mydependency-1.0">
</a>
</div>
</section>
</div>
Expand Down
14 changes: 5 additions & 9 deletions pkg_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,20 @@
<b>
Project links :
</b>
<a href="_homepage" target="_blank" id="repoHomepage">
<button>
Github Repository
</button>
</a>
<button onclick="location.href='_homepage'" id="repoHomepage">
Homepage
</button>
<p class="elem">
<b>
Author :
</b>
_author
</p>
<section class="versions" id="versions">
<div onclick="load_readme('_version', scroll_to_div=true)" id="_version">
<a>
<div id="_version">
<a href="_link" onclick="load_readme('_version', scroll_to_div=true)">
_version
</a>
<a href="_link">
</a>
</div>
</section>
</div>
Expand Down
14 changes: 5 additions & 9 deletions private-hello/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,20 @@
<b>
Project links :
</b>
<a href="https://github.com/astariul/private-hello" target="_blank" id="repoHomepage">
<button>
Github Repository
</button>
</a>
<button onclick="location.href='https://github.com/astariul/private-hello'" id="repoHomepage">
Homepage
</button>
<p class="elem">
<b>
Author :
</b>
Nicolas Remond
</p>
<section class="versions" id="versions">
<div onclick="load_readme('0.4.5', scroll_to_div=true)" id="0.4.5">
<a>
<div id="0.4.5">
<a href="git+https://github.com/astariul/private-hello@v0.4.5#egg=private-hello-0.4.5" onclick="load_readme('0.4.5', scroll_to_div=true)">
0.4.5
</a>
<a href="git+https://github.com/astariul/private-hello@0.4.5#egg=private-hello-0.4.5">
</a>
</div>
</section>
</div>
Expand Down
23 changes: 11 additions & 12 deletions public-hello/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,29 @@
<b>
Project links :
</b>
<a href="https://github.com/astariul/public-hello" id="repoHomepage" target="_blank">
<button>
Github Repository
</button>
</a>
<button id="repoHomepage" onclick="location.href='https://github.com/astariul/public-hello'">
Homepage
</button>
<p class="elem">
<b>
Author :
</b>
Nicolas Remond
</p>
<section class="versions" id="versions">
<div id="0.1" onclick="load_readme('0.1', scroll_to_div=true)">
<a>
<div id="0.1">
<a href="git+https://github.com/astariul/public-hello@0.1#egg=public-hello-0.1" onclick="load_readme('0.1', scroll_to_div=true)">
0.1
</a>
<a href="git+https://github.com/astariul/public-hello@0.1#egg=public-hello-0.1">
</a>
</div>
<div class="" id="0.2" onclick="load_readme('0.2', scroll_to_div=true)">
<a>
<div class="" id="0.2">
<a href="git+https://github.com/astariul/public-hello@0.2#egg=public-hello-0.2" onclick="load_readme('0.2', scroll_to_div=true)">
0.2
</a>
<a href="git+https://github.com/astariul/public-hello@0.2#egg=public-hello-0.2">
</div>
<div class="prerelease" id="0.3.dev0">
<a href="git+https://github.com/astariul/public-hello@0.3.dev0#egg=public-hello-0.3.dev0" onclick="load_readme('0.3.dev0', scroll_to_div=true)">
0.3.dev0
</a>
</div>
</section>
Expand Down
20 changes: 8 additions & 12 deletions transformers/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
<span>
</span>
<span id='latest-version' class="version">
3.0
3.0.0
</span>
<span id='latest-main-version' hidden>
3.0
3.0.0
</span>
</section>

Expand All @@ -69,23 +69,19 @@
<b>
Project links :
</b>
<a href="https://github.com/huggingface/transformers" target="_blank" id="repoHomepage">
<button>
Github Repository
</button>
</a>
<button onclick="location.href='https://github.com/huggingface/transformers'" id="repoHomepage">
Homepage
</button>
<p class="elem">
<b>
Author :
</b>
Nicolas Remond
</p>
<section class="versions" id="versions">
<div onclick="load_readme('3.0', scroll_to_div=true)" id="3.0">
<a>
3.0
</a>
<a href="git+https://github.com/huggingface/transformers@3.0#egg=transformers-3.0">
<div id="3.0.0">
<a href="git+https://github.com/huggingface/transformers@v3.0.0#egg=transformers-3.0.0" onclick="load_readme('3.0.0', scroll_to_div=true)">
3.0.0
</a>
</div>
</section>
Expand Down
Loading