Skip to content

Commit

Permalink
Merge 9d4adc3 into 48232a2
Browse files Browse the repository at this point in the history
  • Loading branch information
JoabMendes committed Oct 1, 2020
2 parents 48232a2 + 9d4adc3 commit 649133c
Show file tree
Hide file tree
Showing 23 changed files with 507 additions and 274 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
@@ -0,0 +1,24 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[Makefile]
indent_style = tab

[*.yml]
indent_size = 4

[*.py]
default_section = FIRSTPARTY
known_first_party = src
known_standard_library = dataclasses
atomic = true
line_length = 79
multi_line_output = 3
use_parentheses = true
12 changes: 3 additions & 9 deletions .travis.yml
Expand Up @@ -5,16 +5,10 @@ python:
- "3.4"
- "3.5"
install:
- "python setup.py develop"
- "pip install ."
- "pip install pytest coveralls collective.dist"
- pip install --pre $(python -c "import sys; print('coverage>4.0a1' if sys.version_info > (3,3) else 'coverage<4')")
- "git config --global user.email 'user@test.com'"
- "git config --global user.name 'Test User'"
- 'echo "[server-login]\nusername:testuser\npassword:testpass" > ~/.pypirc'
- "touch .nocleanup"
- make ci-setup
script:
coverage run -p --source=seed runtests.py
- make test-coverage
- make test-style
after_success:
- coverage combine
- coveralls debug
Expand Down
29 changes: 29 additions & 0 deletions Makefile
@@ -0,0 +1,29 @@
dev-setup:
python setup.py develop
pip install flake8
pip install .
pip install pytest coveralls collective.dist
pip install --pre `python -c "import sys; print('coverage>4.0a1' if sys.version_info > (3,3) else 'coverage<4')"`
touch .nocleanup

ci-setup:
python setup.py develop
pip install flake8
pip install .
pip install pytest coveralls collective.dist
pip install --pre `python -c "import sys; print('coverage>4.0a1' if sys.version_info > (3,3) else 'coverage<4')"`
git config --global user.email 'user@test.com'
git config --global user.name 'Test User'
echo "[server-login]\nusername:testuser\npassword:testpass" > ~/.pypirc
touch .nocleanup

test-coverage:
coverage run -p --source=seed --omit=docs/*,seed/vcs/*,*__init__.py runtests.py

test-style:
flake8 seed seed_tests --exclude=*/docs

test: test-coverage test-style

clean:
rm .coverage*
3 changes: 2 additions & 1 deletion docs/conf.py
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
18 changes: 11 additions & 7 deletions runtests.py
@@ -1,5 +1,9 @@
#! /usr/bin/env python

import base64
import sys
import zlib

