-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from adfinis/jlf/feat-build-packages
feat: build packages
- Loading branch information
Showing
7 changed files
with
249 additions
and
2 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
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,4 +1,5 @@ | ||
__pycache__ | ||
/.hypothesis | ||
/.dmypy.json | ||
/.coverage | ||
/.coverage | ||
/dist |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,84 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import os | ||
import shutil | ||
from pathlib import Path | ||
from subprocess import PIPE, run | ||
from tempfile import NamedTemporaryFile | ||
|
||
from tomli import load | ||
from tomli_w import dump | ||
|
||
base = Path(__file__).resolve().absolute().parent.parent | ||
|
||
version_tag = "%global pypi_version " | ||
source_tag = "Source0: " | ||
|
||
|
||
def fix_spec(spec, version, package): | ||
with spec.open("r", encoding="UTF-8") as f: | ||
data = f.read() | ||
with spec.open("w", encoding="UTF-8") as f: | ||
for line in data.splitlines(): | ||
if line.startswith("%changelog"): | ||
break | ||
if line.startswith(version_tag): | ||
f.write(f"{version_tag}{version}\n") | ||
elif line.startswith(source_tag): | ||
f.write(f"{source_tag}{package}\n") | ||
else: | ||
f.write(f"{line}\n") | ||
|
||
|
||
def main(): | ||
build_id = run( | ||
["git", "rev-parse", "--short", "HEAD"], | ||
stdout=PIPE, | ||
check=True, | ||
encoding="UTF-8", | ||
).stdout.strip() | ||
dist = base / "dist" | ||
shutil.rmtree(dist, ignore_errors=True) | ||
target = Path(os.path.expanduser("~/rpmbuild")) | ||
shutil.rmtree(target, ignore_errors=True) | ||
pyproject = base / "pyproject.toml" | ||
with pyproject.open("rb") as f: | ||
project = load(f) | ||
version_orig = project["tool"]["poetry"]["version"] | ||
version = f"{version_orig}+{build_id}" | ||
project["tool"]["poetry"]["version"] = version | ||
try: | ||
temp_toml_path = None | ||
with NamedTemporaryFile("wb", delete=False) as temp_toml: | ||
temp_toml_path = Path(temp_toml.name) | ||
with pyproject.open("rb") as f: | ||
temp_toml.write(f.read()) | ||
with pyproject.open("wb") as f: | ||
dump(project, f) | ||
# hack to disable git: poetry has a bug | ||
git = Path("/usr/bin/git") | ||
git_dis = Path("/usr/bin/git_dis") | ||
git.rename(git_dis) | ||
run(["poetry", "build"], check=True) | ||
finally: | ||
git_dis.rename(git) | ||
if temp_toml_path: | ||
with temp_toml_path.open("rb") as temp_file: | ||
with pyproject.open("wb") as f: | ||
f.write(temp_file.read()) | ||
|
||
package = Path(list(dist.glob("pyaptly-*+*.tar.gz"))[0]) | ||
run(["pyp2rpm", "-s", "-d", target, package], check=True) | ||
spec = target / "SPECS" / "python-pyaptly.spec" | ||
sources = target / "SOURCES" | ||
sources.mkdir() | ||
shutil.copy2(package, sources) | ||
fix_spec(spec, version.replace("+", "^"), package.name) | ||
run(["rpmbuild", "-bs", spec], check=True) | ||
srpms = target / "SRPMS" | ||
rpm = str(list(srpms.glob("python-pyaptly-*.src.rpm"))[0]) | ||
shutil.copy2(rpm, dist) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |