Skip to main content

No project description provided

Project description

切换为中文

1. Instructions:

  1. Installation (the syntax does not use the latest Python version, so it should be compatible with most Python3 versions above)
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
  1. 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 Python imported modules, this __init__.py file will be executed automatically, so there is no need to write add_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 import into 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

  1. The original appearance of this function has to be copied every time it is referenced
  2. Secondly, this file is mainly placed in the site-packages directory. After packaging and sending it to others for use, this file will be missing
  3. I found a similar package on pypi, but it failed to meet my expectations, so I wrote one myself
  4. 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 py file imports the top-level module method: ModuleNotFoundError: No module named 'package name'

  • Normally, our pwd paths are all in the top-level directory. At this time, we can directly run the main.py file. Of course, there is no problem if I run python test_project/main.py directly.

  1. If your project structure is like this, the main.py file is the entry file, child_package is the custom package, and child_package/child_package is the subpackage of the custom package, they all have specific py file

  2. Run directly in the entry file in the main.py file like this

  3. This is how it works in the child_package/call_user.py file. The first time the error is reported because the line import auto_syspath3 # noqa F401 has been commented out

  4. This is how it works in the child_package/child_package/call_user.py file. The first time the error is reported because the line import auto_syspath3 # noqa F401 is commented out

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

auto_syspath3-1.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

auto_syspath3-1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file auto_syspath3-1.0.tar.gz.

File metadata

  • Download URL: auto_syspath3-1.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for auto_syspath3-1.0.tar.gz
Algorithm Hash digest
SHA256 11e7cc9e159176029f46038e45202454a7c4db2bad127f6d05ea228636de8276
MD5 ebf0176f80e91741121effc4bde73116
BLAKE2b-256 be087f9cae76472b88190056c3b476534e684854405f1e62e561574ed22ec2b8

See more details on using hashes here.

File details

Details for the file auto_syspath3-1.0-py3-none-any.whl.

File metadata

  • Download URL: auto_syspath3-1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for auto_syspath3-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00598b6e6420237726f43c563d46ec0aac0f69ccadb897745796ae4d606d0fc7
MD5 a91ae851c5cc487a1c7032399aea1e15
BLAKE2b-256 6faa295b4ceaad30412e4ec40280492157b5738386d38dc2ca9fe46646674a61

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page