Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import from custom _utils #52136

Closed
kiemlicz opened this issue Mar 11, 2019 · 12 comments
Closed

Import from custom _utils #52136

kiemlicz opened this issue Mar 11, 2019 · 12 comments
Assignees
Labels
Bug Confirmed ZRelease-Sodium
Projects
Milestone

Comments

@kiemlicz
Copy link
Contributor

@kiemlicz kiemlicz commented Mar 11, 2019

Description of Issue/Question

Is it possible to import custom utilities via python imports?
The doc https://docs.saltstack.com/en/latest/topics/utils/index.html suggests so but I couldn't get it working.

Setup

Follow Foo class example from:
https://docs.saltstack.com/en/latest/topics/utils/index.html

Steps to Reproduce Issue

In any custom execution module, e.g.,: _modules/customModule.py it is not possible to write:
import mymodule (given I've named the Foo class file mymodule.py)
It always fails with No module named 'mymodule'
Of course __utils__['mymodule.foo']() syntax works, the question is about import

Could you please clarify if the doc is wrong?

Versions Report

Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: 1.12.2
       cherrypy: unknown
       dateutil: 2.8.0
      docker-py: 1.10.6
          gitdb: 2.0.0
      gitpython: 2.1.1
          ioflo: Not Installed
         Jinja2: 2.10
        libgit2: 0.27.4
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.8
   mysql-python: Not Installed
      pycparser: 2.19
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.27.4
         Python: 3.5.3 (default, Sep 27 2018, 17:25:39)
   python-gnupg: Not Installed
         PyYAML: 3.13
          PyZMQ: 16.0.2
           RAET: Not Installed
          smmap: 2.0.1
        timelib: Not Installed
        Tornado: 4.4.3
            ZMQ: 4.2.1

System Versions:
           dist: debian 9.8
         locale: ANSI_X3.4-1968
        machine: x86_64
        release: 4.9.0-7-amd64
         system: Linux
        version: debian 9.8
@Ch3LL
Copy link
Contributor

@Ch3LL Ch3LL commented Mar 11, 2019

i thought you had to use __utils__ because thats how we pack it in when we load minion_mods, but maybe someone on the @saltstack/team-core can correct me? Looks like that doc example makes it seem like you can import utils, but i thought we always wanted to use __utils__?

@Ch3LL Ch3LL added the Pending-Discussion label Mar 11, 2019
@Ch3LL Ch3LL added this to the Blocked milestone Mar 11, 2019
@UtahDave
Copy link
Member

@UtahDave UtahDave commented Jul 1, 2019

@Ch3LL There are a lot of place where we're importing from Salt utils.

[boucha@flaco salt (develop u=)]$ grep -rn 'import salt.utils' * | wc -l
2711

I'm running into this problem when I'm trying to use an execution module from develop in 2019.2. The execution module needs a utils module. I put the execution module in _modules and the utils module in _utils and run saltutil.sync_all. Everything syncs fine, but it's not possible to import the utils function.

Should we go through and replace all 2711 instances where we're importing directly from salt.utils and use __utils__?

@UtahDave
Copy link
Member

@UtahDave UtahDave commented Jul 1, 2019

looks like @max-arnold has a fix in #53167

@waynew
Copy link
Contributor

@waynew waynew commented Jul 24, 2019

@kiemlicz does the fix in #53167 work for you?

@kiemlicz
Copy link
Contributor Author

@kiemlicz kiemlicz commented Aug 16, 2019

I think yes!
I'm waiting for merge then

@stale
Copy link

@stale stale bot commented Jan 8, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Jan 8, 2020
@kiemlicz
Copy link
Contributor Author

@kiemlicz kiemlicz commented Jan 8, 2020

not yet stale

@stale
Copy link

@stale stale bot commented Jan 8, 2020

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Jan 8, 2020
@stale
Copy link

@stale stale bot commented Feb 7, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

@stale stale bot added the stale label Feb 7, 2020
@kiemlicz
Copy link
Contributor Author

@kiemlicz kiemlicz commented Feb 7, 2020

not yet

@stale
Copy link

@stale stale bot commented Feb 7, 2020

Thank you for updating this issue. It is no longer marked as stale.

@stale stale bot removed the stale label Feb 7, 2020
@waynew waynew added Confirmed fixed-pls-verify and removed Pending-Discussion labels Feb 7, 2020
@sagetherage sagetherage removed this from the Blocked milestone Mar 26, 2020
@sagetherage sagetherage added this to the Approved milestone Mar 26, 2020
@sagetherage sagetherage added Bug ZRelease-Sodium and removed fixed-pls-verify labels Mar 26, 2020
@sagetherage sagetherage added this to Commit in Sodium Mar 26, 2020
@sagetherage sagetherage moved this from Commit to In progress in Sodium Mar 26, 2020
@sagetherage sagetherage moved this from In progress to Done in Sodium May 23, 2020
@sagetherage
Copy link
Collaborator

@sagetherage sagetherage commented May 23, 2020

will be released in sodium - closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Confirmed ZRelease-Sodium
Projects
No open projects
Sodium
  
Done
Development

No branches or pull requests

5 participants