PEP 723 clues
#1162
Replies: 2 comments 1 reply
-
if you need to depend on external packages from pypi, you would want to use this pep-723-compliant syntax:
#!/usr/bin/env -S pipx run --path
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "requests", # example of external dependency
# ]
# ///
import requests
requests.get(...) but if your only dependency is this local spl package, you'll have a much easier time just telling python how to import it directly:
#!/usr/bin/env -S pipx run --path
import os
import sys
sys.path.append(os.path.dirname(__file__)) # tell python to import packages like spl from the folder that scripts.py live in
import spl
spl.do_stuff() then your project layout would simply be: scripts.py
spl/__init__.py
spl/module_one.py
spl/module_two.py ... and so on nice and simple :D |
Beta Was this translation helpful? Give feedback.
0 replies
-
as an addendum, using the following systax... #!/usr/bin/env -S pipx run --path
# /// script
# dependencies = ["mything @ ./mything"]
# /// ... would work, if scripts.py
mything/pyproject.toml
mything/src/mything/__init__.py
mything/src/mything/module_one.py
mything/src/mything/module_two.py |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have a fairly bizarre use case...
I have managed to set up my environment to exert PEP 723 support, following this test; I can put that script in a file, and get it to run using
pipx run test.py
.But I would like to create script which has a Python module in the same directory as a dependency.
I'm developing a set of tools to use as a dependency for scripts you create using PEP 723. So you would do:
However, the tool itself would have some of those scripts. This is an edge case, but I would like to get it working. I have tried variants like:
edit: I mean, instead of fetching
mything
from pypi, or to get it through git+https or whatever, I'd like to use themything
source which is just "right there" in.
.or
, but they are not working for me. Is there a way to get it to work?
New stuff:
OK, this is strange:
I guess this manifests the problem of using a flat layout instead of a src layout? But the installation error feels... like I'm getting closer?
Additional note:
In case anyone's wondering, this is what I'm doing https://github.com/alexpdp7/scripts-py-libs.
Cheers,
Álex
Beta Was this translation helpful? Give feedback.
All reactions