customized output dir of pcreate scaffolding. #892

wants to merge 9 commits into


None yet
3 participants

scaffolding in pcreate is a very powerful feature in setting up dev structure very efficiently.
Currently the output dir is based on the module name because of the nature of python programming. However, when developing module A, sometimes we may want to have some simple files within module A, but still with some basic scaffolding template. This patch intends to provide customized output dir of pcreate.


mmerickel commented Mar 13, 2013

This idea is fine, but the options.output_dir needs to be sanitized properly (what if it's an absolute path or contains a ~). Also os.path.join should be used for cross-platform purposes.


tseaver commented Mar 21, 2013

Thanks for the follow-up: the tests look good. Can I ask one more thing? Please add your name to CONTRIBUTORS.txt and re-push.


tseaver commented Apr 3, 2013

Still need's CONTRIBUTORS.txt.

+ if dir_path[0] == '~':
+ raise Exception('invalid user dir')
+ if dir_path[0] == '/':

mmerickel Jan 23, 2014


os.path.abspath will automatically norm the path and make it absolute via the CWD if it is not already, so the else here should be unnecessary.

+ parser.add_option('-d', '--dir',
+ dest='output_dir',
+ action='store',
+ help='customized output dir. If the dir starting with "~", then the corresponding home dir will be provided. If the leading character of dir is "/", the dir will be treated as absolute path. Otherwise, the dir will be the relative path from current dir (os.getcwd())')

mmerickel Jan 23, 2014


79-character line width

    'customized output dir. '
    'If the dir starting..'
+ return pkg_full_name
+ def _set_output_dir(self, dir_path):
+ if dir_path[0] == '~':

mmerickel Jan 23, 2014


I would call os.path.expanduser regardless of the presence of the ~ because it will not affect the path if the ~ is not there. The Exception also seems unnecessary to me because we should not be creating parent directories for the output_dir, so somewhere else there will be a failure when it fails to create the ~baduser/project folder.

@@ -123,4 +131,25 @@ def out(self, msg): # pragma: no cover
if not self.quiet:
+ def _set_pkg_full_name(self, pkg_path):

mmerickel Jan 23, 2014


my feeble brain is having trouble with all of this path munging, can we get a comment here about what all this is for? I'm not clear what pkg_full_name is versus pkg_name.


chhsiao1981 Feb 28, 2014

Hi mmerickel,

Thank you very much for the comments.
I will make the path-related code cleaner/clearer.

The original goal of this patch is to be able to have pcreate -s dummy -d a/b/c/ Distro
and generate Distro as a.b.c.Distro.

pkg_name was used as Distro. So I added pkg_full_name to indicate a.b.c.Distro
I'll add comments and maybe change the name to make it clearer.
(This code needs revise too.)


chhsiao1981 Mar 8, 2014

(Revised comments)
Currently when doing

pcreate -s starter p/q/r/s/t

pcreate would create p/q/r/s/t as dir, and name t as pkg name, and put content of starter inside t.

What I intend to do is to have module (or package) t inside package r.s, where r is inside directory p/q, when initializing p/q/r/s/
and I also would like to have p/q/test_r/test_s/ as corresponding test file (or other corresponding files).

To achieve this, we need the following information for templates:

  1. output_dir (p/q/r/s)
  2. module/base pkg name (s).
  3. full module/pkg name (r.s.t).
  4. root pkg name (r)
  5. parent pkg name (r.s)

3 and 4 can be derived from 2 within re, and they are not clear if full name is 't'.

I want to have the following command:
pcreate -s simple_module -d p/q r/s/t (or pcreate -s simple_module -d p/q r.s.t)
(I would prefer the first one to be compatible with current usage)

because basename(args[0]) can be treated as module or as pkg,
I would like to have the following variables (pcreate -s simple_module -d p/q r/s/t as example):
pkg_name as basename(args[0]) (t) (as before)
pkg_full_name as full pkg name (r.s.t)

I'll leave root pkg name and parent pkg name to be derived within customized templates.

Suggestions are welcome.

chhsiao1981 added some commits Mar 9, 2014

1. Merge branch 'master' of
2. makes output_dir and pkg_full_name more clear with -d.

3. provide simple_module and simple_pkg template

This pull-request may be off the original purpose of pcreate too much.
I'll retract this pull-request and restart another one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment