Commit b4a9b48f authored by Denis Laxalde's avatar Denis Laxalde
Browse files

[devtools] Update skeleton and newcube command to cube as package layout

Related to #13001466.
parent 3522d2a3389e
......@@ -619,29 +619,25 @@ layout, and a full featured cube with "full" layout.',
raise BadCommandUsage(
'cube name must be a valid python module name')
verbose = self.get('verbose')
cubesdir = self.get('directory')
if not cubesdir:
destdir = self.get('directory')
if not destdir:
cubespath = ServerConfiguration.cubes_search_path()
if len(cubespath) > 1:
raise BadCommandUsage(
"can't guess directory where to put the new cube."
" Please specify it using the --directory option")
cubesdir = cubespath[0]
if not osp.isdir(cubesdir):
print("-> creating cubes directory", cubesdir)
destdir = cubespath[0]
if not osp.isdir(destdir):
print("-> creating cubes directory", destdir)
try:
mkdir(cubesdir)
mkdir(destdir)
except OSError as err:
self.fail("failed to create directory %r\n(%s)"
% (cubesdir, err))
cubedir = osp.join(cubesdir, cubename)
if osp.exists(cubedir):
self.fail("%s already exists!" % cubedir)
skeldir = osp.join(BASEDIR, 'skeleton')
% (destdir, err))
default_name = 'cubicweb-%s' % cubename.lower().replace('_', '-')
if verbose:
distname = input('Debian name for your cube ? [%s]): '
% default_name).strip()
% default_name).strip()
if not distname:
distname = default_name
elif not distname.startswith('cubicweb-'):
......@@ -652,13 +648,19 @@ layout, and a full featured cube with "full" layout.',
if not re.match('[a-z][-a-z0-9]*$', distname):
raise BadCommandUsage(
'cube distname should be a valid debian package name')
cubedir = osp.join(destdir, distname)
if osp.exists(cubedir):
self.fail("%s already exists!" % cubedir)
skeldir = osp.join(BASEDIR, 'skeleton')
longdesc = shortdesc = input(
'Enter a short description for your cube: ')
if verbose:
longdesc = input(
'Enter a long description (leave empty to reuse the short one): ')
dependencies = {'cubicweb': '>= %s' % cubicwebversion,
'six': '>= 1.4.0',}
dependencies = {
'six': '>= 1.4.0',
'cubicweb': '>= %s' % cubicwebversion,
}
if verbose:
dependencies.update(self._ask_for_dependencies())
context = {'cubename' : cubename,
......
......@@ -44,25 +44,33 @@ class DevCtlTC(TestCase):
assertItemsEqual = TestCase.assertCountEqual
def test_newcube(self):
expected = ['i18n', 'hooks.py', 'setup.py', 'views.py', 'test',
'migration', 'entities.py', 'MANIFEST.in', 'schema.py',
'cubicweb-foo.spec', '__init__.py', 'debian', 'data',
'__pkginfo__.py', 'README', 'tox.ini']
expected_project_content = ['setup.py', 'test', 'MANIFEST.in',
'cubicweb_foo',
'cubicweb-foo.spec', 'debian', 'README',
'tox.ini']
expected_package_content = ['i18n', 'hooks.py', 'views.py',
'migration', 'entities.py', 'schema.py',
'__init__.py', 'data', '__pkginfo__.py']
tmpdir = tempfile.mkdtemp(prefix="temp-cwctl-newcube")
try:
retcode, stdout = newcube(tmpdir, 'foo')
self.assertEqual(retcode, 0, msg=to_unicode(stdout))
self.assertItemsEqual(os.listdir(osp.join(tmpdir, 'foo')), expected)
project_dir = osp.join(tmpdir, 'cubicweb-foo')
project_content = os.listdir(project_dir)
package_dir = osp.join(project_dir, 'cubicweb_foo')
package_content = os.listdir(package_dir)
self.assertItemsEqual(project_content, expected_project_content)
self.assertItemsEqual(package_content, expected_package_content)
finally:
shutil.rmtree(tmpdir, ignore_errors=True)
self.assertEqual(retcode, 0, msg=stdout)
def test_flake8(self):
"""Ensure newcube built from skeleton is flake8-compliant"""
tmpdir = tempfile.mkdtemp(prefix="temp-cwctl-newcube-flake8")
try:
newcube(tmpdir, 'foo')
cmd = [sys.executable, '-m', 'flake8', osp.join(tmpdir, 'foo')]
cmd = [sys.executable, '-m', 'flake8',
osp.join(tmpdir, 'cubicweb-foo', 'cubicweb_foo')]
proc = Popen(cmd, stdout=PIPE, stderr=STDOUT)
retcode = proc.wait()
finally:
......
......@@ -17,4 +17,4 @@ deps =
commands = flake8
[flake8]
exclude = migration/*,test/data/*,setup.py,.tox/*
exclude = cubicweb_%(cubename)s/migration/*,test/data/*,setup.py,.tox/*
......@@ -131,6 +131,9 @@ def copy_skeleton(skeldir, targetdir, context,
targetdir = normpath(targetdir)
for dirpath, dirnames, filenames in walk(skeldir):
tdirpath = dirpath.replace(skeldir, targetdir)
if 'cubicweb_CUBENAME' in tdirpath:
tdirpath = tdirpath.replace('cubicweb_CUBENAME',
'cubicweb_' + context['cubename'])
create_dir(tdirpath)
for fname in filenames:
if any(fnmatch(fname, pat) for pat in exclude):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment