-
Notifications
You must be signed in to change notification settings - Fork 140
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
Conversation
to access the configuration.
- 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.
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
src/bandersnatch/filter.py
Outdated
from .configuration import BandersnatchConfig | ||
|
||
|
||
loaded_filter_plugins = defaultdict(lambda: []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use defaultdict(list)
src/bandersnatch/filter.py
Outdated
loaded_filter_plugins = defaultdict(lambda: []) | ||
|
||
|
||
class Filter(object): |
There was a problem hiding this comment.
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 | ||
""" |
There was a problem hiding this comment.
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: []) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: []) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
…ep440_blacklisting
…nto implement_pep440_blacklisting
Remove -vv from pytest run.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
This pull request has several related changes: