Programming Is Not Software Engineering

编程序不是软件工程
It is one thing to develop a small program, such as the “Hello Essence” program; it is a different thing to develop a commercial product. It is true that some fantastic products such as those that gave birth to Apple, Microsoft, Facebook, Twitter, Google, and Spotify once were developed by one or a few individuals with a great vision but by just using programming as a skill. However, as
the great vision has been implemented, be sure that these companies are today not relying on heroic programmers. Today, these companies have hired the top people with long experience in software engineering including great programming skills. So, what is software engineering? Before we answer this question, we must first make it very clear that there is a remarkable difference between hacking versus professional programming. Professional programming involves clear logical thinking, beginning with the objective of the program, and refining the objective into logically constructed expressions. Indeed, the expressions are a reflection of
the programmers’ thinking and analysis. Hacking on the other hand is an ad hoc trial and error to induce the desired effect. When the effect is achieved, the hacker marvels without really understanding why it worked. Professional programmers understand why and how it worked.

As such, professional programming is highly disciplined. Software engineering takes this discipline to software teams working on complex software. A typical software development endeavor involves more than one person working on a complex problem over a period of time to meet some objectives. Throughout Smith’s introductory software engineering course, he worked on several assignments, which frequently required him to work with his fellow students, and which included tasks, such as :

1. brainstorming what an event calendar app would look like;
2. writing code for a simple event calendar in a small group;
3. writing code for the event calendar app, and hosting the app on the cloud;

