Compare commits

..

No commits in common. "d7624ba08df0fd7b59714b7ffa1a1eada13a2f2e" and "f23de9941489db89a5844e0db113b836bb27f34d" have entirely different histories.

4 changed files with 26 additions and 54 deletions

View File

@ -3,11 +3,13 @@ repos:
hooks: hooks:
- id: linter - id: linter
name: linter name: linter
entry: hatch run lint entry: hatch run lint --no-fix
language: system language: system
types: [python] types: [python]
pass_filenames: false
- id: format - id: format
name: format name: format
entry: hatch run format --diff entry: hatch run format
language: system language: system
types: [python] types: [python]
pass_filenames: true

View File

@ -136,34 +136,13 @@ We follow [youtube-dl's policy](https://github.com/ytdl-org/youtube-dl#can-you-a
Most users do not need to build yt-dlp and can [download the builds](https://github.com/yt-dlp/yt-dlp/releases) or get them via [the other installation methods](README.md#installation). Most users do not need to build yt-dlp and can [download the builds](https://github.com/yt-dlp/yt-dlp/releases) or get them via [the other installation methods](README.md#installation).
To quickly run yt-dlp as a developer, you don't need to build anything either. Simply execute To run yt-dlp as a developer, you don't need to build anything either. Simply execute
```shell python -m yt_dlp
$ python -m yt_dlp
```
To properly interact with `yt-dlp` as a developer, you should use [`hatch`](<https://hatch.pypa.io>) (easily installed using [`pipx`](<https://pipx.pypa.io>)).
After installing, you can use `hatch shell` to create a shell with all dependencies as well as `yt-dlp` installed.
If you plan on contributing to `yt-dlp`, run
```shell
$ hatch run install
```
to prepare a full development environment and install `pre-commit`.
To run all the available core tests, use: To run all the available core tests, use:
```shell python devscripts/run_tests.py
$ hatch run tests core
```
You can also run tests for all installed python versions sequentially by setting the `TEST_ALL` variable, like so:
```shell
$ TEST_ALL=1 hatch run tests core
```
See item 6 of [new extractor tutorial](#adding-support-for-a-new-site) for how to run extractor specific test cases. See item 6 of [new extractor tutorial](#adding-support-for-a-new-site) for how to run extractor specific test cases.
@ -186,16 +165,12 @@ After you have ensured this site is distributing its content legally, you can fo
1. [Fork this repository](https://github.com/yt-dlp/yt-dlp/fork) 1. [Fork this repository](https://github.com/yt-dlp/yt-dlp/fork)
1. Check out the source code with: 1. Check out the source code with:
```shell git clone git@github.com:YOUR_GITHUB_USERNAME/yt-dlp.git
$ git clone git@github.com:YOUR_GITHUB_USERNAME/yt-dlp.git
```
1. Start a new git branch with 1. Start a new git branch with
```shell cd yt-dlp
$ cd yt-dlp git checkout -b yourextractor
$ git checkout -b yourextractor
```
1. Start with this simple template and save it to `yt_dlp/extractor/yourextractor.py`: 1. Start with this simple template and save it to `yt_dlp/extractor/yourextractor.py`:
@ -243,27 +218,20 @@ After you have ensured this site is distributing its content legally, you can fo
} }
``` ```
1. Add an import in [`yt_dlp/extractor/_extractors.py`](yt_dlp/extractor/_extractors.py). Note that the class name must end with `IE`. 1. Add an import in [`yt_dlp/extractor/_extractors.py`](yt_dlp/extractor/_extractors.py). Note that the class name must end with `IE`.
1. Run `hatch run tests YourExtractor`. This *may fail* at first, but you can continually re-run it until you're done. Upon failure, it will output the missing fields and/or correct values which you can copy. If you decide to add more than one test, the tests will then be named `YourExtractor`, `YourExtractor_1`, `YourExtractor_2`, etc. Note that tests with an `only_matching` key in the test's dict are not included in the count. You can also run all the tests in one go with `YourExtractor_all` 1. Run `python devscripts/run_tests.py YourExtractor`. This *may fail* at first, but you can continually re-run it until you're done. Upon failure, it will output the missing fields and/or correct values which you can copy. If you decide to add more than one test, the tests will then be named `YourExtractor`, `YourExtractor_1`, `YourExtractor_2`, etc. Note that tests with an `only_matching` key in the test's dict are not included in the count. You can also run all the tests in one go with `YourExtractor_all`
1. Make sure you have at least one test for your extractor. Even if all videos covered by the extractor are expected to be inaccessible for automated testing, tests should still be added with a `skip` parameter indicating why the particular test is disabled from running. 1. Make sure you have at least one test for your extractor. Even if all videos covered by the extractor are expected to be inaccessible for automated testing, tests should still be added with a `skip` parameter indicating why the particular test is disabled from running.
1. Have a look at [`yt_dlp/extractor/common.py`](yt_dlp/extractor/common.py) for possible helper methods and a [detailed description of what your extractor should and may return](yt_dlp/extractor/common.py#L119-L440). Add tests and code for as many as you want. 1. Have a look at [`yt_dlp/extractor/common.py`](yt_dlp/extractor/common.py) for possible helper methods and a [detailed description of what your extractor should and may return](yt_dlp/extractor/common.py#L119-L440). Add tests and code for as many as you want.
1. Make sure your code follows [yt-dlp coding conventions](#yt-dlp-coding-conventions), passes [ruff](https://docs.astral.sh/ruff/tutorial/#getting-started) code checks and is properly formatted: 1. Make sure your code follows [yt-dlp coding conventions](#yt-dlp-coding-conventions) and check the code with [ruff](https://docs.astral.sh/ruff/tutorial/#getting-started):
```shell $ ruff check yt_dlp/extractor/yourextractor.py
$ hatch run lint
$ hatch run format
```
You can use `hatch run lint --fix` to automatically fix problems.
1. Make sure your code works under all [Python](https://www.python.org/) versions supported by yt-dlp, namely CPython and PyPy for Python 3.8 and above. Backward compatibility is not required for even older versions of Python. 1. Make sure your code works under all [Python](https://www.python.org/) versions supported by yt-dlp, namely CPython and PyPy for Python 3.8 and above. Backward compatibility is not required for even older versions of Python.
1. When the tests pass, [add](https://git-scm.com/docs/git-add) the new files, [commit](https://git-scm.com/docs/git-commit) them and [push](https://git-scm.com/docs/git-push) the result, like this: 1. When the tests pass, [add](https://git-scm.com/docs/git-add) the new files, [commit](https://git-scm.com/docs/git-commit) them and [push](https://git-scm.com/docs/git-push) the result, like this:
```shell
$ git add yt_dlp/extractor/_extractors.py $ git add yt_dlp/extractor/_extractors.py
$ git add yt_dlp/extractor/yourextractor.py $ git add yt_dlp/extractor/yourextractor.py
$ git commit -m '[yourextractor] Add extractor' $ git commit -m '[yourextractor] Add extractor'
$ git push origin yourextractor $ git push origin yourextractor
```
1. Finally, [create a pull request](https://help.github.com/articles/creating-a-pull-request). We'll then review and merge it. 1. Finally, [create a pull request](https://help.github.com/articles/creating-a-pull-request). We'll then review and merge it.

View File

@ -29,12 +29,12 @@ def run_tests(*tests, pattern=None, ci=False):
arguments = ['pytest', '-Werror', '--tb=short'] arguments = ['pytest', '-Werror', '--tb=short']
if ci: if ci:
arguments.append('--color=yes') arguments.append('--color=yes')
if pattern:
arguments.extend(['-k', pattern])
if run_core: if run_core:
arguments.extend(['--ignore', 'test/test_download.py']) arguments.extend(['-m', 'not download'])
elif run_download: elif run_download:
arguments.extend(['test/test_download.py']) arguments.extend(['-m', 'download'])
elif pattern:
arguments.extend(['-k', pattern])
else: else:
arguments.extend( arguments.extend(
f'test/test_download.py::TestDownload::test_{test}' for test in tests) f'test/test_download.py::TestDownload::test_{test}' for test in tests)
@ -46,13 +46,13 @@ def run_tests(*tests, pattern=None, ci=False):
pass pass
arguments = [sys.executable, '-Werror', '-m', 'unittest'] arguments = [sys.executable, '-Werror', '-m', 'unittest']
if pattern:
arguments.extend(['-k', pattern])
if run_core: if run_core:
print('"pytest" needs to be installed to run core tests', file=sys.stderr, flush=True) print('"pytest" needs to be installed to run core tests', file=sys.stderr, flush=True)
return 1 return 1
elif run_download: elif run_download:
arguments.append('test.test_download') arguments.append('test.test_download')
elif pattern:
arguments.extend(['-k', pattern])
else: else:
arguments.extend( arguments.extend(
f'test.test_download.TestDownload.test_{test}' for test in tests) f'test.test_download.TestDownload.test_{test}' for test in tests)

View File

@ -88,8 +88,9 @@ dependencies = ["yt-dlp[dev]"]
[tool.hatch.envs.default.scripts] [tool.hatch.envs.default.scripts]
install = "pre-commit install" install = "pre-commit install"
lint = "ruff check {args:.}" lint = "ruff check {args:.}"
format = "autopep8 {args:--in-place .}" format = "autopep8 {args:.}"
tests = "python -m devscripts.run_tests {args}" tests = "python -m devscripts.run_tests {args}"
tests-core = "pytest -We --tb=short --ignore=test/test_download.py {args}"
[[tool.hatch.envs.default.overrides.env.TEST_ALL.matrix.value]] [[tool.hatch.envs.default.overrides.env.TEST_ALL.matrix.value]]
python = [ python = [
@ -172,6 +173,7 @@ relative-imports-order = "closest-to-furthest"
[tool.autopep8] [tool.autopep8]
max_line_length = 120 max_line_length = 120
in-place = true
recursive = true recursive = true
jobs = 0 jobs = 0