1. Instructions:
- Installation (the syntax does not use the latest
Pythonversion, so it should be compatible with mostPython3versions above)
- Currently released to PyPI, install directly using
pip install auto_syspath3
git clone https://github.com/Alan3344/auto_syspath3.git
cd auto_syspath3
Python setup.py install
Or
pip install git+https://github.com/Alan3344/auto_syspath3.git
- Use
No need to add these two lines at the beginning of each document, because this will attract the annoying Flake8 squiggly line 〰️ prompt Flake8(E402)
- People with OCD say they are less willing to accept
import sys
sys.path.extend(['./', '../'])
from utils import login
from config import env
Now you only need to add this line directly in front of the custom package. If you don’t like the Flake8 prompt unused, you can add # noqa after it
Just reference it in front of the custom module
- According to the characteristics of
Pythonimported modules, this__init__.pyfile will be executed automatically, so there is no need to writeadd_path()function
import os
import auto_syspath3 # noqa
from utils import quit
from config import env
2. Refused Flake8 prompt detection: module level import not at top of file Flake8(E402)
- Reason: In order to make this file run independently, put
importinto the function
3. Reasons for writing this module:
I use VSCode to write Python code, but VSCode import is correctly prompted, but Flake8 prompts an error
Maybe using PyCharm will not have this problem, but he needs to be set to source root, I don't like this
- The original appearance of this function has to be copied every time it is referenced
- Secondly, this file is mainly placed in the
site-packagesdirectory. After packaging and sending it to others for use, this file will be missing - I found a similar package on
pypi, but it failed to meet my expectations, so I wrote one myself - The important thing is that after using this package, the customized package can be used in any terminal, no need to set
source root
def add_path(path=__file__, deep=0):
"""Add a path to the sys.path if it is not already there."""
paths = []
path = os.path.abspath(path)
dirname = os.path.dirname(path)
for i in range(deep):
dirname = os.path.dirname(dirname)
d(f'dirname: {dirname}')
for p in os.walk(dirname):
p0 = p[0].replace(dirname, '')
if p0.startswith('/.') or '__pycache__' in p0:
continue
elif not p[0] in sys.path:
paths.append(p[0])
sys.path.insert(0, p[0])
d(f'add path: {p[0]}')
return paths
Screenshot during use
-
Solve the error when the subpackage
pyfile imports the top-level module method:ModuleNotFoundError: No module named 'package name' -
Normally, our
pwdpaths are all in the top-level directory. At this time, we can directly run themain.pyfile. Of course, there is no problem if I runpython test_project/main.pydirectly.
-
If your project structure is like this, the
main.pyfile is the entry file,child_packageis the custom package, andchild_package/child_packageis the subpackage of the custom package, they all have specificpyfile -
Run directly in the entry file in the
main.pyfile like this -
This is how it works in the
child_package/call_user.pyfile. The first time the error is reported because the lineimport auto_syspath3 # noqa F401has been commented out -
This is how it works in the
child_package/child_package/call_user.pyfile. The first time the error is reported because the lineimport auto_syspath3 # noqa F401is commented out
Metadata
Release files for auto-syspath3 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| auto_syspath3-1.0.1.tar.gz | 7.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| auto_syspath3-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 kB
Release files / auto_syspath3-1.0.1.tar.gz
| Download URL | auto_syspath3-1.0.1.tar.gz |
|---|---|
| Size | 7.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6fae50cb8d19b797448253ae6429afc8af07dc4fc9fe2fcebc8de945a9b88407
|
|
BLAKE2b-256 checksum How to use checksums |
2a178879a9592160b0f983ea4c5849ea42d5465b2b4d4ab33b6f1081b40e7bc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / auto_syspath3-1.0.1-py3-none-any.whl
| Download URL | auto_syspath3-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d3dd7469b24c0088968a6b3b55348b95a401e53f6537eeae4389446bcd2abfd
|
|
BLAKE2b-256 checksum How to use checksums |
2e1ef5c6ddfea645e963c5cdef2733c1bd376c6bdfea260e4ace57eaee3cb709
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for auto-syspath3 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.