How can I make setup.py to include a class into packaging - setuptools

I'm using setup.py to package my project. the structure is like:
foo -
|
|--foo/
| |
| |--first.py
| |--second.py
| |--...
|--README
|--requirements.txt
|--scripts/
| |
| |-script1.sh
| |-script2.py
|--service.py
|--setup.py
If I run the current setup.py, which is in accordance with the suggestions here: What is setup.py?
then in the venv/lib/python3.6/site-packages/foo and venv/lib/python3.6/site-packages/scripts I can see all python classes there. But service.py is absent. My question is how to modify the setup.py to include service.py into packaging such that I can find service.py at venv/lib/python3.6/site-packages/?
Thanks in advance!

For top level modules, such as service.py, to be included in the distributions, setuptools offers the py_modules parameter.
The setuptools documentation does not show it clearly, but it is the same as in (now deprecated) distutils:
https://docs.python.org/3/distutils/setupscript.html#listing-individual-modules
setuptools.setup(
# ...
py_modules=['service'], # no '.py'
)

Related

Airflow duplicated plugin entries in virtualenv

Was setting up Airflow (2.1.4) in a virtual environment followed by an install of a third-party plugin "pip install simple-dag-editor"
Plugin installed successfully, however upon checking the plugin list, there were duplicated entries.
(venv) root#test-server:/opt/airflow$ airflow plugins
name | source | flask_blueprints | appbuilder_views
==================+============================================================+=======================================================+=============================================================
simple_dag_editor | simple-dag-editor==0.1.1: | <flask.blueprints.Blueprint object at 0x7f69e5e427b8> | {'category': 'Admin', 'name': 'Simple DAG editor', 'view':
| EntryPoint(name='simple_dag_editor', value='simple_dag_edi | | <simple_dag_editor.app_builder_view.AppBuilderDagEditorView
| tor.simple_dag_editor:SimpleDagEditor', | | object at 0x7f69e5dd1470>}
| group='airflow.plugins') | |
simple_dag_editor | simple-dag-editor==0.1.1: | <flask.blueprints.Blueprint object at 0x7f69e5e427b8> | {'category': 'Admin', 'name': 'Simple DAG editor', 'view':
| EntryPoint(name='simple_dag_editor', value='simple_dag_edi | | <simple_dag_editor.app_builder_view.AppBuilderDagEditorView
| tor.simple_dag_editor:SimpleDagEditor', | | object at 0x7f69e5dd1470>}
| group='airflow.plugins') | |
Airflow portal also resulted in 2 entries in the "Admin" section
Any idea what is happening? I tested the setup again both on a docker container and standalone on the server. Both instances did not result in the duplicated entries therefore I am suspecting it is related to running Airflow in a Python virtual environment. The server is running on CentOS 7.
I believe you might have plugin installed twice in two different places:
In "plugins" folder as simply a python package
Installed as python package
Aiflow Allows for both types of installations, and I think if you have both - it will install both.
If you change the airflow log level to verbose, you should be able to see two entries:
"Loading plugins from entrypoints"
"Loading plugins from directory: <DIRECTORY>"
They should be followed by attempts to import the plugins.
The solution would be to remove the plugings from the "plugins" directory.
It's also possible that you have two packages that have the same entrypoint - for example if you installed it with different package name before, it could also be discovered twice. Airflow checks all pacakges available and if they have appropriate entrypoint declared, it will load it as plugin. But if you enable DEBUG logging level, you should see details. You can easily set airflow logging level by config option (or environment variable):
https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#logging-level

VS Code Extension Settings CLI

I want to create an automated script for setting up VS Code.
Part of this is the installation of the extensions and configuring them as necessary.
So I was able to install the extensions via CLI, but can't find how to change the extension settings by only using the command line.
For example - I want to change Jest Runner settings. I found this on their readme:
Jest Runner will work out of the box, with a valid Jest config.
If you have a custom setup use the following options to configure Jest Runner:
| Command | Description |
| --- | --- |
| jestrunner.configPath | Jest config path (relative to ${workFolder} e.g. jest-config.json) |
| jestrunner.jestPath | Absolute path to jest bin file (e.g. /usr/lib/node_modules/jest/bin/jest.js) |
| jestrunner.debugOptions | Add or overwrite vscode debug configurations (only in debug mode) (e.g. `"jestrunner.debugOptions": { "args": ["--no-cache"] }`) |
| jestrunner.runOptions | Add CLI Options to the Jest Command (e.g. `"jestrunner.runOptions": ["--coverage", "--colors"]`) https://jestjs.io/docs/en/cli |
| jestrunner.jestCommand | Define an alternative Jest command (e.g. for Create React App and similar abstractions) |
| jestrunner.disableCodeLens | Disable CodeLens feature
| jestrunner.codeLensSelector | CodeLens will be shown on files matching this pattern (default **/*.{test,spec}.{js,jsx,ts,tsx})
But don't know how to access it via cmd.
Any thoughts on how to do this?
Thanks!
Was able to find a solution now.
So it turns out that the settings are actually stored in:
<userFolder>\AppData\Roaming\Code\User\Settings.json
From there I can open up the json file and add in the commands as specified by the extension's readme.

IntelliJ Scala: import works in test folder but not in main folder

I have an IntelliJ project in scala with the following directory structure (I've renamed files/directories for simplicity):
project
|
+--src
| |
| +--main
| | |
| | +--scala
| | |
| | +--'X'
| | |
| | +--'Y.scala'
| +--test
| |
| +--scala
| |
| +--'X'
| |
| +--'YSuite.scala'
|
+--build.sbt
The issue I'm having is that I'm able to import things in the YSuite.scala file that I'm not able to in YSuite.scala - specifically, the scala.collections.parallel packages. I just have no idea how or why I can import in the test file, but not in the parallel application file. I need them in the main file for implementation. Can someone point me in the right direction?
Screenshots are of the Y.scala file, YSuite.scala file, as well as the build.sbt file, if they help at all.
As can be seen, the red text indicates that I wasn't able to import it in Y.scala - when I hover over it with my mouse, it simply says cannot resolve symbol parallel. However, I've run the test file with some implementation of the parallel package, which runs with no problems.
Y.scala
YSuite.scala
build.sbt
a solution that seems to have worked for me:
step 1: File -> Invalidate Caches / Restart
step 2: build again/spin up sbt

Service Loader config file doesn't explode properly

So I am writing a webapp in Eclipse and I want to use the serviceloader in one of my classes. Question is where to put the META-INF/services stuff. From here (https://stackoverflow.com/a/3421191/2742995) I found:
But the ideal way is to have it in your plugin's jar file. E.g if you
have a plugin bundled as WEB-INF/lib/myplugin.jar, and your plugin
class is com.example.plugin.MyPlugin Then the jar should have a
structure:
myplugin.jar!/META-INF/services/com.example.plugin.MyPlugin
So I have in the module containing the serviceloader stuff, the source: src/main/java/ containing
vcs.validation.* (containing the source code)
a folder: META-INF/services/vcs.validation.javatests.JavaTest containing:
Test1 (which reads vcs.validation.javatests.Test1) and
Test2 (which reads vcs.validation.javatests.Test2)
(The interface vcs.validation.javatests.JavaTest has two implementing classes Test1 and Test2)
However, when I package the whole webapp as a war and deploy in tomcat the web-app/WEB-INF/classes/ folder does not contain any META-INF/services/. What am I doing wrong here?
Structure should be:
Project
| Module
| | src
| | main
| | java
| | [ source code]
| | resources
| | META-INF
| | services
| | [service files]
instead of:
Project
| Module
| | src
| | main
| | java
| | [source code]
| | META-INF
| | services
| | [service files]
In this way the service files are no longer exploded to webapp/WEB-INF/classes/META-INF/services but just live in the jar in which they are packaged according to:
myplugin.jar!/META-INF/services/com.example.plugin.MyPlugin

Emacs source code navigation features

I am working on a large c++ project. I am working with emacs for the last six months.
I have try to configure CEDET so as to be able to navigate easily but i have found some problems.
1.- Sometimes semantic does not find some symbols and sometimes he don't ... i do not know clearly which files is semantic indexing.
I have tried to use EDE (following the instructions in this paper http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html), but i have found some problems also...
I have multiple version ( Releases) of the same project, each one in its own folder. How can i tell emacs which project i am working with?
How can i tell ede where to look for my header files? Can I specify just a root directory and semantic will search for header files in all the subdirectories?
2.- I was working with vim+cscope some time ago and i remember there was a way to navigate back in the stack of symbols (Ctrl-t). Is there anything like this in emacs?
P.D.> Some data to make the question more clear.
I have multiple releases of the same project.
Each one has its own root directory.
Each project has multiple modules each one inside a subdirectory.
There are headers file in each module.
/home/user/
|
\Release-001
| |
| \makefile
| \ Module-001
| | |
| | \makefile
| | \subdir-001
| | | \header-001.h
| | | \header-002.h
| | \subdir-002
| | | \header-003.h
| \ Module-002
| | |
| | \makefile
| | \subdir-003
| | | \header-004.h
| | | \header-005.h
| | \subdir-004
| | | \header-006.h
|
\Release-002
| |
| \makefile
| \ Module-001
| | |
| | \makefile
| | \subdir-001
| | | \header-001.h
| | | \header-002.h
| | \subdir-002
| | | \header-003.h
| \ Module-002
| | |
| | \makefile
| | \subdir-003
| | | \header-004.h
| | | \header-005.h
| | \subdir-004
| | | \header-006.h
This is the configuration about EDE i have in my .emacs
;; Cedet load commands
(add-to-list 'load-path "~/emacs-dir/cedet/cedet")
(load-file "~/emacs-dir/cedet/cedet/common/cedet.el")
;; EDE: activating mode.
(global-ede-mode t)
;; Projects definition
(ede-cpp-root-project "Release-001"
:name "Release-001"
:file "~/Release-001/makefile"
:include-path '("/"
)
:system-include-path '("~/exp/include")
:spp-table '(("SUSE9" . "")
)
)
(ede-cpp-root-project "Release-002"
:name "Release-002"
:file "~/Release-002/makefile"
:include-path '("/"
)
:system-include-path '("~/exp/include")
:spp-table '(("SUSE9" . "")
)
)
Just to let you know ... I am working with the console version ( -nw) of emacs.
Your configuration is basically correct, except for the :include-path for your projects.
If a given source file says:
#include "Module-001/subdir-002/header-003.h"
then it is ok. If the include says:
#include "subdir-002/header-003.h"
then your :include-path should have
:include-path '("/Module-001" )
in it.
As for which things does semantic index, it will index your current file, and all includes it can find. Use the semantic-decoration mode to see which headers EDE has found for you to determine if your configuration is accurate.
It will also index all files in the same directory as the one you are editing, but only in idle time, so if you don't let Emacs be idle, it won't get around to it.
You can speed the indexing operations up if you use CScope as Bozhidar suggests. You can then enable the CScope support in both EDE and the Semantic database. The inclusion of CScope support in Semantic DB is recent, however, so you would need the CVS version of CEDET. That would make sure the whole thing was indexed.
To navigate backward, investigate the help for semantic-mru-bookmark-mode. This tracks your progress through your files on a named location basis that is quite handy and always works.
I had used in the past the Emacs Code Browser when working on C++ projects and I found it very satisfactory - in a addition to great files and code structure navigation you get excellent VCS integration(different icons according to current state of a file in the project). In conjunction with ECB I used cscope for Emacs, since you mentioned in for vim, you'll probably want to use it in Emacs as well.
Alternatively if you want a simpler solution you might have a look at Emacs Nav. It supports some fancy stuff as well and has no dependency to semantic and speedbar - you'll only have to use etags/ctags to index your project.