-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,254 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# name: Run tests for parselmouth | ||
|
||
on: | ||
push: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
jobs: | ||
run_tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.9' # Specify your Python version | ||
|
||
- uses: prefix-dev/[email protected] | ||
with: | ||
pixi-version: "latest" | ||
manifest-path: pyproject.toml | ||
|
||
- name: run tests | ||
run: | | ||
pixi run run_tests | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import requests | ||
import logging | ||
from conda_forge_metadata.artifact_info.info_json import get_artifact_info_as_json | ||
|
||
|
||
def get_all_archs_available() -> list[str]: | ||
response = requests.get("https://conda.anaconda.org/conda-forge/channeldata.json") | ||
channel_json = response.json() | ||
# Collect all subdirectories | ||
subdirs: list[str] = [] | ||
for package in channel_json["packages"].values(): | ||
subdirs.extend(package.get("subdirs", [])) | ||
|
||
return list(set(subdirs)) | ||
|
||
|
||
def get_subdir_repodata(subdir: str) -> dict: | ||
url = f"https://conda.anaconda.org/conda-forge/{subdir}/repodata.json" | ||
response = requests.get(url) | ||
if not response.ok: | ||
logging.error(f"Requst for repodata to {url} failed. {response.reason}") | ||
|
||
response.raise_for_status() | ||
|
||
return response.json() | ||
|
||
|
||
def get_all_packages_by_subdir(subdir: str) -> dict[str, dict]: | ||
repodatas: dict[str, dict] = {} | ||
|
||
repodata = get_subdir_repodata(subdir) | ||
|
||
repodatas.update(repodata["packages"]) | ||
repodatas.update(repodata["packages.conda"]) | ||
|
||
return repodatas | ||
|
||
|
||
def get_artifact_info(subdir, artifact, backend, channel="conda-forge"): | ||
return get_artifact_info_as_json(channel, subdir, artifact, backend) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,26 @@ | ||
import io | ||
import json | ||
import boto3 | ||
import os | ||
from dotenv import load_dotenv | ||
import logging | ||
|
||
load_dotenv() | ||
from parselmouth.s3 import s3_client | ||
|
||
account_id = os.environ["R2_PREFIX_ACCOUNT_ID"] | ||
access_key_id = os.environ["R2_PREFIX_ACCESS_KEY_ID"] | ||
access_key_secret = os.environ["R2_PREFIX_SECRET_ACCESS_KEY"] | ||
bucket_name = os.environ["R2_PREFIX_BUCKET"] | ||
|
||
|
||
def upload(file_name: str, bucket_name: str, file_body: dict, s3_client): | ||
output = json.dumps(file_body) | ||
output_as_file = io.BytesIO(output.encode("utf-8")) | ||
|
||
s3_client.upload_fileobj(output_as_file, bucket_name, f"hash-v0/{file_name}") | ||
|
||
|
||
if __name__ == "__main__": | ||
s3_client = boto3.client( | ||
service_name="s3", | ||
endpoint_url=f"https://{account_id}.r2.cloudflarestorage.com", | ||
aws_access_key_id=f"{access_key_id}", | ||
aws_secret_access_key=f"{access_key_secret}", | ||
region_name="eeur", # Must be one of: wnam, enam, weur, eeur, apac, auto | ||
) | ||
|
||
obj_key = "hash-v0/index.json" | ||
response = s3_client.get_object(Bucket=bucket_name, Key=obj_key) | ||
existing_mapping_data: dict = json.loads(response["Body"].read().decode("utf-8")) | ||
def main(output_dir: str = "output"): | ||
existing_mapping_data = s3_client.get_mapping() | ||
|
||
total_new_files = 0 | ||
|
||
for filename in os.listdir("output"): | ||
filepath = os.path.join("output", filename) | ||
for filename in os.listdir(output_dir): | ||
filepath = os.path.join(output_dir, filename) | ||
with open(filepath) as partial_file: | ||
partial_json = json.load(partial_file) | ||
existing_mapping_data.update(partial_json) | ||
total_new_files += 1 | ||
|
||
print(f"Total new files {total_new_files}") | ||
logging.info(f"Total new files {total_new_files}") | ||
|
||
s3_client.upload_mapping(existing_mapping_data, "index.json") | ||
|
||
upload("index.json", bucket_name, existing_mapping_data, s3_client) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import re | ||
|
||
|
||
def normalize(name: str) -> str: | ||
return re.sub(r"[-_.]+", "-", name).lower() |
Oops, something went wrong.