Skip to content

General fix and update styles #71

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 25 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
de8a140
:wrench: Update actions and workflows
Dec 28, 2023
e46e40b
:art: Add static folder
Dec 28, 2023
bc23691
:sparkles: add script to update packages
Dec 28, 2023
d74d2af
:lipstick: Add new styles and update existing styles
Dec 28, 2023
900b586
:lipstick: Update existing packages
Dec 28, 2023
b972d87
:lipstick: Change go back anchor to button
Dec 29, 2023
b42176d
:lipstick: Remove footer from package template
Dec 29, 2023
9fca18f
:lipstick: Latest tag will be visible always
Dec 29, 2023
cd31d79
:recycle: Remove unused code
Dec 29, 2023
9e636db
:lipstick:
Dec 29, 2023
8ba538b
:lipstick: Update existing packages
Dec 29, 2023
b98164d
:lipstick: Remove footer from index
Dec 29, 2023
51ec1fe
:recycle: Remove template anchor and add it as variable on actions.py
Dec 29, 2023
da3939a
🐛 Fix tag names in update script + use python directly instead of cal…
astariul Dec 29, 2023
a4b6de7
🐛 Add init.py to allow import of python code
astariul Dec 29, 2023
03b00ca
🐛 Make sure the templates are PEP 503 compliant by keeping only ancho…
astariul Dec 29, 2023
4d7fa48
📝 Improve description of version in github actions
astariul Dec 29, 2023
34d120c
🚀 Update current packages to fit latest changes
astariul Dec 29, 2023
05ee7a2
🐛 Move onclick from the div to the anchor to ensure the README is loa…
astariul Dec 30, 2023
0034696
🚀 Update packages to reflect latest changes
astariul Dec 30, 2023
3ba584b
Merge pull request #1 from astariul/my_branch
pabnas Dec 31, 2023
7b4905e
:bug: Version anchors now can be selected and triggers the onclick fu…
Dec 31, 2023
c7dd592
:lipstick: Homepage button now opens in a new tab
Dec 31, 2023
4ed1290
:lipstick: Refactor some styles
Dec 31, 2023
78a9726
:lipstick: Update current packages to fit latest changes
Dec 31, 2023
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.
123 changes: 90 additions & 33 deletions .github/actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import json
import copy
import re
import shutil
Expand All @@ -11,12 +10,35 @@
TEMPLATE_FILE = "pkg_template.html"
YAML_ACTION_FILES = [".github/workflows/delete.yml", ".github/workflows/update.yml"]

INDEX_CARD_HTML = '''
<a class="card" href="">
placeholder_name
<span>
</span>
<span class="version">
placehholder_version
</span>
<br/>
<span class="description">
placeholder_description
</span>
</a>'''


def normalize(name):
""" From PEP503 : https://www.python.org/dev/peps/pep-0503/ """
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 @@ -25,26 +47,40 @@ def package_exists(soup, package_name):
return False


def register(pkg_name, version, author, short_desc, long_desc, homepage, link):
def transform_github_url(input_url):
# Split the input URL to extract relevant information
parts = input_url.rstrip('/').split('/')
username, repo = parts[-2], parts[-1]

# Create the raw GitHub content URL
raw_url = f'https://raw.githubusercontent.com/{username}/{repo}/main/README.md'
return raw_url


def register(pkg_name, version, author, short_desc, homepage):
link = f'git+{homepage}@{version}'
long_desc = transform_github_url(homepage)
# Read our index first
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
last_anchor = soup.find_all('a')[-1] # Copy the last anchor element
new_anchor = copy.copy(last_anchor)
new_anchor['href'] = "{}/".format(norm_pkg_name)
new_anchor.contents[0].replace_with(pkg_name)
spans = new_anchor.find_all('span')
spans[1].string = version # First span contain the version
placeholder_card = BeautifulSoup(INDEX_CARD_HTML, 'html.parser')
placeholder_card = placeholder_card.find('a')
new_package = copy.copy(placeholder_card)
new_package['href'] = f"{norm_pkg_name}/"
new_package.contents[0].replace_with(pkg_name)
spans = new_package.find_all('span')
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
last_anchor.insert_after(new_anchor)
soup.find('h6', class_='text-header').insert_after(new_package)
with open(INDEX_FILE, 'wb') as index:
index.write(soup.prettify("utf-8"))

Expand All @@ -53,49 +89,71 @@ def register(pkg_name, version, author, short_desc, long_desc, homepage, link):
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", norm_version)

os.mkdir(norm_pkg_name)
package_index = os.path.join(norm_pkg_name, INDEX_FILE)
with open(package_index, "w") as f:
f.write(template)


def update(pkg_name, version, link):
def update(pkg_name, version):
# Read our index first
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('button', id='repoHomepage')
if button:
link = button.get("onclick")[len("location.href='"):-1]
else:
raise Exception("Homepage URL not found")

# Create a new anchor element for our new version
last_anchor = soup.find_all('a')[-1] # Copy the last anchor element
new_anchor = copy.copy(last_anchor)
new_anchor['href'] = "{}#egg={}-{}".format(link, norm_pkg_name, version)
original_div = soup.find('section', class_='versions').findAll('div')[-1]
new_div = copy.copy(original_div)
anchor = new_div.find('a')
new_div['onclick'] = f"load_readme('{version}', scroll_to_div=true);"
new_div['id'] = norm_version
new_div['class'] = ""
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 = norm_version
anchor.string = norm_version
anchor['href'] = f"git+{link}@{version}#egg={norm_pkg_name}-{norm_version}"

# Add it to our index
last_anchor.insert_after(new_anchor)
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 @@ -109,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 All @@ -131,17 +189,16 @@ def main():
version=os.environ["PKG_VERSION"],
author=os.environ["PKG_AUTHOR"],
short_desc=os.environ["PKG_SHORT_DESC"],
long_desc=os.environ["PKG_LONG_DESC"],
homepage=os.environ["PKG_HOMEPAGE"],
link=os.environ["PKG_LINK"],
)
elif action == "DELETE":
delete(pkg_name=os.environ["PKG_NAME"])
delete(
pkg_name=os.environ["PKG_NAME"]
)
elif action == "UPDATE":
update(
pkg_name=os.environ["PKG_NAME"],
version=os.environ["PKG_VERSION"],
link=os.environ["PKG_LINK"],
version=os.environ["PKG_VERSION"]
)


Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/register.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,21 @@ on:
required: true
type: string
version:
description: 'Version of the package'
description: 'Version of the package (tag name)'
required: true
type: string
author:
description: 'Author(s) of the package'
required: true
type: string
short_desc:
description: 'A short description of the package'
required: true
type: string
long_desc:
description: 'A longer description of the package (HTML)'
description: 'A short description of the package to show on the index'
required: true
type: string
homepage:
description: 'Homepage of the package (link to the github repository)'
required: true
type: string
link:
description: 'Link used for `pip`. For example, for a github-hosted package refered by the tag `v3.0.2`, it would be : git+https://github.com/huggingface/transformers@v3.0.2'
required: true
type: string

jobs:
update:
Expand All @@ -52,9 +44,7 @@ jobs:
PKG_VERSION: ${{ inputs.version }}
PKG_AUTHOR: ${{ inputs.author }}
PKG_SHORT_DESC: ${{ inputs.short_desc }}
PKG_LONG_DESC: ${{ inputs.long_desc }}
PKG_HOMEPAGE: ${{ inputs.homepage }}
PKG_LINK: ${{ inputs.link }}
run: |
pip install beautifulsoup4
python .github/actions.py
Expand Down
8 changes: 1 addition & 7 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ on:
required: true
type: string
version:
description: New version of the package
required: true
type: string
link:
description: 'Link used for `pip`. For example, for a github-hosted package
refered by the tag `v3.0.2`, it would be : git+https://github.com/huggingface/transformers@v3.0.2'
description: New version of the package (tag name)
required: true
type: string

Expand All @@ -35,7 +30,6 @@ jobs:
PKG_ACTION: UPDATE
PKG_NAME: ${{ inputs.package_name }}
PKG_VERSION: ${{ inputs.version }}
PKG_LINK: ${{ inputs.link }}
run: |
pip install beautifulsoup4
python .github/actions.py
Expand Down
82 changes: 19 additions & 63 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,16 @@
<link crossorigin="anonymous" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css" rel="stylesheet"/>
<!-- Font -->
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;600&amp;display=swap" rel="stylesheet" type="text/css"/>
<!-- JQuery -->
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<!-- Our JS -->
<script type="text/javascript" src="pypi_checker.js"></script>
<!-- Favicon -->
<link href="https://gist.githubusercontent.com/astariul/c09af596e802e945d3032774e10e1047/raw/f693a2e2b65966494da082887bc4be2917f615e4/random_icon.svg" rel="icon"/>
<style>
body { font-family: "Montserrat"; }
code {
font-size: 100%;
display: inline-block !important;
font-size: 1.3rem; }
.header {
margin-top: 6rem;
text-align: center; }
.text-header {
text-transform: uppercase;
font-size: 1.4rem;
letter-spacing: .2rem;
font-weight: 600; }
.card {
display: inline-block;
height: auto;
min-width: 32%;
padding: 0.5rem 2rem;
margin: 0.5rem 0.5rem;
color: #555;
font-size: 1.5rem;
font-weight: 600;
line-height: 1.5;
letter-spacing: .05rem;
text-decoration: none;
white-space: normal;
background-color: transparent;
border-radius: 4px;
border: 1px solid #bbb;
cursor: pointer;
box-sizing: border-box; }
.card:hover {
border-color: darkcyan;
color: darkcyan; }
.version {
font-size: 1rem;
font-style: italic;}
.description {
font-weight: 300; }
.redalert {
border-color: crimson;
color: crimson; }
.redalert:hover {
border-color: tomato;
color: tomato;
}
</style>
<!-- Custom Styles -->
<link href="static/index_styles.css" rel="stylesheet"/>
<!-- JQuery -->
<script src="https://code.jquery.com/jquery-latest.min.js">
</script>
<!-- Our JS -->
<script src="static/pypi_checker.js" type="text/javascript">
</script>
<title>
Pypi - YourCompany
</title>
Expand Down Expand Up @@ -128,7 +84,7 @@ <h6 class="text-header">
<span>
</span>
<span class="version">
3.0
3.0.0
</span>
<br/>
<span class="description">
Expand All @@ -137,19 +93,19 @@ <h6 class="text-header">
</a>
</div>
<script>
$(document).ready(function(){
$(document).ready(function(){
for (let lnk of document.getElementsByTagName('a')) {
var content = lnk.textContent.trim().replace(/\s\s+/g, ' ').split(" ");
var pkg_name = content[0];
var pkg_vers = content[1];
var content = lnk.textContent.trim().replace(/\s\s+/g, ' ').split(" ");
var pkg_name = content[0];
var pkg_vers = content[1];

function mark_red() {
lnk.classList.add("redalert");
}
function mark_red() {
lnk.classList.add("redalert");
}

check_supply_chain_attack(pkg_name, pkg_vers, mark_red);
check_supply_chain_attack(pkg_name, pkg_vers, mark_red);
}
});
});
</script>
</body>
</html>
</html>
Loading