Visitar URL original
Become more PEP-257 compliant. by bowlofeggs · Pull Request #9 · pulp/pulp_python · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Become more PEP-257 compliant.
  • Loading branch information
Randy Barlow
Randy Barlow committed Nov 20, 2014
commit 7278ceb56d45bb1e62df9103bacbacb06a0cac2c
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ install:
- "sudo mkdir -p /etc/pulp"
- "sudo touch /etc/pulp/server.conf"
script:
- "flake8 --config=flake8.cfg ."
- "nosetests --with-coverage --cover-package pulp_python --cover-package $(pwd) --cover-min-percentage 100 common/test/unit/ extensions_admin/test/unit/ plugins/test/unit/"
- "./run-tests.py --enable-coverage --cover-min-percentage 100"
after_success: coveralls
50 changes: 42 additions & 8 deletions extensions_admin/pulp_python/extensions/admin/cudl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@


class CreatePythonRepositoryCommand(CreateAndConfigureRepositoryCommand, ImporterConfigMixin):
"""
Creates Python repositories on the Pulp server.
"""

default_notes = {REPO_NOTE_TYPE_KEY: constants.REPO_NOTE_PYTHON}
IMPORTER_TYPE_ID = constants.IMPORTER_TYPE_ID

def __init__(self, context):
"""
Initialize the command.

:param context: The CLI context
:type context: pulp.client.extensions.core.ClientContext
"""
CreateAndConfigureRepositoryCommand.__init__(self, context)
ImporterConfigMixin.__init__(self, **IMPORTER_CONFIGURATION_FLAGS)
self.add_option(OPT_AUTO_PUBLISH)
Expand All @@ -44,7 +54,7 @@ def _describe_distributors(self, user_input):
is needed to create distributor configs.

:param user_input: dictionary of data passed in by okaara
:type user_inpus: dict
:type user_input: dict
:return: list of dict containing distributor_type_id,
repo_plugin_config, auto_publish, and distributor_id (the same
that would be passed to the RepoDistributorAPI.create call).
Expand All @@ -67,7 +77,7 @@ def _parse_importer_config(self, user_input):
is needed to create an importer config.

:param user_input: dictionary of data passed in by okaara
:type user_inpus: dict
:type user_input: dict
:return: importer config
:rtype: dict
"""
Expand All @@ -76,14 +86,29 @@ def _parse_importer_config(self, user_input):


class UpdatePythonRepositoryCommand(UpdateRepositoryCommand, ImporterConfigMixin):
"""
Updates existing Python repositories on the Pulp server.
"""

def __init__(self, context):
"""
Initialize the command.

:param context: The CLI context
:type context: pulp.client.extensions.core.ClientContext
"""
UpdateRepositoryCommand.__init__(self, context)
ImporterConfigMixin.__init__(self, **IMPORTER_CONFIGURATION_FLAGS)
self.add_option(OPT_AUTO_PUBLISH)
self.options_bundle.opt_feed.description = DESC_FEED

def run(self, **kwargs):
"""
Update the repository.

:param kwargs: The user input
:type kwargs: dict
"""
arg_utils.convert_removed_options(kwargs)

importer_config = self.parse_user_input(kwargs)
Expand All @@ -110,8 +135,17 @@ def run(self, **kwargs):


class ListPythonRepositoriesCommand(ListRepositoriesCommand):
"""
List the Python repostories on the Pulp server.
"""

def __init__(self, context):
"""
Initialize the command.

:param context: The CLI context
:type context: pulp.client.extensions.core.ClientContext
"""
repos_title = _('Python Repositories')
super(ListPythonRepositoriesCommand, self).__init__(context, repos_title=repos_title)

Expand All @@ -125,9 +159,9 @@ def get_repositories(self, query_params, **kwargs):
Get a list of all the python repositories that match the specified query params

:param query_params: query parameters for refining the list of repositories
:type query_params: dict
:type query_params: dict
:param kwargs: Any additional parameters passed into the repo list command
:type kwargs: dict
:type kwargs: dict
:return: List of python repositories
:rtype: list of dict
"""
Expand All @@ -147,9 +181,9 @@ def get_other_repositories(self, query_params, **kwargs):
Get a list of all the non python repositories that match the specified query params

:param query_params: query parameters for refining the list of repositories
:type query_params: dict
:type query_params: dict
:param kwargs: Any additional parameters passed into the repo list command
:type kwargs: dict
:type kwargs: dict
:return: List of non repositories
:rtype: list of dict
"""
Expand All @@ -168,9 +202,9 @@ def _all_repos(self, query_params, **kwargs):
get all the repositories associated with a repo that match a set of query parameters

:param query_params: query parameters for refining the list of repositories
:type query_params: dict
:type query_params: dict
:param kwargs: Any additional parameters passed into the repo list command
:type kwargs: dict
:type kwargs: dict
:return: list of repositories
:rtype: list of dict
"""
Expand Down
2 changes: 1 addition & 1 deletion extensions_admin/pulp_python/extensions/admin/pulp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(context):
Create the python CLI section and add it to the root

