Created
October 5, 2025 13:16
-
-
Save KosarevDmitry/7fefcdfaa9a6bcd43ce5ff52a4f5e06b to your computer and use it in GitHub Desktop.
pyproject+venv usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mkdir baz | |
| cd baz | |
| # create confing file | |
| Set-Content -Path ".\pyproject.toml" -Value @" | |
| [project] | |
| name = "boo-package" | |
| version = "0.1" | |
| [build-system] | |
| requires = ["setuptools"] | |
| build-backend = "setuptools.build_meta" | |
| [options] | |
| package_dir = "src" | |
| # path by analogy with pip repo | |
| [project.scripts] | |
| mycli = "bip._internal.cli.main:main" | |
| "@ | |
| # main input | |
| Set-Content -Path ".\boo.py" -Value @" | |
| def say_hello(): | |
| print("Hello world!!!") | |
| "@ | |
| # make additional script | |
| New-Item -Path ".\src\bip\_internal\cli" -ItemType Directory | |
| New-Item -Path ".\src\__init__.py" -ItemType File -Force | |
| New-Item -Path ".\src\bip\__init__.py" -ItemType File -Force | |
| New-Item -Path ".\src\bip\_internal\__init__.py" -ItemType File -Force | |
| New-Item -Path ".\src\bip\_internal\cli\__init__.py" -ItemType File -Force | |
| # this script will be compiled in `\venv\Scripts\mycli.exe` | |
| Set-Content -Path ".\src\bip\_internal\cli\main.py" -Value @" | |
| def subfunc(x) -> None: | |
| print(x) | |
| # calls by bip._internal.cli.main:main | |
| def main() -> int: | |
| print(3) | |
| subfunc(4) | |
| return 0 | |
| "@ | |
| # create editable local package store | |
| py -m venv venv | |
| # include `\venv\Scripts\ in PATH | |
| .\venv\Scripts\Activate.ps1 | |
| # check if you want that `\venv\Scripts\ is included in PATH | |
| # (venv) is just marker | |
| $env:Path -split ';' | |
| # install src as package | |
| pip install -e . | |
| # to test that package works well | |
| Set-Content -Path ".\test.py" -Value @" | |
| import boo | |
| boo.say_hello() | |
| "@ | |
| py .\test.py | |
| # call \venv\Scripts\mycli.exe | |
| mycli | |
| Read-Host -Prompt "Press any key to continue..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment