Skip to content

Commit

Permalink
add placeholder for opencv-python
Browse files Browse the repository at this point in the history
  • Loading branch information
bjia56 committed Oct 20, 2023
1 parent bbd7cd3 commit 8db2c56
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 23 deletions.
3 changes: 3 additions & 0 deletions pypi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ <h6 class="text-header">
<a class="card" href="psutil/">
psutil
</a>
<a class="card" href="opencv-python/">
opencv_python
</a>
</div>
</body>
</html>
68 changes: 68 additions & 0 deletions pypi/opencv-python/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8"/>
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport"/>
<!-- Skeleton CSS -->
<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"/>
<style>
body { font-family: "Montserrat"; }
code {
font-size: 100%;
display: inline-block !important;
font-size: 1.4rem; }
.header {
margin-top: 15rem;
font-size: 3.6rem;
font-weight: 400;
letter-spacing: -.1rem; }
.text-header {
text-transform: uppercase;
font-size: 1.4rem;
letter-spacing: .2rem;
font-weight: 600; }
.version {
font-size: 2.3rem;
font-style: italic;
font-weight: 300; }
.elem { margin: 1rem 0rem; }
</style>
<title>
PyPI - Python Wheels for armv7l
</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<script>
function annotateDownloadCount(releaseTag, anchorElement) {
fetch("https://api.github.com/repos/bjia56/armv7l-wheels/releases/tags/" + releaseTag)
.then(async resp => {
let release = await resp.json();
let downloadCount = release.assets[0].download_count;
anchorElement.innerText = anchorElement.innerText + " (" + downloadCount + " downloads)";
})
.catch(e => console.log(e));
}

function annotateAll() {
Array.from(document.links).forEach(anchor => annotateDownloadCount(anchor.href.split("/")[7], anchor));
}

$(document).ready(annotateAll);
</script>
</head>
<body>
<div class="container">
<section class="header">
opencv_python
</section>
<pre><code>pip install opencv_python --extra-index-url https://bjia56.github.io/armv7l-wheels/</code></pre>
<br/>
<a href="_link">
_filename
</a>
<hr/>
</div>
</body>
</html>
59 changes: 36 additions & 23 deletions scripts/generate_pypi_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,51 @@ def package_exists(soup, package_name):
def update(pkg_name: str, link: str) -> None:
norm_pkg_name = normalize(pkg_name)

url = urlparse(link)
filename = url.path.split('/')[-1]

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

anchors = soup.find_all('a')
skip_add = False
for anchor in anchors:
if anchor['href'] == link:
return

# Create a new anchor element for our new version
last_anchor = anchors[-1] # Copy the last anchor element
new_anchor = copy.copy(last_anchor)
new_anchor['href'] = link
url = urlparse(link)
filename = url.path.split('/')[-1]
new_anchor.contents[0].replace_with(filename)

# Add it to our index
br = soup.new_tag("br")
last_anchor.insert_after(br)
br.insert_after(new_anchor)
if anchor['href'] == "_link":
anchor['href'] = link
anchor.contents[0].replace_with(filename)
skip_add = True

if not skip_add:
# Create a new anchor element for our new version
last_anchor = anchors[-1] # Copy the last anchor element
new_anchor = copy.copy(last_anchor)
new_anchor['href'] = link
new_anchor.contents[0].replace_with(filename)

# Add it to our index
br = soup.new_tag("br")
last_anchor.insert_after(br)
br.insert_after(new_anchor)

# Save it
with open(index_file, 'wb') as index:
index.write(soup.prettify("utf-8"))


def register_or_update(pkg_name: str, link: str) -> None:
def register_or_update(pkg_name: str, link: str = None) -> None:
# Read our index first
root_index = os.path.join(PYPI_DIR, INDEX_FILE)
with open(root_index) as html_file:
soup = BeautifulSoup(html_file, "html.parser")
norm_pkg_name = normalize(pkg_name)

if package_exists(soup, norm_pkg_name):
update(pkg_name, link)
if link:
update(pkg_name, link)
return

# Create a new anchor element for our new package
Expand All @@ -83,12 +91,13 @@ def register_or_update(pkg_name: str, link: str) -> None:
with open(os.path.join(PYPI_DIR, TEMPLATE_FILE)) as temp_file:
template = temp_file.read()

url = urlparse(link)
filename = url.path.split('/')[-1]

template = template.replace("_package_name", pkg_name)
template = template.replace("_link", link)
template = template.replace("_filename", filename)
if link:
url = urlparse(link)
filename = url.path.split('/')[-1]

template = template.replace("_link", link)
template = template.replace("_filename", filename)

os.mkdir(os.path.join(PYPI_DIR, norm_pkg_name))
package_index = os.path.join(PYPI_DIR, norm_pkg_name, INDEX_FILE)
Expand All @@ -105,9 +114,13 @@ def main() -> None:
package = sys.argv[2]

release = requests.get(api).json()
for asset in release["assets"]:
url = asset["browser_download_url"]
register_or_update(package, url)
if "assets" in release:
for asset in release["assets"]:
url = asset["browser_download_url"]
register_or_update(package, url)
else:
print(f"Warning: No release found, but will ensure package directory exists")
register_or_update(package)


if __name__ == "__main__":
Expand Down

0 comments on commit 8db2c56

Please sign in to comment.