Skip to content

Commit

Permalink
Merge pull request #15 from roedesh/issue-14
Browse files Browse the repository at this point in the history
Removed unnecessary README files from brewjs and libnx templates
  • Loading branch information
roedesh authored Dec 2, 2018
2 parents 9b22db3 + 67d6f6f commit ad1470a
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 145 deletions.
30 changes: 20 additions & 10 deletions nxstart/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,27 @@ def __init__(self):


@click.group()
@click.option('--name', '-n', default=None, help='The name of your project')
@click.option('--author', '-a', default=None, help='The full name of the author')
@click.option("--name", "-n", default=None, help="The name of your project")
@click.option("--author", "-a", default=None, help="The full name of the author")
@pass_context
def cli(ctx, name, author):
click.echo(TITLE_TEXT)
click.echo(VERSION_STRING)
if not name:
name = click.prompt('Please enter the name of your project', type=str)
name = click.prompt("Please enter the name of your project", type=str)
if not author:
author = click.prompt('Please enter your name', type=str)
author = click.prompt("Please enter your name", type=str)
ctx.name = name
ctx.author = author


@cli.command('libnx', short_help='create a new libnx project (C++)')
@click.option('--clion/--no-clion', default=False, prompt='Are you using CLion?', help='include CMakeLists.txt')
@cli.command("libnx", short_help="create a new libnx project (C++)")
@click.option(
"--clion/--no-clion",
default=False,
prompt="Are you using CLion?",
help="include CMakeLists.txt",
)
@pass_context
def libnx(ctx, clion):
"""
Expand All @@ -53,8 +58,13 @@ def libnx(ctx, clion):
app.libnx(ctx.name, ctx.author, clion, ctx.cwd)


@cli.command('libt', short_help='create a new libtransistor project (C)')
@click.option('--clion/--no-clion', default=False, prompt='Are you using CLion?', help='include CMakeLists.txt')
@cli.command("libt", short_help="create a new libtransistor project (C)")
@click.option(
"--clion/--no-clion",
default=False,
prompt="Are you using CLion?",
help="include CMakeLists.txt",
)
@pass_context
def libt(ctx, clion):
"""
Expand All @@ -66,7 +76,7 @@ def libt(ctx, clion):
app.libt(ctx.name, ctx.author, clion, ctx.cwd)


@cli.command('brewjs', short_help='create a new BrewJS project (Javascript)')
@cli.command("brewjs", short_help="create a new BrewJS project (Javascript)")
@pass_context
def brewjs(ctx):
"""
Expand All @@ -77,7 +87,7 @@ def brewjs(ctx):
app.brewjs(ctx.name, ctx.author, ctx.cwd)


@cli.command('pynx', short_help='create a new PyNX project (Python)')
@cli.command("pynx", short_help="create a new PyNX project (Python)")
@pass_context
def pynx(ctx):
"""
Expand Down
23 changes: 13 additions & 10 deletions nxstart/filebuilder/brewjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import os
from distutils.dir_util import copy_tree

from nxstart.utils.files import get_full_path, replace_in_file
from nxstart.utils.files import (check_and_create_directory, get_full_path,
replace_in_file)


def create_brewjs_project(folder_path, name, author):
Expand All @@ -18,21 +19,23 @@ def create_brewjs_project(folder_path, name, author):
:param name: Name of the project
:param author: Name of the author
"""
template_folder = get_full_path(os.path.join('templates', 'brewjs'))
template_folder = get_full_path(os.path.join("templates", "brewjs"))
copy_tree(template_folder, folder_path)

main_js_file = os.path.join(folder_path, 'Source.js')
main_js_file = os.path.join(folder_path, "Source.js")
main_js_replacements = {
'APP_AUTHOR_PLACEHOLDER': author,
'APP_NAME_PLACEHOLDER': name,
'DATE_PLACEHOLDER': datetime.datetime.now().strftime("%Y-%m-%d")
"APP_AUTHOR_PLACEHOLDER": author,
"APP_NAME_PLACEHOLDER": name,
"DATE_PLACEHOLDER": datetime.datetime.now().strftime("%Y-%m-%d"),
}
replace_in_file(main_js_file, main_js_replacements)

package_json_file = os.path.join(folder_path, 'package.json')
package_json_file = os.path.join(folder_path, "package.json")
package_json_replacements = {
'APP_AUTHOR_PLACEHOLDER': author,
'APP_NAME_PLACEHOLDER': name,
'DATE_PLACEHOLDER': datetime.datetime.now().strftime("%Y-%m-%d")
"APP_AUTHOR_PLACEHOLDER": author,
"APP_NAME_PLACEHOLDER": name,
"DATE_PLACEHOLDER": datetime.datetime.now().strftime("%Y-%m-%d"),
}
replace_in_file(package_json_file, package_json_replacements)

check_and_create_directory(os.path.join(folder_path, "assets"))
16 changes: 7 additions & 9 deletions nxstart/filebuilder/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"""Includes generic functions such as copying the README.md file."""

import glob
import os

from nxstart.utils.files import replace_in_file
Expand All @@ -15,11 +16,10 @@ def modify_readme_file(folder_path, name, author):
:param name: Project name
:param author: Project author
"""
new_readme_file = os.path.join(folder_path, 'README.md')
new_readme_file = os.path.join(folder_path, "README.md")
new_readme_file_replacements = {
'APP_NAME_PLACEHOLDER': name,
'APP_AUTHOR_PLACEHOLDER': author

"APP_NAME_PLACEHOLDER": name,
"APP_AUTHOR_PLACEHOLDER": author,
}
replace_in_file(new_readme_file, new_readme_file_replacements)

Expand All @@ -30,7 +30,7 @@ def remove_cmake_lists_file(folder_path):
:param folder_path: Path to created folder
"""
cmake_lists_file = os.path.join(folder_path, 'CMakeLists.txt')
cmake_lists_file = os.path.join(folder_path, "CMakeLists.txt")
os.remove(cmake_lists_file)


Expand All @@ -41,8 +41,6 @@ def modify_cmake_lists_file(folder_path, folder_name):
:param folder_path: Path to created folder
:param folder_name: Project folder name
"""
cmake_lists_file = os.path.join(folder_path, 'CMakeLists.txt')
cmake_lists_file_replacements = {
'FOLDER_NAME_PLACEHOLDER': folder_name
}
cmake_lists_file = os.path.join(folder_path, "CMakeLists.txt")
cmake_lists_file_replacements = {"FOLDER_NAME_PLACEHOLDER": folder_name}
replace_in_file(cmake_lists_file, cmake_lists_file_replacements)
22 changes: 13 additions & 9 deletions nxstart/filebuilder/libnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import os
from distutils.dir_util import copy_tree

from nxstart.utils.files import get_full_path, replace_in_file
from nxstart.utils.files import (check_and_create_directory, get_full_path,
replace_in_file)


def create_libnx_project(folder_path, name, author):
Expand All @@ -18,20 +19,23 @@ def create_libnx_project(folder_path, name, author):
:param name: Name of the project
:param author: Name of the author
"""
template_folder = get_full_path(os.path.join('templates', 'libnx'))
template_folder = get_full_path(os.path.join("templates", "libnx"))
copy_tree(template_folder, folder_path)

main_cpp_file = os.path.join(folder_path, 'source', 'main.cpp')
main_cpp_file = os.path.join(folder_path, "source", "main.cpp")
main_cpp_replacements = {
'APP_AUTHOR_PLACEHOLDER': author,
'APP_NAME_PLACEHOLDER': name,
'DATE_PLACEHOLDER': datetime.datetime.now().strftime("%Y-%m-%d")
"APP_AUTHOR_PLACEHOLDER": author,
"APP_NAME_PLACEHOLDER": name,
"DATE_PLACEHOLDER": datetime.datetime.now().strftime("%Y-%m-%d"),
}
replace_in_file(main_cpp_file, main_cpp_replacements)

makefile = os.path.join(folder_path, 'Makefile')
makefile = os.path.join(folder_path, "Makefile")
makefile_replacements = {
'APP_NAME_PLACEHOLDER': name,
'APP_AUTHOR_PLACEHOLDER': author
"APP_NAME_PLACEHOLDER": name,
"APP_AUTHOR_PLACEHOLDER": author,
}
replace_in_file(makefile, makefile_replacements)

check_and_create_directory(os.path.join(folder_path, "data"))
check_and_create_directory(os.path.join(folder_path, "includes"))
16 changes: 8 additions & 8 deletions nxstart/filebuilder/libt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ def create_libt_project(folder_path, name, author):
:param name: Name of the project
:param author: Name of the author
"""
template_folder = get_full_path(os.path.join('templates', 'libt'))
template_folder = get_full_path(os.path.join("templates", "libt"))
copy_tree(template_folder, folder_path)

