#206 minor code fixes and cleanups all around
Merged 2 years ago by zbyszek. Opened 2 years ago by decathorpe.
Unknown source main  into  main

file modified
+1 -2
@@ -137,7 +137,7 @@

          req.raise_for_status()

          total = int(req.headers["Content-Length"])

          with util.remove_on_error(cratef), open(cratef, "wb") as f:

-             for chunk in tqdm.tqdm(req.iter_content(), f"Downloading {cratef_base}".format(cratef_base),

+             for chunk in tqdm.tqdm(req.iter_content(), f"Downloading {cratef_base}",

                                     total=total, unit="B", unit_scale=True):

                  f.write(chunk)

      return cratef, crate, version
@@ -231,7 +231,6 @@

  

  

  def make_diff(path, lines1, mtime1, lines2, mtime2):

-     relpath = "/".join(path.split("/")[-2:])

      return list(difflib.unified_diff(lines1, lines2,

                                       fromfile=path, tofile=path,

                                       fromfiledate=mtime1, tofiledate=mtime2))

file modified
+1 -1
@@ -85,7 +85,7 @@

              return sys.byteorder

  

          case 'target_pointer_width':

-             return str(ctypes.sizeof(ctypes.c_voidp) * 8)

+             return str(ctypes.sizeof(ctypes.c_void_p) * 8)

  

          case 'target_vendor':

              return 'unknown'

file modified
+1 -1
@@ -129,7 +129,7 @@

              # remove all the duplicates we should first normalize it

              metadata_lines = []

              for some in process_metadata(md):

-                 if isinstance(some, metadata.Dependency):

+                 if isinstance(some, Dependency):

                      metadata_lines.extend(some.normalize())

                  else:

                      metadata_lines.append(some)

file modified
+8 -4
@@ -327,6 +327,10 @@

                  continue

              deps_by_name[dep["rename"] or dep["name"]].append(Dependency.from_json(dep))

  

+         # FIXME: handle "foo?/bar" style feature dependencies

+         # FIXME: handle "dep:foo/bar" style feature dependencies

+         # c.f. https://pagure.io/fedora-rust/rust2rpm/issue/186

+ 

          deps_by_feature = {}

          local_features = set(md["features"]) | set(

              d["rename"] for d in md["dependencies"] if d["rename"] is not None
@@ -334,11 +338,11 @@

          for feature, f_deps in md["features"].items():

              features = {None}

              deps = set()

-             for dep in f_deps:

-                 if dep in local_features:

-                     features.add(dep)

+             for f_dep in f_deps:

+                 if f_dep in local_features:

+                     features.add(f_dep)

                  else:

-                     pkg, _, f = dep.partition("/")

+                     pkg, _, f = f_dep.partition("/")

                      for dep in deps_by_name[pkg]:

                          dep = copy.deepcopy(dep)

                          if f:

file modified
+1 -1
@@ -8,4 +8,4 @@

      -rrequirements.txt

  whitelist_externals =

      cargo

- commands = py.test -v test.py

+ commands = pytest

__main__.py:

  • drop redundant format call on f-string
  • drop unused relpath variable in make_diff

cfg.py:

  • fix typo: ctypes.c_voidpctypes.c_void_p

inspector.py:

  • drop qualified use of metadata.Dependency: Dependency class is in scope, metadata module is not

metadata.py:

  • add FIXME items for supporting new feature dependency formats added with Rust 1.60+ (will require rework of the from_json method)
  • rename a loop variable (depf_dep) so it does not get shadowed by an inner dep loop variable

tox.ini:

  • drop references to test.py, it was removed when proper tests were added

Note that I was not able to figure out how to actually correctly launch the new tests.
I tried installing requirements.txt + tox + pytest into a virtualenv, but running both tox or pytest failed to correctly load the tests.

@zbyszek Could you document how to run the tests, please?

Pull-Request has been merged by zbyszek

2 years ago

I just use PYTHONPATH=. pytest -v or python -m pytest -v. I don't know tox, but it shouldn't be hard to configure it to do the tests. Also, hook this up in pagure. No idea how to do that though.

PYTHONPATH=. pytest -v

That worked, thanks!