:param context: the CLI context.
:type context: pulp.client.extensions.core.ClientContext
:type context: pulp.client.extensions.core.ClientContext
"""
root_section = context.cli.create_section(SECTION_ROOT, DESC_ROOT)
_add_repo_section(context, root_section)
Expand Down
5 changes: 3 additions & 2 deletions extensions_admin/pulp_python/extensions/admin/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class UploadPackageCommand(upload.UploadCommand):
"""
The command used to upload Python packages.
"""

def determine_type_id(self, filename, **kwargs):
"""
Return pulp_python.common.constants.PACKAGE_TYPE_ID.
Expand All @@ -15,7 +16,7 @@ def determine_type_id(self, filename, **kwargs):
:type filename: basestring
:param kwargs: Unused
:type kwargs: dict
:returns: pulp_python.common.constants.PACKAGE_TYPE_ID
:return: pulp_python.common.constants.PACKAGE_TYPE_ID
:rtype: basestring
"""
return constants.PACKAGE_TYPE_ID
Expand All @@ -29,7 +30,7 @@ def generate_unit_key(self, *args, **kwargs):
:type args: list
:param kwargs: Unused
:type kwargs: dict
:returns: An empty dictionary
:return: An empty dictionary
:rtype: dict
"""
return {}
6 changes: 2 additions & 4 deletions plugins/pulp_python/plugins/distributors/configuration.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import logging
import os

from pulp_python.common import constants


logger = logging.getLogger(__name__)


def validate_config(config):
"""
Validate a configuration.

:param config: Pulp configuration for the distributor
:type config: pulp.plugins.config.PluginCallConfiguration
:return: This always returns (True, None)
:rtype: tuple
:raises: PulpCodedValidationException if any validations failed
"""
return True, None
Expand Down
3 changes: 3 additions & 0 deletions plugins/pulp_python/plugins/distributors/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class PublishContentStep(PluginStep):
"""
Publish Content
"""

def __init__(self):
"""
Initialize the PublishContentStep.
Expand All @@ -42,6 +43,7 @@ class PublishMetadataStep(PluginStep):
"""
Publish Metadata (refs, branch heads, etc)
"""

def __init__(self):
"""
Initialize the PublishMetadataStep.
Expand Down Expand Up @@ -122,6 +124,7 @@ class PythonPublisher(PluginStep):
Publisher class that is responsible for the actual publishing
of a repository via a web server.
"""

def __init__(self, repo, publish_conduit, config):
"""
:param repo: Pulp managed Python repository
Expand Down
1 change: 1 addition & 0 deletions plugins/pulp_python/plugins/distributors/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PythonDistributor(Distributor):
"""
This distributor is for use with the pip client.
"""

@classmethod
def metadata(cls):
"""
Expand Down
8 changes: 8 additions & 0 deletions plugins/pulp_python/plugins/importers/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class PythonImporter(Importer):
"""
This class is used to import Python modules into Pulp.
"""

@classmethod
def metadata(cls):
"""
Expand Down Expand Up @@ -105,5 +106,12 @@ def upload_unit(self, repo, type_id, unit_key, metadata, file_path, conduit, con
def validate_config(self, repo, config):
"""
We don't have a config yet, so it's always valid

:param repo: metadata describing the repository
:type repo: pulp.plugins.model.Repository
:param config: plugin configuration for the repository
:type config: pulp.plugins.config.PluginCallConfiguration
:return: This always returns (True, '')
:rtype: tuple
"""
return True, ''
1 change: 1 addition & 0 deletions plugins/pulp_python/plugins/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Package(object):
"""
This class represents a Python package.
"""

TYPE = constants.PACKAGE_TYPE_ID
# The full list of supported attributes. Attributes beginning with underscore are specific to
# this module and are not found in PKG-INFO.
Expand Down
3 changes: 3 additions & 0 deletions pulp-dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
def parse_cmdline():
"""
Parse and validate the command line options.

:return: A 2-tuple of the options and arguments that the user provided.
:rtype: tuple
"""
parser = optparse.OptionParser()

Expand Down
25 changes: 23 additions & 2 deletions run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,36 @@

import os
import subprocess
import sys

from pulp.devel import doc_check
from pulp.devel.test_runner import run_tests


# Find and eradicate any existing .pyc files, so they do not eradicate us!
PROJECT_DIR = os.path.dirname(__file__)
subprocess.call(['find', PROJECT_DIR, '-name', '*.pyc', '-delete'])

# Check the code for PEP-8 compliance
config_file = os.path.join(PROJECT_DIR, 'flake8.cfg')
subprocess.call(['flake8', '--config', config_file, PROJECT_DIR])
exit_code = subprocess.call(['flake8', '--config', config_file, PROJECT_DIR])

if exit_code != 0:
sys.exit(exit_code)

# Check the code for PEP-257 compliance
# We should remove some of these over time
pep257_fail_ignore_codes = 'D100,D103,D200,D202,D203,D205,D400,D401,D402'

print "checking pep257 for failures, ignoring %s" % pep257_fail_ignore_codes
exit_code = subprocess.call(['pep257', '--ignore=' + pep257_fail_ignore_codes])

if exit_code != 0:
sys.exit(exit_code)

# Ensure that all doc strings are present
doc_check.recursive_check(PROJECT_DIR)


PACKAGES = [PROJECT_DIR, 'pulp_python', ]

Expand All @@ -25,4 +46,4 @@
dir_safe_all_platforms = [os.path.join(os.path.dirname(__file__), x) for x in TESTS]
dir_safe_non_rhel5 = [os.path.join(os.path.dirname(__file__), x) for x in PLUGIN_TESTS]

run_tests(PACKAGES, dir_safe_all_platforms, dir_safe_non_rhel5)
sys.exit(run_tests(PACKAGES, dir_safe_all_platforms, dir_safe_non_rhel5))
1 change: 1 addition & 0 deletions test_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ flake8
coveralls
coverage
nose
pep257