Re: Why not being able to call modules from lib folder into test folder although I have __init__.py file both?

2019-04-25 Thread dieter
Arup Rakshit  writes:
> I am not able to call modules from lib folder in my test folder, but outside 
> of tests folder I can access them. How should I fix this?
>
> Mocks$ tree .
> .
> ├── lib
> │   ├── __init__.py
> │   ├── __pycache__
> │   │   ├── __init__.cpython-37.pyc
> │   │   └── product.cpython-37.pyc
> │   └── product.py
> └── tests
> ├── __init__.py
> └── product_test.py
>
> 3 directories, 6 files
> Mocks$ python3
> ...
 from lib.product import ProductionKlass
> ...
 ProductionKlass()
> 
> ...
> Mocks$ python3 tests/product_test.py 
> Traceback (most recent call last):
>   File "tests/product_test.py", line 4, in 
> from lib.product import ProductionKlass
> ModuleNotFoundError: No module named 'lib'

Python's import is controlled by "sys.path" -- typically a sequence of
folders where Python should look for modules/packages to import.

When you start a Python script, it puts the folder containing
the script automatically on "sys.path" (to facilitate imports
by this script). When you start Python interactively, it puts
the current working directory on "sys.path".

These differences explain your observations.
In the first case, "lib" can be imported because
the current working directory has been put on "sys.path".
In the second case, "lib" cannot be imported because the subfolder
"tests" has been put on "sys.path" (not the current working directory
itself).


A modern approach to avoid such situations looks like:

 * make your project into a package
   (see "https://packaging.python.org/";)

 * use either package relative imports or absolute imports with
   the package as prefix to access modules in your package

 * install your package into a Python installation
   (use "virtualenv" to get a light weight local Python installation,
   if necessary)

 * have tiny script wrappers for scripts in your package.
   Packageing tools (such as "setuptools"
   --> "https://setuptools.readthedocs.io/en/latest/";)
   can create thoses wrappers for you on installation.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to catch a usefull error message ?

2019-04-25 Thread Vincent Vande Vyvre

Le 25/04/19 à 08:25, Chris Angelico a écrit :

On Thu, Apr 25, 2019 at 2:32 PM Vincent Vande Vyvre
 wrote:

Le 24/04/19 à 19:57, MRAB a écrit :

On 2019-04-23 20:21, Vincent Vande Vyvre wrote:

Le 23/04/19 à 20:54, Chris Angelico a écrit :


Why a SystemError ?
The SystemError means that you're using the Python C API in a way that
doesn't make sense to the interpreter. You're leaving a marker saying
"hey, I need you to throw an exception" but then you're also returning
a value. You'll need to figure out where that's happening and exactly
what is being called. How are you setting up your class?

ChrisA
The syntaxe

   if (!PyArg_ParseTuple(args, "s", &fname))
return NULL;

Is the usage described in the doc [*]

And without block try-except I get the good one error.


[*]
https://docs.python.org/3.5//extending/extending.html#back-to-the-example



If you look at the previous example, the function's return type is
"PyObject *".

On success it returns a reference (pointer) to an object; on error it
returns NULL.

Your function's return type is int.

In this case yes, beause it need to return the result of the command system.

But the "return 0" is a common case for an "Foo_init()"

see:
https://docs.python.org/3.5//extending/newtypes.html#adding-data-and-methods-to-the-basic-example

... And that's nothing to do with my initial question

Actually, it is a lot to do with your initial question. Notice how
there are two distinct signatures being demonstrated in the example
you linked to: those declared as returning PyObject* and those
declared as returning int. If something is meant to return an object,
then returning NULL says "hey, I set an error state, unwind the stack
and raise the exception". If it's meant to return an integer, though,
it returns -1 to give that message. See details here (second
paragraph):

https://docs.python.org/3/c-api/intro.html#exceptions

The __init__ function is defined as returning an integer:

https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_init

You're right that "return 0" is a common case; that isn't the problem.
The problem is the "return NULL", which is correct for a function that
normally returns a PyObject*, but not for one that returns an int.
That's why you're getting a SystemError - you're setting the exception
state, but then saying "hey, everything's fine, it's okay to return
None".

ChrisA


Does not change anything with PyObject *, same behaviour.

But with "static int" and "return -1;" instead of "NULL",  now I have 
the correct error.



So, thanks to all and sorry for the delays of my mails but it seems I'm 
always moderated ...



Vincent

--
https://mail.python.org/mailman/listinfo/python-list


