Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement pep440 blacklisting #16

Merged
merged 13 commits into from
May 18, 2018
Merged

Conversation

dwighthubbard
Copy link
Contributor

This pull request has several related changes:

  • Implements a configuration class singleton to allow the configuration settings to be accessed where needed in code instead of passing the values as function/method arguments.
  • Adds Filter plugin classes for packages and releases.
  • Adds functions to query package_resources for the filtering plugin classes.
  • Moves the blacklist functionality to the BlacklistProject() plugin.
  • Updates the mirror object blacklist functionality to use the BlacklistProject() plugin.
  • Adds the new plugin entrypoints to the setup.py.
  • Adds tests for the plugin functionality.
  • Updated documentation for the new functionality.

dhubbard added 7 commits May 15, 2018 14:32
- Add more documentation on filtering
- Add stubs for the 2 types of filters to be implemented
…ep440_blacklisting

# Manually fixed Conflicts:
#	src/bandersnatch/mirror.py
#	src/bandersnatch/package.py

Fixed tests that broke due to update changes.
Copy link
Contributor

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

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

Long diff ! No wonder it took you all day.

  • Nice tests
    Just some questions about introducing such a different style

Also, how do you feel about using the backport of importlib_resources for easy move in 3.7?

if self.config_file:
config_files.append(self.config_file)
self.config = ConfigParser()
self.config.read(config_files)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a separate module, this already is a singleton ... So what does this "singleton" achieve that I am missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using a singleton makes it easier to test since the module can be reinitialized with a different configuration during the tests.

"""
Blacklist management
"""
import pkg_resources
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we look at using pip install importlib_resources with a easier move forward to the stdlib version in 3.7 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would certainly be a good idea, but looking at the documentation for importlib_resources at https://docs.python.org/3.7/library/importlib.html#module-importlib.resources it looks like it implements only a subset of the functionality in pkg_resources and doesn't implement the functionality to iterate registered package entrypoints.

from .configuration import BandersnatchConfig


loaded_filter_plugins = defaultdict(lambda: [])
Copy link
Contributor

Choose a reason for hiding this comment

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

Just use defaultdict(list)

loaded_filter_plugins = defaultdict(lambda: [])


class Filter(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

This is Python 3 - object is defaults

''' Take the JSON metadata we just fetched and save to disk '''
"""
Take the JSON metadata we just fetched and save to disk
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

If these fit on 1 line < 80 chars what does this format achieve?

def setUp(self):
self.cwd = os.getcwd()
self.tempdir = TemporaryDirectory()
bandersnatch.filter.loaded_filter_plugins = defaultdict(lambda: [])
Copy link
Contributor

Choose a reason for hiding this comment

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

defaultdict(list)

if self.tempdir:
os.chdir(self.cwd)
self.tempdir.cleanup()
self.tempdir = None
Copy link
Contributor

Choose a reason for hiding this comment

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

What does setting tmpdir to None do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's defensive coding since the teardown only removes the tempdir if one was created and stored to the self.tempdir attribute.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think cleanup() does that.

def setUp(self):
self.cwd = os.getcwd()
self.tempdir = TemporaryDirectory()
bandersnatch.filter.loaded_filter_plugins = defaultdict(lambda: [])
Copy link
Contributor

Choose a reason for hiding this comment

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

What does lambda achieve?

m.packages_to_sync = {'example1': None, 'example2': None}
m._remove_blacklisted_packages()
assert blacklisted_package not in m.packages_to_sync
def test_mirror__filter_packages__match(tmpdir):
Copy link
Contributor

Choose a reason for hiding this comment

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

Why double __ ? What does it mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is to differentiate between spaces and underscores since the function names being tested have underscores in their name and I like the test to include the name of the function being tested.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a standard or something? Never heard of it.

tox.ini Outdated
@@ -3,7 +3,7 @@ envlist = py36

[testenv]
deps = -rtest-requirements.txt
commands = pytest
commands = pytest -vv
Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes I find this to much output ... But I guess it does not hurt

@cooperlees cooperlees added the enhancement New feature or request label May 17, 2018
Copy link
Contributor

@cooperlees cooperlees left a comment

Choose a reason for hiding this comment

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

Thanks for the feature.

In parts it seems a little complicated and I'm not sold on the entry points but we can always fix it if it becomes a problems.

from configparser import ConfigParser


class Singleton(type): # pragma: no cover
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll look it up, but no idea why we need type here.

if self.tempdir:
os.chdir(self.cwd)
self.tempdir.cleanup()
self.tempdir = None
Copy link
Contributor

Choose a reason for hiding this comment

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

I think cleanup() does that.

m.packages_to_sync = {'example1': None, 'example2': None}
m._remove_blacklisted_packages()
assert blacklisted_package not in m.packages_to_sync
def test_mirror__filter_packages__match(tmpdir):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a standard or something? Never heard of it.

@cooperlees cooperlees merged commit 945dece into master May 18, 2018
@cooperlees cooperlees deleted the implement_pep440_blacklisting branch May 18, 2018 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants