Skip to content

Commit

Permalink
ci: add basic test + lint steps
Browse files Browse the repository at this point in the history
  • Loading branch information
jsou committed May 8, 2020
1 parent e530ab7 commit 13bab41
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Copyright checks
run: |
make copyright
- name: Linting with flake8
run: |
pip install flake8
make flake8
- name: Linting with pylint
run: |
pip install pytest pylint pylint-quotes
make pylint
- name: Tests
run: |
pip install pytest
make unittest
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
short_ver = 0.0.1
long_ver = $(shell git describe --long 2>/dev/null || echo $(short_ver)-0-unknown-g`git describe --always`)

all:
all:

PYTHON ?= python3
PYTHON_SOURCE_DIRS = rpm_s3_mirror/ tests/
Expand All @@ -28,7 +28,7 @@ build-dep-fed:
python3-boto3 \
python3-lxml

test: copyright pylint unittest
test: copyright lint unittest

reformat:
yapf --parallel --recursive --in-place tests/ rpm_s3_mirror/
Expand All @@ -46,9 +46,11 @@ coverage:
$(PYTHON) -m coverage report --show-missing

pylint:
$(PYTHON) -m pylint.lint --rcfile .pylintrc $(PYTHON_SOURCE_DIRS)
pylint --rcfile .pylintrc $(PYTHON_SOURCE_DIRS)

flake8:
$(PYTHON) -m flake8 --exclude=__init__.py --ignore=E722 --max-line-len=125 $(PYTHON_SOURCE_DIRS)

lint: pylint flake8

.PHONY: rpm
6 changes: 3 additions & 3 deletions rpm_s3_mirror/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,13 @@ def _rewrite_primary(self, temp_dir, primary: RepodataSection):
)

def _rewrite_repomd(self, repomd_xml, snapshot: SnapshotPrimary):
for element in repomd_xml.findall(f"repo:*", namespaces=namespaces):
for element in repomd_xml.findall("repo:*", namespaces=namespaces):
# We only support *.xml.gz files currently
if element.attrib.get("type", None) not in {"primary", "filelists", "other"}:
repomd_xml.remove(element)

# Rewrite the XML with correct metadata for our changed primary.xml
for element in repomd_xml.find(f"repo:data[@type='primary']", namespaces=namespaces):
for element in repomd_xml.find("repo:data[@type='primary']", namespaces=namespaces):
_, _, key = element.tag.partition("}")
if key == "checksum":
element.text = snapshot.checksum
Expand All @@ -246,7 +246,7 @@ def _extract_package_list(self, primary: RepodataSection) -> PackageList:

def parse_repomd(self, xml: Element) -> Dict[str, RepodataSection]:
sections = {}
for data_element in xml.findall(f"repo:data", namespaces=namespaces):
for data_element in xml.findall("repo:data", namespaces=namespaces):
section_type = data_element.attrib["type"]
section = {}
for element in xml.findall(f"repo:data[@type='{section_type}']/repo:*", namespaces=namespaces):
Expand Down
10 changes: 6 additions & 4 deletions rpm_s3_mirror/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,12 @@ def put_object(self, local_path: str, key: str, cache_age=31536000):
ACL="public-read",
Bucket=self.bucket_name,
CacheControl=f"max-age={cache_age}",
# S3 is not very nice and cannot handle the "+" sign in filenames (https://forums.aws.amazon.com/thread.jspa?threadID=55746).
# Everything works fine when uploading but when you attempt to retrieve the file it is urlencoded to %2B, which of course
# breaks DNF as it doesn't try to decode the URL when retrieving the file. We can hack around this problem by replacing the "+"
# character with a space as S3 interprets that as a "+" sign on retrieval :(
# S3 is not very nice and cannot handle the "+" sign in filenames
# (https://forums.aws.amazon.com/thread.jspa?threadID=55746).
# Everything works fine when uploading but when you attempt to retrieve the file # it is urlencoded to %2B,
# which of course breaks DNF as it doesn't try to decode the URL when retrieving the file.
# We can hack around this problem by replacing the "+" character with a space as
# S3 interprets that as a "+" sign on retrieval :(
Key=key.replace("+", " "),
Body=package_fp,
ContentMD5=md5_header
Expand Down

0 comments on commit 13bab41

Please sign in to comment.