Skip to content
This repository has been archived by the owner on Feb 4, 2019. It is now read-only.

Commit

Permalink
Minor Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wilfredinni committed Mar 5, 2018
1 parent 1c38927 commit 0ede33b
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 98 deletions.
25 changes: 12 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ A simple and quick command line tool to create python packages.
Install
-------

``$ pip install do``
``$ pip install do-pack``

Usage
-----
Expand All @@ -34,7 +34,7 @@ The config command

``$ do config``

Use the config command to fill common fields once (if executed twice it
Use it to fill common fields once (if executed twice it
will overwrite the previous configuration).

Create a default python project
Expand All @@ -47,20 +47,20 @@ Create a project using one of the available templates

``$ do create <project-name> -t <template>``

*-t* is the short for *template*.
*-t* is the short for *--template*.

Available templates:

- *flask*
- *django*
- *pymin* (minimal python project)

To use your own template you can use a *.json* file in your current
To use your own template you need to store it in a *.json* file in your current
directory, e.g.:

``my_template.json``

And call it using:
And use it by:

``$ do create my_project -t my_template``

Expand All @@ -69,20 +69,20 @@ A step by step setup for new projects

``$ do assistant``

This command fills:
This command help you fill:

- ``setup.py``
- ``AUTHORS.rst``
- ``LICENSE``
- ``.gitignore`` file with rules for *Linux*, *MacOs*,
- ``.gitignore`` with rules for *Linux*, *MacOs*,
*Windows*, *Python*, *Visual Studio*, *VS Code*, *Sublime Text* and
*Pycharm* (made with https://www.gitignore.io/).

Default Folder Structure and Templates
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This is the folder structure created when using
``do create <my_project>``.
``do create <my_project>`` and ``do assistant``.

::

Expand All @@ -103,11 +103,11 @@ This is the folder structure created when using
├── requirements.txt
└── test-requirements.txt

- The template system use a ``.json`` file in wich the keys are the
- The template system use a ``.json`` file in wich the keys are
folders and the values are files.
- Every time a folder is created, the program will automatically enter
it. If you need to exit that folder so the next one is placed in the
same directory, ``<--`` can be used as many times needed.
same directory, place a ``<--`` in the files (values) as many times needed.
- Folders (keys) ``base`` and ``bin`` are replaced with the project name.
- ``project.py`` is replaced with the project name (e.g.
``my_project.py``).
Expand Down Expand Up @@ -148,8 +148,7 @@ This is the template for the default folder structure:
TODOs
~~~~~

- Implement a ``template`` to ``assistant`` (75%).
- Add github username to the ``config`` command to fill the project
- Implement ``--template`` for the ``assistant`` command (75%).
- Add github username to the ``config`` command for the project
url.
- Generate the documentation (sphinx).
- Add a template for a python ``.gitignore``.
38 changes: 17 additions & 21 deletions do/assist.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
Create de skeleton of the python project and
Create the structure of the python project and
Redirect the files and folders to the proper function.
Also write the AUTHORS.rst, LICENSE and setup.py with
the users inputs.
Also write the AUTHORS.rst, LICENSE, .gitignore and
setup.py files with the users inputs.
"""
import os
import sys
Expand All @@ -13,23 +13,20 @@

def make_skeleton(project_name, authors, choosen_license, setup, gitignore):
"""
Create de skeleton of the python project and
Creates the structure of the python project and
redirect the files and folders to the proper function.
"""
# TODO: 50% - implement a template system for the skeleton in .json
loaded_template = load_template()
# make the folders
for folder in loaded_template.keys():
for folder in loaded_template.keys(): # make the folders
makedir(folder, project_name)
# make the files
for files in loaded_template[folder]:
for files in loaded_template[folder]: # make the files
makefile(files, project_name, authors,
choosen_license, setup, gitignore)


def load_template():
"""
Load the template for the python package
Load the default template for the python package
"""
skeleton = os.path.join(os.path.dirname(__file__),
'templates', 'default_structure.json')
Expand All @@ -48,8 +45,7 @@ def makedir(directory, project_name):
# change the name of base and bin for the name of the project
if (directory == 'base') or (directory == 'bin'):
directory = project_name
# write the folders
try:
try: # write the folders
os.makedirs(directory)
os.chdir(directory)
except FileExistsError:
Expand All @@ -60,7 +56,8 @@ def makedir(directory, project_name):
def makefile(file, project_name, authors, choosen_license, setup, gitignore):
"""
Make the files for the project and write the content
of AUTHORS.rst, LICENSE and setup.py in assistant mode
of AUTHORS.rst, LICENSE, .gitignore and setup.py in
assistant mode
"""
# change the names project.py and test_project.py
if file == 'project.py':
Expand All @@ -73,8 +70,7 @@ def makefile(file, project_name, authors, choosen_license, setup, gitignore):
'AUTHORS.rst': lambda: writefile(file, authors),
'setup.py': lambda: writefile(file, setup),
'.gitignore': lambda: writefile(file, gitignore)
}
# if the file is found, template it, else, None
} # if the file is found, template it, else, None
template_files.get(file, lambda: writefile(file))()


Expand All @@ -86,12 +82,12 @@ def writefile(file, content=''):
if file == '<--': # go back one directory
os.chdir('..')
else:
try:
with open(file, 'w') as f:
f.write(content)
except Exception as e:
click.echo('Error wrinting {}. Aborted!'.format(file))
sys.exit(1)
# try:
with open(file, 'w') as f:
f.write(content)
# except Exception as e:
# click.echo('Error wrinting {}. Aborted!'.format(file))
# sys.exit(1)


if __name__ == '__main__':
Expand Down
5 changes: 4 additions & 1 deletion do/config.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{"default_author": "John Smith", "default_mail": "john@smith.com"}
{
"default_author": "John Smith",
"default_mail": "john@smith.com"
}
19 changes: 16 additions & 3 deletions do/config.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
"""
Retrieve and load the user inputs for common fields.
config command.
"""
import os
import json


# the absolute path to config.json
path_config = os.path.join(
os.path.dirname(__file__), 'config.json')


def load_json():
"""
Load the config.json
"""
with open(path_config, 'r') as f:
return json.load(f)


def write_json(author, mail):
"""
Retrieves the input info form do.config()
and write the confit.json.
"""
loaded_config = load_json()
loaded_config['default_author'] = author
loaded_config['default_mail'] = mail
Expand All @@ -21,10 +32,12 @@ def write_json(author, mail):


def show_common(field):
"""
return the default data for the assistant command
"""
loaded_config = load_json()
return loaded_config[field]


if __name__ == '__main__':
a = show_common('default_author')
print(a)
pass
41 changes: 24 additions & 17 deletions do/do.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
"""
A simple and quick command line tool to create python packages.
"""

import do.template_config
import do.skeleton
import do.licenses
Expand All @@ -8,13 +12,10 @@
import os


# TODO: implement templates for create() (empty structure) 50%.


@click.group()
def main():
"""
Simple command-line tool to create python packages.
A simple and quick command line tool to create python packages.
"""
pass

Expand All @@ -25,7 +26,7 @@ def main():
@click.argument('project-name')
def create(project_name, template):
"""
creates an empty structure for your package.
creates a default python structure for your package or project.
"""
# long messages
notice = '\ndo will create your {} Project Structure.'.format(project_name)
Expand All @@ -38,12 +39,12 @@ def create(project_name, template):
click.echo(notice_t)
if click.confirm('Do you want to continue?'):
do.skeleton.make_skeleton(project_name, template)
click.echo(done.format(project_name, os.path.join(os.getcwd())))
click.echo(done.format(project_name, os.getcwd()))
else:
click.echo(notice)
if click.confirm('Do you want to continue?'):
do.skeleton.make_skeleton(project_name)
click.echo(done.format(project_name, os.path.join(os.getcwd())))
click.echo(done.format(project_name, os.getcwd()))


@main.command()
Expand All @@ -56,8 +57,7 @@ def assistant():
msg_lice_ref = '(more detailed info in https://choosealicense.com):\n'
msg_choose_lice = '\nEnter the number of the license to choose one'

# clear the console
os.system('cls')
clear() # clear the console

# click.echo('do will now start the assistant.')
if click.confirm(msg_notice):
Expand Down Expand Up @@ -99,39 +99,42 @@ def assistant():
setup, gitignore
)
click.echo('\n>> {} was created on {}'.format(
project_name, os.path.join(os.getcwd())))
project_name, os.getcwd()))


@main.command()
def config():
"""
A simple configuration for common fields.
A simple configuration for common fields (author_name
and author_email).
If executed twice, it will overwrite the previous one.
"""
# TODO: add github user name for the project url

# retrieve the config data from config.json
config_field = do.config.show_common
default_author = config_field('default_author')
default_mail = config_field('default_mail')

# long messages
msg_welcome = '\nWelcome to the configuration for common fields.'
msg_ask_author = '\nauthor'
msg_ask_mail = 'author_email'

# ask
click.echo(msg_welcome)
if click.confirm('Do you want to continue?'):
oneTime_author = click.prompt(msg_ask_author, default=default_author)
oneTime_mail = click.prompt(msg_ask_mail, default=default_mail)
oneTime_author = click.prompt('\nauthor', default=default_author)
oneTime_mail = click.prompt('author_email', default=default_mail)
# write the fields in config.json
do.config.write_json(oneTime_author, oneTime_mail)


def lice(num, setup_author, project_name):
# using a dict instead of an if statement
"""
Returns the license choosed by the user.
"""
choose = do.licenses.choose
return {
return { # dict instead of an if statement
'1': lambda: choose('Apache License 2.0', setup_author),
'2': lambda: choose('BSD License', setup_author),
'3': lambda: choose('GNU Affero General Public License v3',
Expand All @@ -146,5 +149,9 @@ def lice(num, setup_author, project_name):
}.get(num, lambda: sys.exit(1))()


def clear():
os.system('cls' if os.name == 'nt' else 'clear')


if __name__ == '__main__':
main()
Loading

0 comments on commit 0ede33b

Please sign in to comment.