Re: Running virtualenv to set the ENV

2019-04-25 Thread Rich Shepard

On Thu, 25 Apr 2019, Cameron Simpson wrote:


Personally, I like to treat the virtualenv as a source for third party
modules needed by the project. I explicitly do not like to pollute it with
project code - that way revision control can ignore the whole venv tree
and it can be blown away/rebuilt freely.

So my project setup looks like this:


Cameron,

Thank you for the full explanation. I'm not a computer professional so when
I read multiple approaches to setting up a project I have no background that
allows me to evaluate them. And there are many approaches in use.

More for me to think about.

Best regards,

Rich
--
https://mail.python.org/mailman/listinfo/python-list


Re: Importing module from another subdirectory

2019-04-25 Thread Rich Shepard

On Thu, 25 Apr 2019, dieter wrote:


The means that "test_act_de.py" has not extended "sys.path"
appropriately.


Dieter,

That's what I thought.


When Python starts a script ("gui/test_act_de.py" in your case), it
automatically extends "sys.path" with the folder containing the script
("gui" in your case).


This is what I expected based on what I read, and ...


If Python needs to find modules elsewhere, you must extend "sys.path" to
tell it where it should look.


this is what I missed in my reading. I'll explicitly extend sys.path when
it's not done automatically.

I've taken your suggestion of developing each project in its own virtual
environment and I think that explicitly appending imported packages will
resolve all these issues.

Many thanks,

Rich

--
https://mail.python.org/mailman/listinfo/python-list


Why not being able to call modules from lib folder into test folder although I have __init__.py file both?

2019-04-25 Thread Arup Rakshit
I am not able to call modules from lib folder in my test folder, but outside of 
tests folder I can access them. How should I fix this?

Mocks$ tree .
.
├── lib
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-37.pyc
│   │   └── product.cpython-37.pyc
│   └── product.py
└── tests
├── __init__.py
└── product_test.py

3 directories, 6 files
Mocks$ python3
Python 3.7.3 (default, Mar 27 2019, 09:23:15) 
[Clang 10.0.1 (clang-1001.0.46.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lib.product import ProductionKlass
>>> ProductionKlass()

>>> exit()
Mocks$ python3 tests/product_test.py 
Traceback (most recent call last):
  File "tests/product_test.py", line 4, in 
from lib.product import ProductionKlass
ModuleNotFoundError: No module named 'lib'
Mocks$ 

The file product_test.py has content like:

from unittest import mock
import unittest

from lib.product import ProductionKlass

class TesProductKlass(unittest.TestCase):
def setUp(self):
self.real = ProductionKlass()
self.real.something = mock.MagicMock()

def test_method(self):
self.real.method()
self.real.something.assert_called_once_with(1, 2, 3)

if __file__ == "__main__":
unittest.main()



Thanks,

Arup Rakshit
a...@zeit.io



-- 
https://mail.python.org/mailman/listinfo/python-list


EuroPython 2019: Call for Proposals

2019-04-25 Thread M.-A. Lemburg
We are happy to announce the Call for Proposals is now open. The CfP
will close on Sunday in two weeks:

   * Sunday, May 12 23:59:59 CEST *


Please submit your proposal via our website:

 * https://ep2019.europython.eu/events/call-for-proposals/ *

We’re looking for proposals on every aspect of Python: programming
from novice to advanced levels, applications and frameworks, or how
you have been involved in introducing Python into your
organization. EuroPython is a community conference and we are eager to
hear about your experience.

Please also forward this Call for Proposals to anyone that you feel
may be interested.

Presenting at EuroPython


We will accept a broad range of presentations, from reports on
academic and commercial projects to tutorials and case studies. As
long as the presentation is interesting and potentially useful to the
Python community, it will be considered for inclusion in the program.

Can you show something new and useful? Can you show the attendees how
to: use a module? Explore a Python language feature? Package an
application? If so, please consider submitting a talk.

PyData EuroPython 2019
--

As usual there will be a PyData track at this year’s
conference. Please submit your papers for the PyData track through the
EuroPython form. Any suitable (i.e. data science, AI and analytics)
submission will be considered for the PyData track.

The PyData track is run in cooperation with NumFocus.

The 2019 PyData track will be on Tuesday (trainings), Wednesday
(talks) and Thursday (talks).

There are six different kinds of contributions that you can present at
EuroPython:

Formats
---

* Talks and trainings should be held in English language only.

* Regular Talk / approx. 110 slots

  These are standard “talks with slides”, allocated in slots of

  The Q&A session, if present, is included in the time slot. 3-5
  Minutes for Q&A is a good practice.

  We will only offer a limited number of 60 minute slots, please only
  choose these slots for in-depth sessions or topics which require
  more background information.

  - 30 minutes (ca. 50%)
  - 45 minutes (ca. 34%)
  - 60 minutes (ca. 16%)

  We are looking for an approx. distribution of expertise (Python or
  domain expertise)

  - 40% Beginners
  - 25% Intermediate
  - 25% Advanced

* Trainings / 16 slots

  Deep-dive into a subject with all details. These sessions are
  apporx. 3 hours long. The training attendees will be encouraged to
  bring a laptop. They should be prepared with less slides and more
  source code. Room capacity for the trainings rooms is approx. 100
  seats.

* Panels

  A panel is group of three to six experts plus a moderator discussing
  a matter in depth, an intensive exchange of (maybe opposite)
  opinions. A panel may be 30-60 minutes long. We have introduced this
  interactive format for EuroPython 2017 due to the many requests we
  have received to make the conference more interactive and have more
  challenging / mind-bending content in place.  Please note if you
  suggest a panel you will have to organise the panelists and
  coordinate with the Program WG, panelist will require a ticket to
  the conference.

* Interactive

  This is a completely open 60-minute format. Feel free to make your
  suggestions. There are only two rules: it must be interactive,
  real-time human-to-human-interaction and of course compliant with
  the EuroPython Code of Conduct.

* Posters / 20 slots

  Posters are a graphical way to describe a project or a technology,
  printed in large formats; posters are exhibited at the conference,
  can be read at any time by participants, and can be discussed face
  to face with their authors during the poster session.

* Helpdesk / 6 slots

  Helpdesks are a great way to share your experience on a technology,
  by offering to help people answering their questions and solving
  their practical problems. You can run a helpdesk by yourself or with
  colleagues and friends. Each helpdesk will be open for 3 hours in
  total, 1.5 hours in the morning and 1.5 hours in the
  afternoon. People looking for help will sign up for a 30 minute slot
  and talk to you. There is no specific preparation needed; you just
  need to be proficient in the technology you run the helpdesk for.

* Lightning Talks

  A lightning talk (LT) is a short presenatation which must not be
  longer than five minute. LTs are not via the CfP but walk-in
  registations, see here.

Community Based Talk Voting
---

Attendees who have bought a ticket in time for the Talk Voting period
gain the right to vote for talks submitted during the Call For
Proposals.

The Program WG will also set aside a number of slots which they will
then select based on other criteria to e.g. increase diversity or give
a chance to less mainstream topics.

Conference Layout
-

Please note that the conference layout has changed in 2018, the main

EuroPython 2019: Launching our website

2019-04-25 Thread M.-A. Lemburg
We are happy to announce the launch of our website for EuroPython 2019:

  * https://ep2019.europython.eu/ *

Thanks to Artur, Patrick and our web WG, the website now comes with a
renovated layout, modern technology and new features.

At the same time, we are launching the CFP for the conference. We’ll
post details in a separate blog post.


Dates and Venues


EuroPython will be held from July 8-14 2019 in Basel, Switzerland, at
the Congress Center Basel (BCC) for the main conference days (Wed-Fri)
and the FHNW Muttenz for the workshops/trainings/sprints days
(Mon-Tue, Sat-Sun).

For more details, please have a look at our website and the FAQ:

https://ep2019.europython.eu/faq


Help spread the word


Please help us spread this message by sharing it on your social
networks as widely as possible. Thank you !

Link to the blog post:

https://blog.europython.eu/post/184430105792/europython-2019-launching-our-website

Tweet:

https://twitter.com/europython/status/1121307733519679489


Enjoy,
--
EuroPython 2019 Team
https://ep2019.europython.eu/
https://www.europython-society.org/

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to catch a usefull error message ?

2019-04-25 Thread Gregory Ewing

Vincent Vande Vyvre wrote:

But the "return 0" is a common case for an "Foo_init()"

see: 
https://docs.python.org/3.5//extending/newtypes.html#adding-data-and-methods-to-the-basic-example


Look carefully at the init function from that example:

static int
Noddy_init(Noddy *self, PyObject *args, PyObject *kwds)
{
PyObject *first=NULL, *last=NULL, *tmp;

static char *kwlist[] = {"first", "last", "number", NULL};

if (! PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist,
  &first, &last,
  &self->number))
return -1;
^

See that?

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list