cookiecutter-pypackage icon indicating copy to clipboard operation
cookiecutter-pypackage copied to clipboard

src/{{cookiecutter-package}} layout breaks CLI module

Open egberts opened this issue 6 years ago • 0 comments

  • Date you used Cookiecutter PyPackage: Dec 10-12, 2018
  • Cookiecutter version used, if any: 1.60
  • Python version, if any: Python3.5 (and Python 3.7)
  • Operating System: MacOSX (and Linux/Debian 9/Stretch)

Description

This is my attempt to use the Python project template with the following characteristics:

  • tests directory is outside of package
  • package name is under src subdirectory

As outline in this commonly read Python article on directory layouts in https://blog.ionelmc.ro/2014/05/25/python-packaging/.

But I cannot get the {{cookiecutter-package}}.cli module to be import-able into python CLI session (or from any Python script having such said import statement.

Strangely, all other packages modules under src/reconfigure were import-able, just not CLI.

What I Did

Error looks like:

$ cd ~/work/python/junk
$ python3 -m venv env3
$ cd env3
$ source bin/activate
$ git clone https://github.com/audreyr/cookiecutter.git
$ cd cookiecutter
$ python3 setup.py build
$ python3 setup.py install
$ hash -r
$ cookiecutter --version
1.6.0
$ cookiecutter https://github.com/audreyr/cookiecutter-pypackage.git
You've downloaded /home/steve/.cookiecutters/cookiecutter-pypackage before. Is it okay to delete and re-download it? [yes]: yes
full_name [Audrey Roy Greenfeld]: John Doe
email [[email protected]]: [email protected]
github_username [audreyr]: egberts
project_name [Python Boilerplate]: Python Reconfigure
project_slug [reconfigure]: 
project_short_description [Python Boilerplate contains all the boilerplate you need to create a Python package.]: 
pypi_username [egberts]: 
version [0.1.0]: 2.0.0
use_pytest [n]: y
use_pypi_deployment_with_travis [y]: 
add_pyup_badge [n]: 
Select command_line_interface:
1 - Click
2 - No command-line interface
Choose from 1, 2 (1, 2) [1]: 1
create_author_file [y]: 
Select open_source_license:
1 - MIT license
2 - BSD license
3 - ISC license
4 - Apache Software License 2.0
5 - GNU General Public License v3
6 - Not open source
Choose from 1, 2, 3, 4, 5, 6 (1, 2, 3, 4, 5, 6) [1]: 5
(env3) ~/work/python/junk/env3$

This is the part where I push the package subdirectory down the newly created src directory.

(env3) ~/work/python/junk/env3$ cd reconfigure
(env3) ~/work/python/junk/env3/reconfigure$ mkdir src
(env3) ~/work/python/junk/env3/reconfigure$ mv reconfigure src/

Final directory layout now looks like:

reconfigure
  |
  +-- docs
  +-- .github
  +-- .eggs
  +-- reconfigure.egg-info
  +-- src
  |    |
  |    +-- reconfigure.  # Python Installable Package
  +-- tests

Then build a basic CLI

(env3) ~/work/python/junk/env3/reconfigure3$ make distclean
(env3) ~/work/python/junk/env3/reconfigure$ python3 setup.py build
(env3) ~/work/python/junk/env3/reconfigure$ pip install -e .

Then onward to see if the CLI module is importable:

pytest
============================= test session starts ==============================
platform linux -- Python 3.5.3, pytest-3.7.1, py-1.5.4, pluggy-0.7.1
rootdir: ~/work/python/junk/env3/reconfigure, inifile: setup.cfg
plugins: pylama-7.6.6
collected 0 items / 1 errors                                                   

==================================== ERRORS ====================================
__________________ ERROR collecting tests/test_reconfigure.py __________________
ImportError while importing test module '~/work/python/junk/env3/reconfigure/tests/test_reconfigure.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests/test_reconfigure.py:10: in <module>
    from reconfigure import reconfigure
E   ImportError: cannot import name 'reconfigure'
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.19 seconds ============================
(env3) ~/work/python/junk/env3/reconfigure$

egberts avatar Dec 13 '18 01:12 egberts