Skip to content

ENH: Remove dependency upon python-apt library#115

Merged
rbuccigrossi merged 25 commits intoReproNim:masterfrom
rbuccigrossi:enh-remove_python_apt
Oct 13, 2017
Merged

ENH: Remove dependency upon python-apt library#115
rbuccigrossi merged 25 commits intoReproNim:masterfrom
rbuccigrossi:enh-remove_python_apt

Conversation

@rbuccigrossi
Copy link
Contributor

@rbuccigrossi rbuccigrossi commented Sep 21, 2017

The goal is to remove our dependency upon the python-apt library by using apt-cache calls.

  • Split _create_package into reasonable methods
  • Parse source_name and source_version (from Source: line if different than package)
  • Get the install_date for a package (from /var/lib/dpkg/info/package.list
  • Get the APTSource date from /var/lib/apt/lists/*Release file ("Date:" tag)
  • More unit testing

@codecov-io
Copy link

codecov-io commented Sep 21, 2017

Codecov Report

Merging #115 into master will increase coverage by 0.19%.
The diff coverage is 91.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #115      +/-   ##
==========================================
+ Coverage    75.4%   75.59%   +0.19%     
==========================================
  Files         118      118              
  Lines        7915     8065     +150     
==========================================
+ Hits         5968     6097     +129     
- Misses       1947     1968      +21
Impacted Files Coverage Δ
niceman/interface/retrace.py 98.33% <100%> (+3.78%) ⬆️
niceman/distributions/tests/test_debian.py 95.74% <100%> (+2.52%) ⬆️
niceman/resource/tests/test_shell.py 100% <100%> (ø) ⬆️
niceman/distributions/base.py 87.8% <100%> (+0.15%) ⬆️
niceman/support/distributions/debian.py 94.89% <100%> (-5.11%) ⬇️
niceman/tests/test_tests_utils.py 97.46% <100%> (+0.07%) ⬆️
niceman/support/distributions/tests/test_debian.py 100% <100%> (+15.38%) ⬆️
niceman/resource/shell.py 74.07% <100%> (+0.99%) ⬆️
niceman/distributions/debian.py 89.91% <86.2%> (-1.22%) ⬇️
niceman/tests/utils.py 77.99% <87.5%> (+0.3%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e53e36...d725b9e. Read the comment docs.

Copy link
Member

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor quick comments

for entry in entries:
match = re_pkg.match(entry.strip())
if not match:
print("FAILED in ", entry)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgr.warning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


# Split before PGP signature if present
if "-----BEGIN PGP SIGNATURE-----" in content:
content = content.split("-----BEGIN PGP SIGNATURE-----")[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't it be without 'if' statement and just the content = content.split("-----BEGIN PGP SIGNATURE-----")[0]? ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at that! That's nice behavior for str.split()

@rbuccigrossi rbuccigrossi removed the WiP label Oct 12, 2017
@rbuccigrossi rbuccigrossi changed the title WIP ENH: Remove dependency upon python-apt library ENH: Remove dependency upon python-apt library Oct 12, 2017
@rbuccigrossi
Copy link
Contributor Author

Assigned to Yarik for review and next steps.

Copy link
Member

@yarikoptic yarikoptic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grr.. I was certain that I have submitted the review yesterday, but found today that comments weren't yet finalized! sorry!

What if we merge it in the current shape and you would address requested changes in a separate followup PR? This way we could resolve quickly conflicts with @chaselgrove changes in #121 before piling up more of them.
In other words , if approve, merge please ;)

from niceman.tests.utils import skip_if


@skip_if(not apt)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, we still will need to skip it on non-debian systems. probably entire module (unless it is some mocked up test).
May be, define in external_versions a new checker for cmd:apt-cache (see the one for git) and then skip here if version is "None" (not installed ie).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I added a skip_if_no_apt_cache decorator in 7a6337b.

datetime.utcfromtimestamp(
mktime_tz(parsedate_tz(spec.date)))))
except TypeError as _:
lgr.warning("Unexpected date format %s " % spec.date)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we may be just blow completely for now so we could detect those instead of missing all possible hundreds of warnings ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

except TypeError as _:
lgr.warning("Unexpected date format %s " % spec.date)
break
except CommandError as _:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't there at least be a warning or better even exception? otherwise it might be tricky later to find out why we are missing some information

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that we have two different potential file name endings ("Release" and "InRelease"), so we expect a bunch of failures in attempting to read the files. I'll put better documentation in a comment.


assert parse('diversion by dash from: /bin/sh') is None


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could there be a sledgehummer test which would (after we start throwing exceptions whenever things go not as planned, see above comments) test on some good number of packages (or even all packages) that it could trace it... how long will it take do you think e.g. on your ubuntu? you could probably try to trace /usr/bin/ and /usr/lib/* /usr/lib// for starters ;)
test itself could verify that all apt sources have some date, all packages have version and architecture, and some apt source assigned.

@with_tempfile(content="content")
def test_isdir(script=None):
ses = ShellSession()
assert not ses.isdir(script)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tempfile is a heavy artillery for this... why not just __FILE__? ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

raise AssertionError("Key %s is missing" % key)
assert_is_subset_dict_recur(a[key], b[key])
else:
if not a == b:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a note -- there is still != in Python ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. And, I love the fact that my assertion error used != while I used "not =="

@yarikoptic
Copy link
Member

Eh, merging Matt's PR introduced some minor conflicts... I will resolve them now

* origin/master: (39 commits)
  BF: changed travis python apt packages
  ENH: added exec interface
  ENH: Added mkdir, get and put interfaces
  BF: Added back in some commented out tests for SSH
  ENH: Made code changes recommended by comments. Fixed python 3 issues.
  DOC: restored nose install; using pytest directly for testing
  DOC: updated to reflect new testing (not nose)
  allow downgrades
  never give up!
  BF: adjust apt installation for trusty
  BF: Retry Travis internal fault.
  ENH: Changed AWS resource to use Ssh package to connect to remote EC2 servers.
  BF: Skipping SSH test if no network found. (try 2)
  BF: Skipping SSH test if no network found.
  BF: removal of Travis build_install_apt
  BF: reverting Travis distribution back to precise
  BF: seeing if Travis installs the docker service on Trusty
  BF: Restored retrace package test.
  RF: Used six package for NoSectionError exception.
  ENH: Moved SSH connection session out of execute command methods.
  ...
@rbuccigrossi
Copy link
Contributor Author

I'm merging to minimize future conflicts, but will resolve suggestions in a future pull request.

@rbuccigrossi rbuccigrossi merged commit 3fa69df into ReproNim:master Oct 13, 2017
yarikoptic added a commit that referenced this pull request Nov 8, 2017
Addressing code review comments for debian identification (#115)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants