How can I use a module as a stand-alone CLI and also as a submodule for another module (API)?

James T.

I'd like to figure out how to have a module act independently (as CLI) and as a submodule for another module (as API).

Minimal example: http://www.filedropper.com/submoduleconfusion-master


For file structure:

  • SubmoduleConfusion/
    • mod_a/
      • mod_a.py

Suppose there's some function that's located in SubmoduleConfusion.mod_a.mod_a then I'd use from mod_a.mod_a import f


Since mod_a can also be run as it's own independent module,

For file structure:

  • mod_a/
    • mod_a.py

from mod_a import f

James T.

The best thing to do is to make the module pip installable (add setup.py outside 1 step up from module path) with an entry point for a console script.

https://github.com/jtara1/misc_scripts/tree/master/misc_scripts/templates

I use this template setup.py and setup.cfg in most of my module I've created. It uses setuptools_scm which will use the version (tag) from git for the project to define the version within the setup.py.

In other words, you need to git tag 0.1.0 and git push --tags before trying to install the module or upload it to be installed.

My setup.py will also infer the name of the module is the same name as the parent directory (github project name)

so the directory should look something like this

my_module

  • images
  • my_module
    • __main__.py
  • setup.py
  • setup.cfg
  • README.md

name of alias currently defined within setup function within setup.py , might move it to variable later

https://github.com/jtara1/misc_scripts/blob/master/misc_scripts/templates/setup.py#L113

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I use a controller of one module in another module?

From Dev

can I develop a node module as GIT submodule

From Dev

Get module of a function (defined stand-alone)

From Dev

How Can I "Inherit" a Ruby Module to Create Another Module?

From Dev

How can I load a module into another module using Elixir language?

From Dev

How can I use a CommonJS module on JSFiddle?

From Dev

How can I use the "http" module in koa?

From Dev

How to use callModule from within another module? (Can I use the same id?)

From Dev

How module can use resources of another module using gradle multi-module

From Java

How to use a module that is outside of "GOPATH" in another module?

From Dev

AngularJS: can I use filter, defined in another module?

From Dev

In Typescript, how can I use functions defined in another TS file without puting them in a module?

From Dev

How To Require Module of a Node Submodule

From Dev

How To Require Module of a Node Submodule

From Dev

how i can use submodule gitlab in this stracture

From Dev

How can I get a test resource from another module

From Dev

how can i import class from another module maven

From Dev

how can i import class from another module maven

From Dev

How to solve "ImportError: No module named dis3" when making stand-alone executable file from python script

From Dev

How do i use a file on FTP in a stand alone spark cluster (pySpark)?

From Dev

How can I debug stand alone JavaScript files in Visual Studio Community 2015?

From Dev

How can i pass value from one angular module another Module?

From Dev

How can I use a custom module inside a doctest?

From Dev

How can I use an Ada module in a Perl program using XS?

From Dev

How can I use module Control.Monad.Free in Haskell?

From Dev

How can I use class instance variables in an extended module in Ruby?

From Dev

Can we use Data Access Layer in stand alone application?

From Dev

How can I target a module?

From Dev

How can I simplify this module?

Related Related

  1. 1

    How can I use a controller of one module in another module?

  2. 2

    can I develop a node module as GIT submodule

  3. 3

    Get module of a function (defined stand-alone)

  4. 4

    How Can I "Inherit" a Ruby Module to Create Another Module?

  5. 5

    How can I load a module into another module using Elixir language?

  6. 6

    How can I use a CommonJS module on JSFiddle?

  7. 7

    How can I use the "http" module in koa?

  8. 8

    How to use callModule from within another module? (Can I use the same id?)

  9. 9

    How module can use resources of another module using gradle multi-module

  10. 10

    How to use a module that is outside of "GOPATH" in another module?

  11. 11

    AngularJS: can I use filter, defined in another module?

  12. 12

    In Typescript, how can I use functions defined in another TS file without puting them in a module?

  13. 13

    How To Require Module of a Node Submodule

  14. 14

    How To Require Module of a Node Submodule

  15. 15

    how i can use submodule gitlab in this stracture

  16. 16

    How can I get a test resource from another module

  17. 17

    how can i import class from another module maven

  18. 18

    how can i import class from another module maven

  19. 19

    How to solve "ImportError: No module named dis3" when making stand-alone executable file from python script

  20. 20

    How do i use a file on FTP in a stand alone spark cluster (pySpark)?

  21. 21

    How can I debug stand alone JavaScript files in Visual Studio Community 2015?

  22. 22

    How can i pass value from one angular module another Module?

  23. 23

    How can I use a custom module inside a doctest?

  24. 24

    How can I use an Ada module in a Perl program using XS?

  25. 25

    How can I use module Control.Monad.Free in Haskell?

  26. 26

    How can I use class instance variables in an extended module in Ruby?

  27. 27

    Can we use Data Access Layer in stand alone application?

  28. 28

    How can I target a module?

  29. 29

    How can I simplify this module?

HotTag

Archive