parent
a31cf1d2ba
commit
ae59ba471d
@ -0,0 +1,148 @@
|
||||
From 52b6ff8d55d59ace29950621ed41175ac31fa90c Mon Sep 17 00:00:00 2001
|
||||
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
|
||||
Date: Wed, 31 Oct 2018 18:03:21 +0100
|
||||
Subject: [PATCH 09/10] add support for feeding user configuration
|
||||
|
||||
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
|
||||
---
|
||||
README.md | 26 ++++++++++++++++++++++++++
|
||||
README.rst | 5 -----
|
||||
rust2rpm/__main__.py | 13 +++++++++++++
|
||||
rust2rpm/templates/main.spec | 17 ++++++++++++++++-
|
||||
4 files changed, 55 insertions(+), 6 deletions(-)
|
||||
create mode 100644 README.md
|
||||
delete mode 100644 README.rst
|
||||
|
||||
diff --git a/README.md b/README.md
|
||||
new file mode 100644
|
||||
index 0000000..22b4b30
|
||||
--- /dev/null
|
||||
+++ b/README.md
|
||||
@@ -0,0 +1,26 @@
|
||||
+# rust2rpm
|
||||
+
|
||||
+Convert Rust crates to RPM.
|
||||
+
|
||||
+## `.rust2rpm.conf`
|
||||
+
|
||||
+You can place configuration file which is used as source for additional
|
||||
+information for spec generation.
|
||||
+
|
||||
+Some simple example would be better than many words ;)
|
||||
+
|
||||
+```ini
|
||||
+[DEFAULT]
|
||||
+buildrequires =
|
||||
+ pkgconfig(foo) >= 1.2.3
|
||||
+lib.requires =
|
||||
+ pkgconfig(foo) >= 1.2.3
|
||||
+
|
||||
+[fedora]
|
||||
+bin.requires =
|
||||
+ findutils
|
||||
+buildrequires =
|
||||
+lib.requires =
|
||||
+lib+default.requires =
|
||||
+ pkgconfig(bar) >= 2.0.0
|
||||
+```
|
||||
diff --git a/README.rst b/README.rst
|
||||
deleted file mode 100644
|
||||
index 8866027..0000000
|
||||
--- a/README.rst
|
||||
+++ /dev/null
|
||||
@@ -1,5 +0,0 @@
|
||||
-========
|
||||
-rust2rpm
|
||||
-========
|
||||
-
|
||||
-Convert Rust crates to RPM.
|
||||
diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py
|
||||
index d19cb47..18fac5c 100644
|
||||
--- a/rust2rpm/__main__.py
|
||||
+++ b/rust2rpm/__main__.py
|
||||
@@ -199,6 +199,11 @@ def make_diff_metadata(crate, version, patch=False, store=False):
|
||||
shutil.copy2(cratef, os.path.join(os.getcwd(), f"{metadata.name}-{version}.crate"))
|
||||
return crate, diff, metadata
|
||||
|
||||
+def to_list(s):
|
||||
+ if not s:
|
||||
+ return []
|
||||
+ return list(filter(None, (l.strip() for l in s.splitlines())))
|
||||
+
|
||||
def main():
|
||||
parser = argparse.ArgumentParser("rust2rpm",
|
||||
formatter_class=argparse.RawTextHelpFormatter)
|
||||
@@ -232,6 +237,7 @@ def main():
|
||||
store=args.store_crate)
|
||||
|
||||
JINJA_ENV.globals["normalize_deps"] = normalize_deps
|
||||
+ JINJA_ENV.globals["to_list"] = to_list
|
||||
template = JINJA_ENV.get_template("main.spec")
|
||||
|
||||
if args.patch and len(diff) > 0:
|
||||
@@ -287,6 +293,13 @@ def main():
|
||||
kwargs["license"] = license
|
||||
kwargs["license_comments"] = comments
|
||||
|
||||
+ conf = configparser.ConfigParser()
|
||||
+ conf.read(".rust2rpm.conf")
|
||||
+ if args.target not in conf:
|
||||
+ conf.add_section(args.target)
|
||||
+
|
||||
+ kwargs["distconf"] = conf[args.target]
|
||||
+
|
||||
spec_file = f"rust-{metadata.name}.spec"
|
||||
spec_contents = template.render(md=metadata, patch_file=patch_file, **kwargs)
|
||||
if args.stdout:
|
||||
diff --git a/rust2rpm/templates/main.spec b/rust2rpm/templates/main.spec
|
||||
index 0d9a80b..d901e6d 100644
|
||||
--- a/rust2rpm/templates/main.spec
|
||||
+++ b/rust2rpm/templates/main.spec
|
||||
@@ -65,6 +65,9 @@ BuildRequires: {{ req }}
|
||||
{% endfor %}
|
||||
%endif
|
||||
{% endif %}
|
||||
+{% for req in to_list(distconf.get("buildrequires"))|sort %}
|
||||
+BuildRequires: {{ req }}
|
||||
+{% endfor %}
|
||||
|
||||
%global _description \
|
||||
{% if md.description is none %}
|
||||
@@ -81,6 +84,9 @@ Summary: %{summary}
|
||||
{% if rust_group is defined %}
|
||||
Group: # FIXME
|
||||
{% endif %}
|
||||
+ {% for req in to_list(distconf.get("bin.requires"))|sort %}
|
||||
+Requires: {{ req }}
|
||||
+ {% endfor %}
|
||||
|
||||
%description -n %{crate}
|
||||
%{summary}.
|
||||
@@ -106,7 +112,13 @@ Group: # FIXME
|
||||
{% do features.insert(0, None) %}
|
||||
{% do features.insert(1, "default") %}
|
||||
{% for feature in features %}
|
||||
- {% set pkg = "-n %%{name}+%s-devel"|format(feature) if feature is not none else " devel" %}
|
||||
+ {% if feature is none %}
|
||||
+ {% set pkg = " devel" %}
|
||||
+ {% set conf_prefix = "lib" %}
|
||||
+ {% else %}
|
||||
+ {% set pkg = "-n %%{name}+%s-devel"|format(feature) %}
|
||||
+ {% set conf_prefix = "lib+%s"|format(feature) %}
|
||||
+ {% endif %}
|
||||
%package {{ pkg }}
|
||||
Summary: %{summary}
|
||||
{% if rust_group is defined %}
|
||||
@@ -122,6 +134,9 @@ Requires: cargo
|
||||
Requires: {{ req }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
+ {% for req in to_list(distconf.get("%s.requires"|format(conf_prefix)))|sort %}
|
||||
+Requires: {{ req }}
|
||||
+ {% endfor %}
|
||||
|
||||
%description {{ pkg }} %{_description}
|
||||
|
||||
--
|
||||
2.19.1
|
||||
|
@ -0,0 +1,94 @@
|
||||
From 00ed1ce05d9dd4c8042f27ca959350ce34fb1be5 Mon Sep 17 00:00:00 2001
|
||||
From: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
|
||||
Date: Wed, 31 Oct 2018 17:00:58 +0100
|
||||
Subject: [PATCH 10/10] trivial: use f-strings everywhere
|
||||
|
||||
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
|
||||
---
|
||||
rust2rpm/__main__.py | 22 +++++++++++-----------
|
||||
1 file changed, 11 insertions(+), 11 deletions(-)
|
||||
|
||||
diff --git a/rust2rpm/__main__.py b/rust2rpm/__main__.py
|
||||
index 18fac5c..b4eb624 100644
|
||||
--- a/rust2rpm/__main__.py
|
||||
+++ b/rust2rpm/__main__.py
|
||||
@@ -79,7 +79,7 @@ def detect_packager():
|
||||
if git is not None:
|
||||
name = subprocess.check_output([git, "config", "user.name"], universal_newlines=True).strip()
|
||||
email = subprocess.check_output([git, "config", "user.email"], universal_newlines=True).strip()
|
||||
- return "{} <{}>".format(name, email)
|
||||
+ return f"{name} <{email}>"
|
||||
|
||||
return None
|
||||
|
||||
@@ -108,23 +108,23 @@ def local_crate(crate, version):
|
||||
def download(crate, version):
|
||||
if version is None:
|
||||
# Now we need to get latest version
|
||||
- url = requests.compat.urljoin(API_URL, "crates/{}/versions".format(crate))
|
||||
+ url = requests.compat.urljoin(API_URL, f"crates/{crate}/versions")
|
||||
req = requests.get(url)
|
||||
req.raise_for_status()
|
||||
versions = req.json()["versions"]
|
||||
version = next(version["num"] for version in versions if not version["yanked"])
|
||||
|
||||
os.makedirs(CACHEDIR, exist_ok=True)
|
||||
- cratef_base = "{}-{}.crate".format(crate, version)
|
||||
+ cratef_base = f"{crate}-{version}.crate"
|
||||
cratef = os.path.join(CACHEDIR, cratef_base)
|
||||
if not os.path.isfile(cratef):
|
||||
- url = requests.compat.urljoin(API_URL, "crates/{}/{}/download#".format(crate, version))
|
||||
+ url = requests.compat.urljoin(API_URL, f"crates/{crate}/{version}/download#")
|
||||
req = requests.get(url, stream=True)
|
||||
req.raise_for_status()
|
||||
total = int(req.headers["Content-Length"])
|
||||
with remove_on_error(cratef), \
|
||||
open(cratef, "wb") as f:
|
||||
- for chunk in tqdm.tqdm(req.iter_content(), "Downloading {}".format(cratef_base),
|
||||
+ for chunk in tqdm.tqdm(req.iter_content(), f"Downloading {cratef_base}".format(cratef_base),
|
||||
total=total, unit="B", unit_scale=True):
|
||||
f.write(chunk)
|
||||
return cratef, crate, version
|
||||
@@ -132,14 +132,14 @@ def download(crate, version):
|
||||
@contextlib.contextmanager
|
||||
def toml_from_crate(cratef, crate, version):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
- target_dir = "{}/".format(tmpdir)
|
||||
+ target_dir = f"{tmpdir}/"
|
||||
with tarfile.open(cratef, "r") as archive:
|
||||
for n in archive.getnames():
|
||||
if not os.path.abspath(os.path.join(target_dir, n)).startswith(target_dir):
|
||||
raise Exception("Unsafe filenames!")
|
||||
archive.extractall(target_dir)
|
||||
- toml_relpath = "{}-{}/Cargo.toml".format(crate, version)
|
||||
- toml = "{}/{}".format(tmpdir, toml_relpath)
|
||||
+ toml_relpath = f"{crate}-{version}/Cargo.toml"
|
||||
+ toml = f"{tmpdir}/{toml_relpath}"
|
||||
if not os.path.isfile(toml):
|
||||
raise IOError("crate does not contain Cargo.toml file")
|
||||
yield toml
|
||||
@@ -270,7 +270,7 @@ def main():
|
||||
kwargs["include_provides"] = True
|
||||
kwargs["include_requires"] = True
|
||||
else:
|
||||
- assert False, "Unknown target {!r}".format(args.target)
|
||||
+ assert False, f"Unknown target {args.target!r}"
|
||||
|
||||
if args.target == "mageia":
|
||||
kwargs["pkg_release"] = "%mkrel 1"
|
||||
@@ -303,10 +303,10 @@ def main():
|
||||
spec_file = f"rust-{metadata.name}.spec"
|
||||
spec_contents = template.render(md=metadata, patch_file=patch_file, **kwargs)
|
||||
if args.stdout:
|
||||
- print("# {}".format(spec_file))
|
||||
+ print(f"# {spec_file}")
|
||||
print(spec_contents)
|
||||
if patch_file is not None:
|
||||
- print("# {}".format(patch_file))
|
||||
+ print(f"# {patch_file}")
|
||||
print("".join(diff), end="")
|
||||
else:
|
||||
with open(spec_file, "w") as fobj:
|
||||
--
|
||||
2.19.1
|
||||
|
Loading…
Reference in new issue