diff --git a/docs/_templates/alabaster/support.py b/docs/_templates/alabaster/support.py index 7e52612..7361718 100644 --- a/docs/_templates/alabaster/support.py +++ b/docs/_templates/alabaster/support.py @@ -1,8 +1,20 @@ # flake8: noqa from pygments.style import Style -from pygments.token import (Comment, Error, Generic, Keyword, Literal, Name, Number, Operator, Other, Punctuation, - String, Whitespace) +from pygments.token import ( + Comment, + Error, + Generic, + Keyword, + Literal, + Name, + Number, + Operator, + Other, + Punctuation, + String, + Whitespace, +) # Originally based on FlaskyStyle which was based on 'tango'. diff --git a/medikit/commands/init.py b/medikit/commands/init.py index bc562e6..9ddc304 100644 --- a/medikit/commands/init.py +++ b/medikit/commands/init.py @@ -44,7 +44,7 @@ def handle(config_filename, **options): # - ... with _change_working_directory(config_dirname): dispatcher = LoggingDispatcher() - initializer = ProjectInitializer(dispatcher, options) + initializer = ProjectInitializer(dispatcher, options, target=config_dirname) initializer.execute() from medikit.commands import UpdateCommand diff --git a/medikit/feature/__init__.py b/medikit/feature/__init__.py index ab4ba3b..90fa4c6 100644 --- a/medikit/feature/__init__.py +++ b/medikit/feature/__init__.py @@ -113,23 +113,30 @@ def get_config(self, event, feature=None): class ProjectInitializer(Feature): - def __init__(self, dispatcher, options): + def __init__(self, dispatcher, options, target=None): super().__init__(dispatcher) self.options = options + self.target = target def execute(self): - context = {} + context = {"name": ""} if self.options.get("name"): if not is_identifier(self.options["name"]): - raise RuntimeError("Invalid package name {!r}.".format(self.options["name"])) + raise RuntimeError( + "Invalid package name {!r}. Please only use valid python identifiers.".format(self.options["name"]) + ) context["name"] = self.options["name"] - logging.info("name = %s", context["name"]) - else: + elif self.target: + context["name"] = os.path.basename(self.target) + + while not is_identifier(context["name"]): context["name"] = input("Name: ") - while not is_identifier(context["name"]): - logging.error("Invalid name. Please only use valid python identifiers.") - context["name"] = input("Name: ") + logging.error( + "Invalid package name {!r}. Please only use valid python identifiers.".format(context["name"]) + ) + + logging.info("name = %s", context["name"]) if self.options.get("description"): context["description"] = self.options["description"] diff --git a/setup.py b/setup.py index 0eaf772..76b1603 100644 --- a/setup.py +++ b/setup.py @@ -20,70 +20,78 @@ def execfile(fname, globs, locs=None): # Get the long description from the README file try: - with open(path.join(here, 'README.rst'), encoding='utf-8') as f: + with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() except: - long_description = '' + long_description = "" # Get the classifiers from the classifiers file -tolines = lambda c: list(filter(None, map(lambda s: s.strip(), c.split('\n')))) +tolines = lambda c: list(filter(None, map(lambda s: s.strip(), c.split("\n")))) try: - with open(path.join(here, 'classifiers.txt'), encoding='utf-8') as f: + with open(path.join(here, "classifiers.txt"), encoding="utf-8") as f: classifiers = tolines(f.read()) except: classifiers = [] version_ns = {} try: - execfile(path.join(here, 'medikit/_version.py'), version_ns) + execfile(path.join(here, "medikit/_version.py"), version_ns) except EnvironmentError: - version = 'dev' + version = "dev" else: - version = version_ns.get('__version__', 'dev') + version = version_ns.get("__version__", "dev") setup( - author='Romain Dorgueil', - author_email='romain@dorgueil.net', - description='Opinionated python 3.5+ project management.', - license='Apache License, Version 2.0', - name='medikit', - python_requires='>=3.5', + author="Romain Dorgueil", + author_email="romain@dorgueil.net", + description="Opinionated python 3.5+ project management.", + license="Apache License, Version 2.0", + name="medikit", + python_requires=">=3.5", version=version, long_description=long_description, classifiers=classifiers, - packages=find_packages(exclude=['ez_setup', 'example', 'test']), + packages=find_packages(exclude=["ez_setup", "example", "test"]), include_package_data=True, install_requires=[ - 'git-semver ~= 0.2.3', 'jinja2 ~= 2.9', 'mondrian ~= 0.7', - 'packaging ~= 19.0', 'pip-tools ~= 3.0', 'stevedore ~= 1.28', - 'whistle ~= 1.0', 'yapf ~= 0.20' + "git-semver ~= 0.2.3", + "jinja2 ~= 2.9", + "mondrian ~= 0.7", + "packaging ~= 19.0", + "pip-tools ~= 3.0", + "stevedore ~= 1.28", + "whistle ~= 1.0", + "yapf ~= 0.20", ], extras_require={ - 'dev': [ - 'coverage ~= 4.4', 'isort', 'pytest ~= 3.4', 'pytest-cov ~= 2.5', - 'releases >= 1.6, < 1.7', 'sphinx ~= 1.7', 'sphinx-sitemap ~= 1.0' + "dev": [ + "coverage ~= 4.4", + "isort", + "pytest ~= 3.4", + "pytest-cov ~= 2.5", + "releases >= 1.6, < 1.7", + "sphinx ~= 1.7", + "sphinx-sitemap ~= 1.0", ] }, entry_points={ - 'console_scripts': ['medikit=medikit.__main__:main'], - 'medikit.feature': [ - 'django = medikit.feature.django:DjangoFeature', - 'docker = medikit.feature.docker:DockerFeature', - 'format = medikit.feature.format:FormatFeature', - 'git = medikit.feature.git:GitFeature', - 'kube = medikit.feature.kube:KubeFeature', - 'make = medikit.feature.make:MakeFeature', - 'nodejs = medikit.feature.nodejs:NodeJSFeature', - 'pylint = medikit.feature.pylint:PylintFeature', - 'pytest = medikit.feature.pytest:PytestFeature', - 'python = medikit.feature.python:PythonFeature', - 'sphinx = medikit.feature.sphinx:SphinxFeature', - 'webpack = medikit.feature.webpack:WebpackFeature', - 'yapf = medikit.feature.yapf:YapfFeature' - ] + "console_scripts": ["medikit=medikit.__main__:main"], + "medikit.feature": [ + "django = medikit.feature.django:DjangoFeature", + "docker = medikit.feature.docker:DockerFeature", + "format = medikit.feature.format:FormatFeature", + "git = medikit.feature.git:GitFeature", + "kube = medikit.feature.kube:KubeFeature", + "make = medikit.feature.make:MakeFeature", + "nodejs = medikit.feature.nodejs:NodeJSFeature", + "pylint = medikit.feature.pylint:PylintFeature", + "pytest = medikit.feature.pytest:PytestFeature", + "python = medikit.feature.python:PythonFeature", + "sphinx = medikit.feature.sphinx:SphinxFeature", + "webpack = medikit.feature.webpack:WebpackFeature", + "yapf = medikit.feature.yapf:YapfFeature", + ], }, - url='https://python-medikit.github.io/', - download_url= - 'https://github.com/python-medikit/medikit/archive/{version}.tar.gz'. - format(version=version), + url="https://python-medikit.github.io/", + download_url="https://github.com/python-medikit/medikit/archive/{version}.tar.gz".format(version=version), )