main_c_file = os.path.join(folder_path, 'main.c')
main_c_file = os.path.join(folder_path, "main.c")
main_c_replacements = {
'APP_AUTHOR_PLACEHOLDER': author,
'APP_NAME_PLACEHOLDER': name,
'DATE_PLACEHOLDER': datetime.datetime.now().strftime("%Y-%m-%d")
"APP_AUTHOR_PLACEHOLDER": author,
"APP_NAME_PLACEHOLDER": name,
"DATE_PLACEHOLDER": datetime.datetime.now().strftime("%Y-%m-%d"),
}
replace_in_file(main_c_file, main_c_replacements)

makefile = os.path.join(folder_path, 'Makefile')
makefile = os.path.join(folder_path, "Makefile")
makefile_replacements = {
'APP_NAME_PLACEHOLDER': name,
'APP_AUTHOR_PLACEHOLDER': author
"APP_NAME_PLACEHOLDER": name,
"APP_AUTHOR_PLACEHOLDER": author,
}
replace_in_file(makefile, makefile_replacements)
10 changes: 5 additions & 5 deletions nxstart/filebuilder/pynx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def create_pynx_project(folder_path, name, author):
:param name: Name of the project
:param author: Name of the author
"""
template_folder = get_full_path(os.path.join('templates', 'pynx'))
template_folder = get_full_path(os.path.join("templates", "pynx"))
copy_tree(template_folder, folder_path)

main_cpp_file = os.path.join(folder_path, 'main.py')
main_cpp_file = os.path.join(folder_path, "main.py")
main_cpp_replacements = {
'APP_AUTHOR_PLACEHOLDER': author,
'APP_NAME_PLACEHOLDER': name,
'DATE_PLACEHOLDER': datetime.datetime.now().strftime("%Y-%m-%d")
"APP_AUTHOR_PLACEHOLDER": author,
"APP_NAME_PLACEHOLDER": name,
"DATE_PLACEHOLDER": datetime.datetime.now().strftime("%Y-%m-%d"),
}
replace_in_file(main_cpp_file, main_cpp_replacements)
1 change: 0 additions & 1 deletion nxstart/templates/brewjs/assets/README.txt

This file was deleted.

1 change: 0 additions & 1 deletion nxstart/templates/libnx/data/README.txt

This file was deleted.

1 change: 0 additions & 1 deletion nxstart/templates/libnx/include/README.txt

This file was deleted.

4 changes: 2 additions & 2 deletions nxstart/templates/pynx/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ def main():
"""
The main loop
"""
print('Hello world!')
print("Hello world!")


if __name__ == '__main__':
if __name__ == "__main__":
main()
20 changes: 10 additions & 10 deletions nxstart/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import os

# Some constants to be used in tests
APP_NAME = 'Test project'
APP_AUTHOR = 'Ruud Schroën'
APP_NAME = "Test project"
APP_AUTHOR = "Ruud Schroën"
DATE_CREATED = datetime.datetime.now().strftime("%Y-%m-%d")
DIRECTORY_NAME = 'test_project'
DIRECTORY_NAME = "test_project"


def directory_exists():
def directory_exists(folder_name=DIRECTORY_NAME):
"""
Check if a folder called DIRECTORY_NAME exists
Check if a folder exists
"""
return os.path.isdir(DIRECTORY_NAME)
return os.path.isdir(folder_name)


def file_exists(file_path):
Expand All @@ -35,8 +35,8 @@ def file_contains_strings(file_path, strings):
:param file_path: File to check
:param strings: List of strings
"""
with open(os.path.join(DIRECTORY_NAME, file_path), 'r') as file:
data = file.read().replace('\n', '')
with open(os.path.join(DIRECTORY_NAME, file_path), "r") as file:
data = file.read().replace("\n", "")
for s in strings:
if s not in data:
return False
Expand All @@ -47,11 +47,11 @@ def readme_has_project_and_author_name():
"""
Checks that the README.md contains the project and author name.
"""
return file_contains_strings('README.md', [APP_NAME, APP_AUTHOR])
return file_contains_strings("README.md", [APP_NAME, APP_AUTHOR])


