多语言库的 python 位的文件布局和 setuptools 配置

发布于 2024-09-02 18:54:33 字数 1408 浏览 4 评论 0 原文

因此,我们正在编写一个全文搜索框架 MongoDb。 MongoDB 几乎是 javascript 原生的,所以我们首先编写了 javascript 库,并且它可以工作。

现在我正在尝试为其编写一个 python 框架,该框架部分使用 python,但部分使用那些相同的存储的 javascript 函数 - javascript 函数是库的固有部分。另一方面,javascript框架不依赖于python。由于它们非常交织在一起,因此将它们保存在同一个存储库中似乎是值得的。

我正在尝试找出一种构建整个项目的方法,以赋予 javascript 和 python 框架同等的地位(也许是 ruby​​ 驱动程序或将来的其他东西?),但仍然允许 python 库很好地安装。

目前它看起来像这样:(稍微简化)

javascript/jstest/test1.js
javascript/mongo-fulltext/search.js
javascript/mongo-fulltext/util.js
python/docs/indext.rst
python/tests/search_test.py
python/tests/__init__.py
python/mongofulltextsearch/__init__.py
python/mongofulltextsearch/mongo_search.py
python/mongofulltextsearch/util.py
python/setup.py

为了简单起见,我跳过了一些文件,但您已经了解了总体思路;它是一个非常标准的 python 项目...除了它严重依赖于存储在同级目录树中的一大堆 javascript 之外。

当涉及到安装工具时,处理此类事情的首选设置是什么?我可以弄清楚如何使用 package_data 等来安装我的 python 项目中的数据文件根据 setuptools 文档

问题是,如果我想使用 setuptools 来安装东西,包括来自 python 代码树外部的 javascript 文件,然后在开发 python 代码时以及在 easy_install< 时以一致的方式访问它们/code> 访问某人的网站。

这是 setuptools 支持的行为吗?我应该使用 paver 或 distutils2 或 Distribute 或其他东西吗? (基本的 distutils 不是一个选项;我这样做的全部原因是为了启用需求跟踪)我应该如何将这些文件的内容读入 python 脚本?

So we're writing a full-text search framework MongoDb. MongoDB is pretty much javascript-native, so we wrote the javascript library first, and it works.

Now I'm trying to write a python framework for it, which will be partially in python, but partially use those same stored javascript functions - the javascript functions are an intrinsic part of the library. On the other hand, the javascript framework does not depend on python. since they are pretty intertwined it seems like it's worthwhile keeping them in the same repository.

I'm trying to work out a way of structuring the whole project to give the javascript and python frameworks equal status (maybe a ruby driver or whatever in the future?), but still allow the python library to install nicely.

Currently it looks like this: (simplified a little)

javascript/jstest/test1.js
javascript/mongo-fulltext/search.js
javascript/mongo-fulltext/util.js
python/docs/indext.rst
python/tests/search_test.py
python/tests/__init__.py
python/mongofulltextsearch/__init__.py
python/mongofulltextsearch/mongo_search.py
python/mongofulltextsearch/util.py
python/setup.py

I've skipped out a few files for simplicity, but you get the general idea; it' a pretty much standard python project... except that it depends critcally ona whole bunch of javascript which is stored in a sibling directory tree.

What's the preferred setup for dealing with this kind of thing when it comes to setuptools? I can work out how to use package_data etc to install data files that live inside my python project as per the setuptools docs.

The problem is if i want to use setuptools to install stuff, including the javascript files from outside the python code tree, and then also access them in a consistent way when I'm developing the python code and when it is easy_installed to someone's site.

Is that supported behaviour for setuptools? Should i be using paver or distutils2 or Distribute or something? (basic distutils is not an option; the whole reason I'm doing this is to enable requirements tracking) How should i be reading the contents of those files into python scripts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从此见与不见 2024-09-09 18:54:33

简而言之,没有任何 Python 分发工具能够按照您想要的方式执行您想要的操作。即使您使用 distutils 的 data_files 功能,您仍然需要将 javascript 文件复制到您的 Python 项目目录中(即,与 setup.py 位于同一目录下的某个位置。)

鉴于此,您不妨只作为构建过程的一部分,将 .js 文件复制到您的包中(即与 mongofulltextsearch/init.py 一起),并使用 package_data 或 include_package_data=True。

(或者,您可以使用符号链接、外部文件或类似的东西,如果您的版本控制系统支持这些。我相信在构建源代码发行版时,Python 发行版工具会将符号链接转换为真实文件。至少,您可以给它一个尝试。)

The short answer is that none of the Python distribution tools is going to do what you want, the exact way you want it. Even if you use distutils' data_files feature, you're still going to have to have your javascript files copied into your Python project directory (i.e., somewhere under the same directory as your setup.py.)

Given that, you might as well just copy the .js files to your package (i.e. alongside mongofulltextsearch/init.py) as part of your build process, and use package_data or include_package_data=True.

(Or alternatively, you could possibly use symlinks, externals, or some such, if your revision control system supports those. I believe that when building source distributions, the Python distribution tools convert symlinks to real files. At least, you could give that a try.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文