# Ultralytics YOLO 🚀, AGPL-3.0 license import re from pathlib import Path from setuptools import setup # Settings FILE = Path(__file__).resolve() PARENT = FILE.parent # root directory README = (PARENT / 'README.md').read_text(encoding='utf-8') def get_version(): """ Retrieve the version number from the 'ultralytics/__init__.py' file. Returns: (str): The version number extracted from the '__version__' attribute in the 'ultralytics/__init__.py' file. """ file = PARENT / 'ultralytics/__init__.py' return re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', file.read_text(encoding='utf-8'), re.M)[1] def parse_requirements(file_path: Path): """ Parse a requirements.txt file, ignoring lines that start with '#' and any text after '#'. Args: file_path (str | Path): Path to the requirements.txt file. Returns: (List[str]): List of parsed requirements. """ requirements = [] for line in Path(file_path).read_text().splitlines(): line = line.strip() if line and not line.startswith('#'): requirements.append(line.split('#')[0].strip()) # ignore inline comments return requirements setup( name='ultralytics', # name of pypi package version=get_version(), # version of pypi package python_requires='>=3.8', license='AGPL-3.0', description=('Ultralytics YOLOv8 for SOTA object detection, multi-object tracking, instance segmentation, ' 'pose estimation and image classification.'), long_description=README, long_description_content_type='text/markdown', url='https://github.com/ultralytics/ultralytics', project_urls={ 'Bug Reports': 'https://github.com/ultralytics/ultralytics/issues', 'Funding': 'https://ultralytics.com', 'Source': 'https://github.com/ultralytics/ultralytics'}, author='Ultralytics', author_email='hello@ultralytics.com', packages=['ultralytics'] + [str(x) for x in Path('ultralytics').rglob('*/') if x.is_dir() and '__' not in str(x)], package_data={ '': ['*.yaml'], 'ultralytics.assets': ['*.jpg']}, include_package_data=True, install_requires=parse_requirements(PARENT / 'requirements.txt'), extras_require={ 'dev': [ 'ipython', 'check-manifest', 'pre-commit', 'pytest', 'pytest-cov', 'coverage', 'mkdocs-material', 'mkdocstrings[python]', 'mkdocs-redirects', # for 301 redirects 'mkdocs-ultralytics-plugin>=0.0.30', # for meta descriptions and images, dates and authors ], 'export': [ 'coremltools>=7.0', 'openvino-dev>=2023.0', 'tensorflow<=2.13.1', 'tensorflowjs', # automatically installs tensorflow ], }, classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'Intended Audience :: Education', 'Intended Audience :: Science/Research', 'License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Topic :: Software Development', 'Topic :: Scientific/Engineering', 'Topic :: Scientific/Engineering :: Artificial Intelligence', 'Topic :: Scientific/Engineering :: Image Recognition', 'Operating System :: POSIX :: Linux', 'Operating System :: MacOS', 'Operating System :: Microsoft :: Windows', ], keywords='machine-learning, deep-learning, vision, ML, DL, AI, YOLO, YOLOv3, YOLOv5, YOLOv8, HUB, Ultralytics', entry_points={'console_scripts': ['yolo = ultralytics.cfg:entrypoint', 'ultralytics = ultralytics.cfg:entrypoint']})
07-24
<think>我们正在查看一个setup.py文件,它是用于构建和分发Python包的标准脚本。 这个文件是Ultralytics YOLO项目的安装脚本,用于定义包的元数据、依赖和配置。 文件的主要部分包括: 1. 导入必要的模块(setuptools.setup, re, pathlib.Path等) 2. 读取README.md文件内容作为长描述 3. 定义get_version函数:从ultralytics/__init__.py中提取版本号 4. 定义parse_requirements函数:解析requirements.txt文件,忽略注释 5. 调用setup()函数,传入各种参数 下面我们将详细解释setup()函数中的各个参数及其作用。 注意:由于我们是在分析代码,而不是运行它,所以我们将重点放在代码结构和功能上。 由于代码较长,我们将分部分解释。</think>这个 `setup.py` 文件是用于构建和分发 Ultralytics YOLO 项目的 Python 包的核心配置文件。它使用 `setuptools` 来定义包的元数据、依赖关系和安装选项。下面我将详细解释关键部分: ### 核心功能解析 #### 1. 版本号提取 ```python def get_version(): file = PARENT / 'ultralytics/__init__.py' return re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', file.read_text(encoding='utf-8'), re.M)[1] ``` - 使用正则表达式从 `ultralytics/__init__.py` 中提取 `__version__` 变量值 - 确保包版本在单一位置维护(遵循 DRY 原则) #### 2. 依赖解析 ```python def parse_requirements(file_path: Path): requirements = [] for line in Path(file_path).read_text().splitlines(): line = line.strip() if line and not line.startswith('#'): requirements.append(line.split('#')[0].strip()) return requirements ``` - 解析 `requirements.txt` 文件 - 忽略注释行(以 `#` 开头)和行内注释 - 返回纯净的依赖列表 #### 3. 包配置主体 ```python setup( name='ultralytics', version=get_version(), python_requires='>=3.8', license='AGPL-3.0', # ...其他元数据... packages=['ultralytics'] + [str(x) for x in Path('ultralytics').rglob('*/') if x.is_dir() and '__' not in str(x)], package_data={'': ['*.yaml'], 'ultralytics.assets': ['*.jpg']}, install_requires=parse_requirements(PARENT / 'requirements.txt'), extras_require={ 'dev': [/* 开发依赖 */], 'export': [/* 模型导出依赖 */] }, entry_points={'console_scripts': [ 'yolo = ultralytics.cfg:entrypoint', 'ultralytics = ultralytics.cfg:entrypoint' ]} ) ``` ### 关键配置说明 | 配置项 | 作用 | 示例/说明 | |--------|------|-----------| | `packages` | 包含的子包 | 自动包含 `ultralytics` 下所有非特殊目录 | | `package_data` | 非代码资源文件 | 包含所有 YAML 配置和 JPG 示例图像 | | `install_requires` | 核心依赖 | 从 requirements.txt 解析 | | `extras_require` | 可选依赖组 | `dev`(开发工具), `export`(模型导出) | | `entry_points` | 命令行接口 | 创建 `yolo` 和 `ultralytics` 终端命令 | ### 最佳实践亮点 1. **动态版本管理**: ```python version=get_version() # 避免硬编码版本号 ``` 2. **智能包包含**: ```python [str(x) for x in Path('ultralytics').rglob('*/') if x.is_dir() and '__' not in str(x)] ``` 自动包含所有有效子目录,排除 `__pycache__` 等特殊目录 3. **模块化依赖管理**: ```python extras_require={ 'dev': [/* 开发工具 */], 'export': [/* ONNX/TensorRT 导出 */] } ``` 用户可按需安装:`pip install ultralytics[export]` 4. **资源文件包含**: ```python package_data={'': ['*.yaml'], 'ultralytics.assets': ['*.jpg']} ``` 确保模型配置文件和示例图像包含在分发包中 5. **统一入口点**: ```python entry_points={'console_scripts': [ 'yolo = ultralytics.cfg:entrypoint' ]} ``` 创建用户友好的命令行接口 ### 典型安装场景 1. **基础安装**: ```bash pip install ultralytics ``` 2. **带导出功能的安装**: ```bash pip install ultralytics[export] ``` 3. **开发模式安装**: ```bash git clone https://github.com/ultralytics/ultralytics cd ultralytics pip install -e .[dev] # 可编辑模式安装 ``` 这个 `setup.py` 文件展示了专业 Python 包的配置实践,包括动态元数据管理、智能文件包含、分层依赖管理和命令行集成。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值