def makefile_has_project_and_author_name():
"""
Check that the Makefile contains the project and author name.
"""
return file_contains_strings('Makefile', [APP_NAME, APP_AUTHOR])
return file_contains_strings("Makefile", [APP_NAME, APP_AUTHOR])
16 changes: 10 additions & 6 deletions nxstart/tests/test_cli_brewjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@

"""Includes test for the 'brewjs' command"""

import os

from click.testing import CliRunner

from nxstart.cli import cli
from nxstart.tests.helpers import directory_exists, file_contains_strings, APP_NAME, APP_AUTHOR, DATE_CREATED
from nxstart.tests.helpers import (APP_AUTHOR, APP_NAME, DATE_CREATED,
DIRECTORY_NAME, directory_exists,
file_contains_strings)


def test_brewjs():
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(cli, ['-n', APP_NAME, '-a', APP_AUTHOR, 'brewjs'])
result = runner.invoke(cli, ["-n", APP_NAME, "-a", APP_AUTHOR, "brewjs"])
assert not result.exception
assert result.output.endswith('Successfully created the BrewJS project!\n')
assert directory_exists()
assert file_contains_strings('Source.js', [APP_NAME, APP_AUTHOR, DATE_CREATED])
assert file_contains_strings('package.json', [APP_NAME, APP_AUTHOR])
assert result.output.endswith("Successfully created the BrewJS project!\n")
assert directory_exists(os.path.join(DIRECTORY_NAME, "assets"))
assert file_contains_strings("Source.js", [APP_NAME, APP_AUTHOR, DATE_CREATED])
assert file_contains_strings("package.json", [APP_NAME, APP_AUTHOR])
34 changes: 22 additions & 12 deletions nxstart/tests/test_cli_libnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,24 @@
from click.testing import CliRunner

from nxstart.cli import cli
from nxstart.tests.helpers import directory_exists, readme_has_project_and_author_name, \
makefile_has_project_and_author_name, file_contains_strings, file_exists, APP_AUTHOR, APP_NAME, \
DATE_CREATED
from nxstart.tests.helpers import (APP_AUTHOR, APP_NAME, DATE_CREATED,
DIRECTORY_NAME, directory_exists,
file_contains_strings, file_exists,
makefile_has_project_and_author_name,
readme_has_project_and_author_name)


def test_libnx_with_clion():
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(cli, ['-n', APP_NAME, '-a', APP_AUTHOR, 'libnx', '--clion'])
result = runner.invoke(
cli, ["-n", APP_NAME, "-a", APP_AUTHOR, "libnx", "--clion"]
)
assert not result.exception
assert result.output.endswith('Successfully created the libnx project!\n')
assert directory_exists()
assert file_exists('CMakeLists.txt')
assert result.output.endswith("Successfully created the libnx project!\n")
assert directory_exists(os.path.join(DIRECTORY_NAME, "data"))
assert directory_exists(os.path.join(DIRECTORY_NAME, "includes"))
assert file_exists("CMakeLists.txt")
assert readme_has_project_and_author_name()
assert makefile_has_project_and_author_name()
assert main_cpp_has_valid_data()
Expand All @@ -28,15 +33,20 @@ def test_libnx_with_clion():
def test_libnx_without_clion():
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(cli, ['-n', APP_NAME, '-a', APP_AUTHOR, 'libnx', '--no-clion'])
result = runner.invoke(
cli, ["-n", APP_NAME, "-a", APP_AUTHOR, "libnx", "--no-clion"]
)
assert not result.exception
assert result.output.endswith('Successfully created the libnx project!\n')
assert directory_exists()
assert not file_exists('CMakeLists.txt')
assert result.output.endswith("Successfully created the libnx project!\n")
assert directory_exists(os.path.join(DIRECTORY_NAME, "data"))
assert directory_exists(os.path.join(DIRECTORY_NAME, "includes"))
assert not file_exists("CMakeLists.txt")
assert readme_has_project_and_author_name()
assert makefile_has_project_and_author_name()
assert main_cpp_has_valid_data()


def main_cpp_has_valid_data():
return file_contains_strings(os.path.join('source', 'main.cpp'), [APP_NAME, APP_AUTHOR, DATE_CREATED])
return file_contains_strings(
os.path.join("source", "main.cpp"), [APP_NAME, APP_AUTHOR, DATE_CREATED]
)
Loading

0 comments on commit ad1470a

Please sign in to comment.