i have a package and in it i use pyproject.toml
and for proper typing i need stubs generated, although
its kinda annoying to generate them manually every time,
so, is there a way to do it automatically using it ?
i just want it to run stubgen and thats it, just so
mypy sees the stubs and its annoying seeing linters
throw warnings and you keep having to # type: ignore
heres what i have as of now, i rarely do this so its probably
not that good :
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
[project]
name = "<...>"
authors = [
{name = "<...>", email = "<...>"},
]
description = "<...>"
readme = "README"
requires-python = ">=3.10"
keywords = ["<...>"]
license = {text = "GNU General Public License v3 or later (GPLv3+)"}
classifiers = [
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
"Programming Language :: Python :: 3",
]
dependencies = [
"<...>",
]
dynamic = ["version"]
[tool.setuptools]
include-package-data = true
[tool.setuptools.package-data]
<...> = ["*.pyi"]
[tool.pyright]
pythonVersion = "3.10"
exclude = [
"venv",
"**/node_modules",
"**/__pycache__",
".git"
]
include = ["src", "scripts"]
venv = "venv"
stubPath = "src/stubs"
typeCheckingMode = "strict"
useLibraryCodeForTypes = true
reportMissingTypeStubs = true
[tool.mypy]
exclude = [
"^venv/.*",
"^node_modules/.*",
"^__pycache__/.*",
]
thanks for the answers in advance
just make a shellscript and add it to pyproject.toml as a script
:+1:
Related
I have the same problem as in the official documentation (https://www.sphinx-doc.org/en/master/usage/extensions/inheritance.html#examples):
My error is:
Here is a part of my conf.py:
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
'sphinx.ext.inheritance_diagram',
'sphinx.ext.graphviz'
# 'rst2pdf.pdfbuilder']
extensions.append('autoapi.extension')
autoapi_type = 'python'
autoapi_dirs = ['../pyqpanda']
autoapi_options = ['members', 'undoc-members', 'private-members',
'show-inheritance', 'show-module-summary',
'special-members', 'imported-members', 'show-inheritance-diagram']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['.templates']
inheritance_graph_attrs = dict(rankdir="TB", size='""')
I use centos. Sphinx 5.1.1, Graphviz 0.2.
How to solve this abnormal information display? How to show the inherit_diagram in api reference?
In setup.py I can put something like this:
import setuptools
setuptools.setup(
name = "my_project",
version = "1.2.3.4",
packages = [ "my_project" ],
entry_points = {
"console_scripts": [
"my_project = my_project.__main__:main" ] } )
To create an entry point/executable, my_project, that I can call from the console.
Is it possible to create these entry points manually, in a normal Python script, outside of setup.py?
(I'm interested in creating these the same way setup.py does, so not using system-specific hashbang scripts, etc.)
BUILD:
cc_proto_library(
name = "yd_fieldoptions_cc",
deps = [":yd_fieldoptions"],
)
py_proto_library(
name = "yd_fieldoptions_py",
deps = [":yd_fieldoptions"],
)
proto_library(
name = "yd_fieldoptions",
srcs = ["yd_fieldoptions.proto"],
deps = [
"#com_google_protobuf//:descriptor_proto",
],
)
Error
bazel build -s //field_options:yd_fieldoptions_py
BUILD:11:1: name 'py_proto_library' is not defined (did you mean 'cc_proto_library'?)
version:
Build label: 0.14.0- (#non-git)
protobuf verson: 3.5.0
You might be thinking of this rule: https://github.com/google/protobuf/blob/master/protobuf.bzl
In order to use it you have to load the bzl file in the BUILD file: https://docs.bazel.build/versions/master/skylark/concepts.html#loading-an-extension
The implementation of py_proto_library has some hacks related to it.
Some of the toolchain/library references are only valid inside the Protobuf repository. In order to use the rule py_proto_library, you have to manually bind those references in your own repository.
I have a very rough example that demonstrates how to bind some (but definitely not all) of those references in order to make py_proto_library work in your repository.
You can checkout the example here.
This is a very rough implementation, though it works, I don't have any idea whether this will work with a more complex scenario.
You have been warned.
However, if you really really want to make things work.
You can invoke the Protobuf compiler directly, then export the generate Python file to a py_library.
This is guaranteed to work, though this requires more code.
# This generates the Protobuf Python code using the protoc compiler
genrule(
name = "yd_fieldoptions_compiled_python",
srcs = ["yd_fieldoptions.proto"],
outs = ["yd_fieldoptions_pb2.py"],
cmd = "$(location #com_google_protobuf//:protoc) -I=proto --python_out=$(#D) $<",
tools = ["#com_google_protobuf//:protoc"],
)
# Setup a py_library target to be used by your code.
py_library(
name = "yd_fieldoptions_py",
srcs = [":yd_fieldoptions_compiled_python"],
deps = [
"#protobuf_python",
"#pypi_six//:six",
],
)
Also, you have to include the following info in your WORKSPACE file.
Those are used to download the necessary dependencies, you might have to change those URL as well as versions for Protobuf-Python according to your need.
new_http_archive(
name = "pypi_six",
url = "https://pypi.python.org/packages/16/d8/bc6316cf98419719bd59c91742194c111b6f2e85abac88e496adefaf7afe/six-1.11.0.tar.gz",
build_file_content = """
py_library(
name = "six",
srcs = ["six.py"],
visibility = ["//visibility:public"],
)
""",
strip_prefix = "six-1.11.0",
)
new_http_archive(
name = "protobuf_python",
url = "https://pypi.python.org/packages/14/03/ff5279abda7b46e9538bfb1411d42831b7e65c460d73831ed2445649bc02/protobuf-3.5.1.tar.gz",
build_file_content = """
py_library(
name = "protobuf_python",
srcs = glob(["google/protobuf/**/*.py"]),
visibility = ["//visibility:public"],
imports = [
"#pypi_six//:six",
],
)
""",
strip_prefix = "protobuf-3.5.1",
)
BTW, the code included above does not have gRPC plugin included.
If you are looking for a gRPC enabled Protobuf library, you have to include the gRPC repo, then include necessary the plugin in the corresponding rule.
I actually tried following this guide, but it did not work for me(I believe it's only for python 2 since I got a ton of errors and tried fixing them but it wasn't working still, I'm trying to do this for python 3)
set file permissions in setup.py file
So basically I have a folder in lets say
/usr/lib/python3.6/site_packages/XYZ
I want to give XYZ read & write permissions, since the current permissions only give root user write access. In my documentation I can require each user that installs my program through pip to chmod the directory themselves, but I'm looking for a more convenient way so no one has to do that.
Here's my setup.py incase anyone wants to see it
from distutils.core import setup
setup(
name = 'graphite-analytics',
packages = ['graphite'],
package_data={
'graphite' : ['graphite.py', 'capture.j3', 'templates/css/styles.css', 'templates/js/Chart.PieceLabel.js', 'templates/html/render.html', 'templates/fonts/Antro_Vectra.otf', 'templates/images/Calendar-icon.png'],
},
version = '0.1.2.13',
description = 'Create a print-out template for your google analytics data',
author = 'NAME REDACTED',
author_email = 'EMAIL REDACTED',
url = 'https://github.com/ARM-open/Graphite',
include_package_data=True,
zip_safe=True,
classifiers = [],
keywords = ['Google analytics', 'analytics', 'templates'],
install_requires=['Click', 'google-api-python-client', 'jinja2'],
entry_points={'console_scripts': [
'graphite-analytics = graphite.graphite:main'
]}
)
I'm trying to run Tensorflow code downloaded from github tensorflow/models/adversarial_text, but running into a bazel build error. The error looks quite straightforward. But as I haven't used bazel very much before, I'd appreciate any ideas/suggestions about it. The error is below:
ERROR: /home/dasgupta/adversarial_text/BUILD:60:1: no such package 'adversarial_text/data': BUILD file not found on package path and referenced by '//:inputs'.
Inside adversarial_text/BUILD:(line 60 - that gives above error) is the following rule:
py_library(
name = "inputs",
srcs = ["inputs.py"],
deps = [
# tensorflow dep,
"//adversarial_text/data:data_utils",
],
}
But I see that there is a directory called "adversarial_text/data" and inside adversarial_text/data/BUILD there's this rule too:
py_library(
name = "data_utils",
srcs = ["data_utils.py"],
deps = [
# tensorflow dep,
],
)
I tried adding
visibility = ["//adversarial_text:__pkg__"],
right after the deps rule for data_utils, but that didn't solve the problem.
Any ideas what I might be missing here, or what I might need to set/change (environment vars?) to get this to work.
My config: bash on Ubuntu 16.04, Tensorflow 1.2, bazel 0.5 and python 2.7
The visibility has to be //:__pkg__ since adversarial_text is the root of your workspace. And you should try building //:inputs.
So to summarize, this is what I did to make it work, after cloning the project.
1 Create "WORKSPACE" file in adversarial_text/
touch WORKSPACE
2 Edit deps in adversarial_text/BUILD
py_library(
name = "inputs",
srcs = ["inputs.py"],
deps = [
# tensorflow dep,
"//data:data_utils",
],
)
py_test(
name = "graphs_test",
size = "large",
srcs = ["graphs_test.py"],
deps = [
":graphs",
# tensorflow dep,
"//data:data_utils",
],
)
3 add visibility for data_utils in adversarial_text/data/BUILD
py_library(
name = "data_utils",
srcs = ["data_utils.py"],
deps = [
# tensorflow dep,
],
visibility = ["//:__pkg__"],
)
This should be fixed now, running the code no longer requires bazel as of https://github.com/tensorflow/models/pull/3414