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

Add blacklist, here exclude list, of packages not to install #186

Closed
wants to merge 2 commits into from

Conversation

CodeHeeler
Copy link
Contributor

No description provided.

@pep8speaks
Copy link

Hello @CodeHeeler! Thanks for submitting the PR.

Line 85:32: E128 continuation line under-indented for visual indent
Line 86:32: E128 continuation line under-indented for visual indent
Line 87:32: E128 continuation line under-indented for visual indent

Line 144:1: W293 blank line contains whitespace

@pulpbot
Copy link
Member

pulpbot commented Jun 19, 2018

Can one of the admins verify this patch?

1 similar comment
@pulpbot
Copy link
Member

pulpbot commented Jun 19, 2018

Can one of the admins verify this patch?

@werwty werwty added the 3.0 label Jun 19, 2018
@werwty
Copy link
Contributor

werwty commented Jun 19, 2018

@CodeHeeler please rebase to latest 3.0-dev

Currently if includes isn't set, it defaults to excludes, so the following would actually not sync anything.

http POST $BASE_ADDR/pulp/api/v3/remotes/python/ \
    name='bar' \
    url='https://pypi.org/' \
    projects:='[{"name": "django", "version_specifier":"~=2.0"}]'

I was hoping for something more like:

http POST $BASE_ADDR/pulp/api/v3/remotes/python/ \
    name='bar' \
    url='https://pypi.org/' \
    includes:='[{"name": "django", "version_specifier":"~=2.0"}]' \
    excludes:='[{"name": "django", "version_specifier":"=2.0.1"}]'

Which can be done by

1.) creating two separate models, each subclassing ProjectSpecifier: class IncludeSpecifiers(ProjectSpecifier): class ExcludeSpecifiers(ProjectSpecifier):

or
2.) keeping a boolean on the ProjectSpecifier model and having the Remote serializer filter the boolean for two different fields. So an additional boolean to models.py:

class ProjectSpecifier(Model):
    name = models.TextField()
    version_specifier = models.TextField(blank=True, default="")
    remote = models.ForeignKey("PythonRemote",
                               related_name="projects",
                               related_query_name="projectspecifier",
                               on_delete=models.CASCADE)
    include = models.BooleanField()

and in serializers.py (just pseudocode, might not actually work this way):

class PythonRemoteSerializer(core_serializers.RemoteSerializer):
    include = ProjectSpecifierSerializer(
        required=False,
        many=True,
        instance=ProjectSpecifier.objects.filter(include=True, remote=)
    )
    exclude = ProjectSpecifierSerializer(
        required=False,
        many=True,
        instance=ProjectSpecifier.objects.filter(include=False, remote=)
    )

Here's an example on how serializer filtering can be done: https://stackoverflow.com/questions/28309507/django-rest-framework-filtering-for-serializer-field

This would also necessitate amending the RemoteSerializer create() and update() functions. This is more complex, but cleaner overall.

@CodeHeeler CodeHeeler changed the title Issue 3672 Add blacklist, here exclude list, of packages not to install Jun 19, 2018
@CodeHeeler CodeHeeler force-pushed the issue-3672 branch 2 times, most recently from 9a3b4f9 to d4dbe34 Compare June 26, 2018 18:16
@werwty werwty changed the base branch from 3.0-dev to master July 2, 2018 18:12
else:
for type, digest in package['digests'].items():
if digests.filter(type=type, digest=digest).exists():
remote_units.append(parse_metadata(metadata['info'],
Copy link
Contributor

Choose a reason for hiding this comment

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

re-indent this across multiple lines as seen elsewhere in the codebase

related_query_name="projectspecifier",
on_delete=models.CASCADE
)
remote = models.ForeignKey("PythonRemote",
Copy link
Contributor

Choose a reason for hiding this comment

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

Reindent this to be as it was previously

@@ -167,3 +167,9 @@ class PythonRemote(Remote):
"""

TYPE = 'python'

def includes_specifiers(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Should these be decorated with @property?

Also please add docstrings

@@ -56,10 +56,11 @@ def sync(remote_pk, repository_pk):
.format(repository=repository.name, remote=remote.name)
)

project_specifiers = python_models.ProjectSpecifier.objects.filter(remote=remote).all()
includes = python_models.ProjectSpecifier.objects.filter(remote=remote, include=True).all()
excludes = python_models.ProjectSpecifier.objects.filter(remote=remote, include=False).all()
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the .all() is necessary here.

# If neither specifiers nor digests have been set, then we should add the unit
if not project.version_specifier and not digests.exists():
if project.name in excludes:
whatnottosync=excludes[project.name]
Copy link
Contributor

@dralley dralley Jul 16, 2018

Choose a reason for hiding this comment

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

whatnottosync is a little unweildy, maybe call it excluded_pkg?

Equals sign should have spaces on either side (PEP8).

"""
Fetch metadata for content units matching project specifiers from the remote.

Args:
project_specifiers (dict): Information about a project and which versions of a project
to filter

These units are the difference between the include list and the exclude list.

Copy link
Contributor

Choose a reason for hiding this comment

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

Docstring needs to be fixed with the new arguments, still lists project_specifiers.

This one sentence belongs underneath the first one.

@dralley
Copy link
Contributor

dralley commented Jul 16, 2018

See Travis logs for failing PEP8 checks

@CodeHeeler CodeHeeler force-pushed the issue-3672 branch 4 times, most recently from fbb5011 to 81c643f Compare August 3, 2018 16:57
@dralley
Copy link
Contributor

dralley commented Aug 6, 2018

@CodeHeeler could you rebase on current master?

@CodeHeeler CodeHeeler force-pushed the issue-3672 branch 6 times, most recently from dd89b85 to 8441126 Compare August 6, 2018 19:56
Now packages are not only checked against a whitelist/include list
but also against an exclude list when syncing.

fixes #3672
https://pulp.plan.io/issues/3672
@CodeHeeler CodeHeeler force-pushed the issue-3672 branch 5 times, most recently from 365624a to 5845656 Compare August 7, 2018 15:37
def gen_remote(url=PYTHON_FIXTURES_URL, projects=PYTHON_XS_PROJECT_SPECIFIER, **kwargs):
def gen_remote(
url=PYTHON_FIXTURES_URL,
projects=PYTHON_XS_PROJECT_SPECIFIER,
Copy link
Contributor

Choose a reason for hiding this comment

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

remove projects here and below

Copy link
Contributor

Choose a reason for hiding this comment

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

and do a search to replace gen_remote(.., projects=..) with gen_remote(.., includes=..)

@dralley
Copy link
Contributor

dralley commented Aug 7, 2018

There will also need to be some documentation updates to cover the new names. Preferably an example of using Excludes in practice, but at minimum changing e.g. "projects" to "includes" so that the existing examples will still work.

If during the process of testing this you also feel like changing the example urls from the old UUID form to the new integer ID form, that would also be appreciated :) but you don't have to.

@CodeHeeler
Copy link
Contributor Author

Cool, thanks for pointing that out!

@dralley dralley closed this Aug 8, 2018
@dralley
Copy link
Contributor

dralley commented Aug 8, 2018

Going to remake this PR on top of the Declarative Version changes, once those are merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants