如何将可执行文件与库文件分开?

发布于 2024-12-09 14:37:26 字数 766 浏览 0 评论 0原文

我仍然没有得到令我满意的答案。如果您有适合您的 Python 或 PHP 项目的良好系统,请务必提交一些答案。


我的 PHP 和 Python 项目遇到了管理问题。它们都有两种代码文件:应在控制台或 Web 浏览器中运行的文件,以及应从其他文件包含以扩展功能的文件。当我的项目成长为大型命名空间或模块树后,“可执行”文件和库文件在我的所有文件夹中并排放置且具有相同的文件扩展名,这开始变得令人迷惑。如果 PHP 和 Python 是预编译语言,那么这就是带有 main 函数的文件。

例如,图片我有命名空间 com.mycompany.map.address ,其中包含多个 .py 或 .php 文件,具体取决于项目。它将包含不同类型地址的模型以及大量用于处理地址的函数。但此外,它还包含一些从终端运行的可执行文件,提供用于搜索地址的用户工具,并可能在数据库等中添加和删除地址。

我想要一种方法将此类可执行文件与命名空间树中的大量代码文件区分开来,

如果这些文件具有单独的文件扩展名,那么这不会成为问题。但既然他们没有,我想我应该分开文件夹或其他东西,但我不知道如何命名它们。在 PHP 中,我可以执行配置 PHP 来解析不同文件扩展名的黑客解决方案,因此我的项目可以包含 phpsphpx 文件。

如果有人对如何处理这个问题有一些与语言无关的建议,我将不胜感激。这也适用于 C 等语言,其中一个项目可能编译成许多可执行文件。应该如何将包含 main 函数的源文件与其余文件分开?

I still haven't gotten an answer that I'm happy with. Please do submit some answers if you have a nice system for your Python or PHP projects.


I'm having a management issue with my PHP and Python projects. They both have two kinds of code files: files that should be run in the console or web browser, and files that should be included from other files to extend functionality. After my projects grow into large namespace or module trees, it starts getting disorienting that "executable" files and library files lay side by side with the same file extensions in all my folders. If PHP and Python were pre-compile languages, this would be the files with the main function.

For example, picture I have the namespace com.mycompany.map.address which contained multiple .py or .php files depending on the project. It would contain models for different kinds of addresses and tons of functions for working with addresses. But in addition, it would contain some executable files that runs from the terminal, providing a user tools for searching for addresses, and perhaps adding and removing addresses from a database or such.

I want a way of distinguish such executable files from the tons and tons of code files in my namespace trees

If the files had separate file extensions this wouldn't be a problem. But since they don't, I'm thinking I should separate folders or something, but I don't know what to name them. In PHP I could perform the hack solution of configuring PHP to parse different file extensions, so my project could contain phps or phpx files, for instance.

If anyone has some language-independent advice on how to handle this issue, I'd appreciate it. This could also apply to languages such as C, where one project might compile into many executable files. How should one separate the source files containing main functions from the rest of them?

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

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

发布评论

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

评论(2

她说她爱他 2024-12-16 14:37:26

以某种方式将它们分开(按名称、扩展名、位置)。

示例:

这是我们的测试自动化系统的布局(为了清晰起见,手动对输出进行排序):

$ ls -1 automation
atf               \ two major homebrew libraries, with many submodules
atflib            / 

atfconfig         configuration files in .py form
configuration     \ configuration files in .ini form
res_manager       /

test_scripts      - scripts to be invoked directly

然后我们将 automation 文件夹放入 PYTHONPATH 中,并可以导入 atf。< ;smth> 任何地方。
为了运行测试,我们更改为 test_scripts

Separate them somehow (by name, by extension, by location).

Example:

Here's the layout of our test automation system (output is manually sorted for clarity):

$ ls -1 automation
atf               \ two major homebrew libraries, with many submodules
atflib            / 

atfconfig         configuration files in .py form
configuration     \ configuration files in .ini form
res_manager       /

test_scripts      - scripts to be invoked directly

Then we place the automation folder into PYTHONPATH and can import atf.<smth> anywhere.
To run tests, we change into test_scripts.

银河中√捞星星 2024-12-16 14:37:26

对于我的 PHP 项目,我遵循非常 Java 风格的命名约定(我的背景):

index.php

/classes/{organization type: net, org, com}/{organization name}/{component}

/includes/ <-通用配置等;全部不可执行;

/lib/ <- 与特定版本相关的第三方库;未根据需要进行修改、修补/升级;

/modules/ <- 在项目分数中写入扩展的位置

For my PHP projects, I follow a very Java-esque naming convention (my background):

index.php

/classes/{organization type: net, org, com}/{organization name}/{component}

/includes/ <- general configuration, etc; all non-executable;

/lib/ <- third party libraries that are tied to specific releases; not modified, patched/upgraded as needed;

/modules/ <- place for extensions written within the score of the project

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