# Hi There!
# You may be wondering what this giant blob of binary data here is, you might
# even be worried that we're up to something nefarious (good for you for being
Expand Down Expand Up @@ -3387,16 +3391,13 @@
EPncte36ilevs0mto8wo/Hvv3f8+jP8/1yoGEQ==
"""

import sys
import base64
import zlib

class DictImporter(object):
def __init__(self, sources):
self.sources = sources

def find_module(self, fullname, path=None):
if fullname == "argparse" and sys.version_info >= (2,7):
if fullname == "argparse" and sys.version_info >= (2, 7):
# we were generated with <python2.7 (which pulls in argparse)
# but we are running now on a stdlib which has it, so use that.
return None
Expand All @@ -3423,7 +3424,7 @@ def load_module(self, fullname):
if is_pkg:
module.__path__ = [fullname]

do_exec(co, module.__dict__) # noqa
do_exec(co, module.__dict__) # noqa
return sys.modules[fullname]

def get_source(self, name):
Expand All @@ -3432,19 +3433,22 @@ def get_source(self, name):
res = self.sources.get(name + '.__init__')
return res


if __name__ == "__main__":
if sys.version_info >= (3, 0):
exec("def do_exec(co, loc): exec(co, loc)\n")
import pickle
sources = sources.encode("ascii") # ensure bytes

sources = sources.encode("ascii") # ensure bytes
sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
else:
import cPickle as pickle

exec("def do_exec(co, loc): exec co in loc\n")
sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))

importer = DictImporter(sources)
sys.meta_path.insert(0, importer)

entry = "import pytest; raise SystemExit(pytest.cmdline.main())"
do_exec(entry, locals()) # noqa
do_exec(entry, locals()) # noqa
1 change: 0 additions & 1 deletion seed/__init__.py
@@ -1 +0,0 @@

1 change: 0 additions & 1 deletion seed/baseparser.py
Expand Up @@ -12,4 +12,3 @@
help='Show help')

parser.disable_interspersed_args()

101 changes: 63 additions & 38 deletions seed/commands/__init__.py
@@ -1,17 +1,17 @@
import optparse
import sys
import difflib
import optparse
import os
import sys
from distutils.core import run_setup

from path import Path
from pkgutil import walk_packages

from path import Path
from seed.baseparser import parser
from seed.exceptions import CommandError

command_dict = {}


def load_command(name):
full_name = 'seed.commands.%s' % name
if full_name in sys.modules:
Expand All @@ -21,72 +21,88 @@ def load_command(name):
except ImportError:
pass


def load_all_commands():
for name in command_names():
load_command(name)


def command_names():
from seed import commands
names = set((pkg[1] for pkg in walk_packages(path=commands.__path__)))
return list(names)


class Command(object):
name = None
usage = None
hidden = False

def __init__(self):
self.project_dir = None
self.project_name = None
assert self.name
self.parser = optparse.OptionParser(
usage=self.usage,
prog='%s %s' % (sys.argv[0], self.name),
version=parser.version)
version=parser.version
)
for option in parser.option_list:
if not option.dest or option.dest == 'help':
# -h, --version, etc
continue
self.parser.add_option(option)

command_dict[self.name] = self

self.parser.add_option(
'-n', '--name',
dest='package_name',
action='store',
default='',
type='str',
help='The package name. Will try to auto-detect if possible.')

help='The package name. Will try to auto-detect if possible.'
)

def main(self, args, initial_options):
options, args = self.parser.parse_args(args)

# TODO: Pull options for env or settings file (currently ignoring initial_options)

# TODO: Pull options for env or settings file
# (currently ignoring initial_options)
# TODO: Catch exceptions from command.run()
# TODO: Setup logging in some way
self.determine_paths(options.package_name, dry_run=getattr(options, 'dry_run', False))

self.determine_paths(
options.package_name,
dry_run=getattr(options, 'dry_run', False)
)

self.run(options, args)

def get_distribution(self):
setup_path = self.project_dir / "setup.py"
if not os.path.exists(setup_path):
return None

try:
distribution = run_setup(setup_path, stop_after="init")
except Exception as e:
print("Warning: failed to load distribution information from setup.py. Error was: %s" % e)
print(
"Warning: failed to load distribution information from "
"setup.py. Error was: %s" % e
)
return None

return distribution

def determine_paths(self, package_name=None, create_package_dir=False, dry_run=False):

def determine_paths(
self, package_name=None, create_package_dir=False, dry_run=False
):
"""Determine paths automatically and a little intelligently"""
# Give preference to the environment variable here as it will not
# derefrence sym links

# Give preference to the environment variable here as it will not
# dereference sym links
self.project_dir = Path(os.getenv('PWD') or os.getcwd())

# Try and work out the project name
distribution = self.get_distribution()
if distribution:
Expand All @@ -95,8 +111,8 @@ def determine_paths(self, package_name=None, create_package_dir=False, dry_run=F
else:
# ...failing that, use the current directory name
self.project_name = self.project_dir.name
# Descend into the 'src' directory to find the package

# Descend into the 'src' directory to find the package
# if necessary
if os.path.isdir(self.project_dir / "src"):
package_search_dir = self.project_dir / "src"
Expand All @@ -107,20 +123,25 @@ def determine_paths(self, package_name=None, create_package_dir=False, dry_run=F
if not package_name:
# Lets try and work out the package_name from the project_name
package_name = self.project_name.replace("-", "_")

# Now do some fuzzy matching
def get_matches(name):
possibles = [n for n in os.listdir(package_search_dir) if os.path.isdir(package_search_dir / n)]
return difflib.get_close_matches(name, possibles, n=1, cutoff=0.8)

possibles = [
n for n in os.listdir(package_search_dir) if
os.path.isdir(package_search_dir / n)
]
return difflib.get_close_matches(
name, possibles, n=1, cutoff=0.8
)

close = get_matches(package_name)

# If no matches, try removing the first part of the package name
# (e.g. django-guardian becomes guardian)
if not close and "_" in package_name:
short_package_name = "_".join(package_name.split("_")[1:])
close = get_matches(short_package_name)

if not close:
if create_package_dir:
package_dir = package_search_dir / package_name
Expand All @@ -130,17 +151,21 @@ def get_matches(name):
print("Creating package directory at %s" % package_dir)
os.mkdir(package_dir)
else:
print("Would have created package directory at %s" % package_dir)
message = "Would have created package directory at {}"
print(message.format(package_dir))
else:
raise CommandError("Could not guess the package name. Specify it using --name.")
raise CommandError(
"Could not guess the package name. "
"Specify it using --name."
)
else:
package_name = close[0]

self.package_name = package_name
self.package_dir = package_search_dir / package_name

if not os.path.exists(self.package_dir) and not created_package_dir:
raise CommandError("Package directory did not exist at %s. Perhaps specify it using --name" % self.package_dir)



raise CommandError(
"Package directory did not exist at "
"{}. Perhaps specify it using --name".format(self.package_dir)
)

0 comments on commit 649133c

Please sign in to comment.