Re: [Tutor] When are "__init__.py" files needed and not needed in a project?

2018-10-20 Thread boB Stepp
On Sat, Oct 20, 2018 at 11:21 PM Alex Kleider  wrote:
>
> On 2018-10-20 14:52, boB Stepp wrote:
>
>
> >> > In case it helps, my current project structure is:
> >> >
> >> > ~/Projects/solitaire_scorekeeper/# I left off the actual project 
> >> > folder in my original email
> >> > data/
> >> > docs/
> >> > tests/
> >> > .git/
> >> > main.py
> >> > .gitignore
>
>
> I'm curious to know where under the above structure you keep your code
> files? (...or is all your code within main.py?)

For this project, I am hoping that in the end there will not be a lot
of code, so I am currently putting all code in main.py.  If this gets
too unwieldy I will move all refactored source code files into a new
"src" subdirectory.


-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When are "__init__.py" files needed and not needed in a project?

2018-10-20 Thread Alex Kleider

On 2018-10-20 14:52, boB Stepp wrote:



> In case it helps, my current project structure is:
>
> ~/Projects
> data/
> docs/
> tests/
> .git/
> main.py
> .gitignore



I'm curious to know where under the above structure you keep your code 
files? (...or is all your code within main.py?)


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When are "__init__.py" files needed and not needed in a project?

2018-10-20 Thread boB Stepp
On Sat, Oct 20, 2018 at 1:36 PM Peter Otten <__pete...@web.de> wrote:
>
> boB Stepp wrote:
>
> > Linux Mint 19 Cinnamon, Python 3.6.6
[snip]
> > I was expecting this error and will shortly correct it.  So my
> > question remains, when are "__init__.py" files needed and when are
> > they not?
>
> I am struggling with the differences between the two types of packages
> myself, so my first guess was that you accidentally found out that test
> discovery doesn't work for namespace packages. However
>
> https://docs.python.org/dev/library/unittest.html#test-discovery
>
> expicitly states
>
> """
> Changed in version 3.4: Test discovery supports namespace packages.
> """
>
> Perhaps you should file a bug report.

I just waded through PEP 420 describing "implicit namespace packages".
I think I have a cursory understanding now, but not enough to feel
confidant to file a bug report.  It *seems* that with my project
structure below (Note the slight correction.) if I initiate test
discovery in the top level directory (The one holding main.py.) and
have no __init__.py files anywhere, that my initial effort should have
run the one test with the resulting error instead of running 0 tests.
Can anything reading this duplicate my issue?  If yes, then I will
endeavour to file a bug report.  But otherwise, I would suspect
something screwy that I have done and am currently unaware of what it
may be.

> > In case it helps, my current project structure is:
> >
> > ~/Projects
> > data/
> > docs/
> > tests/
> > .git/
> > main.py
> > .gitignore

Just noticed that I mistyped the top level of my project structure.
It should be:
~/Projects/solitaire_scorekeeper/
etc.


-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] When are "__init__.py" files needed and not needed in a project?

2018-10-20 Thread Peter Otten
boB Stepp wrote:

> Linux Mint 19 Cinnamon, Python 3.6.6
> 
> I would have sworn that I had read, either on this list or the main
> Python list, that in the most recent versions of Python 3 that
> "__init__.py" files were no longer needed in nested project file
> structures.  

If you omit the __init__.py you get a "namespace package".

Namespace packages can combine multiple directories into one package, but 
will be shaded by "normal" packages.

> But when I attempted to run tests for the first time on
> my new Solitaire Scorekeeper project (Finally getting around to
> this!), I got:
> 
> bob@Dream-Machine1:~/Projects/solitaire_scorekeeper$ python3 -m unittest
> 
> --
> Ran 0 tests in 0.000s
> 
> OK
> 
> So no tests were run.  So it immediately occurred to me to add an
> empty "__init__.py" file to my "tests" subfolder and got what I was
> currently expecting:
> 
> bob@Dream-Machine1:~/Projects/solitaire_scorekeeper$ python3 -m unittest
> E
> ==
> ERROR: test_get_gamenames_bad_path
> (tests.tests_main.TestGameNamesMapperMethods) Test that when the method,
> get_gamenames(), is passed a path to a
> --
> Traceback (most recent call last):
>   File "/home/bob/Projects/solitaire_scorekeeper/tests/tests_main.py",
> line 20, in test_get_gamenames_bad_path
> self.assertEqual(gamenames.gamenames(), {})
> NameError: name 'self' is not defined
> 
> --
> Ran 1 test in 0.000s
> 
> FAILED (errors=1)
> 
> I was expecting this error and will shortly correct it.  So my
> question remains, when are "__init__.py" files needed and when are
> they not?

I am struggling with the differences between the two types of packages 
myself, so my first guess was that you accidentally found out that test
discovery doesn't work for namespace packages. However

https://docs.python.org/dev/library/unittest.html#test-discovery

expicitly states

"""
Changed in version 3.4: Test discovery supports namespace packages.
"""

Perhaps you should file a bug report.

> In case it helps, my current project structure is:
> 
> ~/Projects
> data/
> docs/
> tests/
> .git/
> main.py
> .gitignore
> 
> TIA!
> 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] When are "__init__.py" files needed and not needed in a project?

2018-10-20 Thread boB Stepp
Linux Mint 19 Cinnamon, Python 3.6.6

I would have sworn that I had read, either on this list or the main
Python list, that in the most recent versions of Python 3 that
"__init__.py" files were no longer needed in nested project file
structures.  But when I attempted to run tests for the first time on
my new Solitaire Scorekeeper project (Finally getting around to
this!), I got:

bob@Dream-Machine1:~/Projects/solitaire_scorekeeper$ python3 -m unittest

--
Ran 0 tests in 0.000s

OK

So no tests were run.  So it immediately occurred to me to add an
empty "__init__.py" file to my "tests" subfolder and got what I was
currently expecting:

bob@Dream-Machine1:~/Projects/solitaire_scorekeeper$ python3 -m unittest
E
==
ERROR: test_get_gamenames_bad_path (tests.tests_main.TestGameNamesMapperMethods)
Test that when the method, get_gamenames(), is passed a path to a
--
Traceback (most recent call last):
  File "/home/bob/Projects/solitaire_scorekeeper/tests/tests_main.py",
line 20, in test_get_gamenames_bad_path
self.assertEqual(gamenames.gamenames(), {})
NameError: name 'self' is not defined

--
Ran 1 test in 0.000s

FAILED (errors=1)

I was expecting this error and will shortly correct it.  So my
question remains, when are "__init__.py" files needed and when are
they not?

In case it helps, my current project structure is:

~/Projects
data/
docs/
tests/
.git/
main.py
.gitignore

TIA!

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor