-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
general: switch from flat layout to src layout
this is long overdue and much friendlier to python tooling ecosystem should be backwards compatible with existing editable installs, with a warning to reinstall properly see #316
- Loading branch information
Showing
225 changed files
with
99 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
def run() -> None: | ||
# uses fixed paths; worth it for the sake of demonstration | ||
# assumes we're in /tmp/my_demo now | ||
# assumes we're in /tmp/my_demo now (set by the context manager in main) | ||
|
||
# 1. clone [email protected]:karlicoss/my.git | ||
copytree( | ||
|
@@ -44,15 +44,15 @@ def run() -> None: | |
|
||
# 4. point my.config to the Hypothesis data | ||
mycfg_root = abspath('my_repo') | ||
init_file = Path(mycfg_root) / 'my/config.py' | ||
init_file = Path(mycfg_root) / 'src/my/config.py' | ||
init_file.write_text(init_file.read_text().replace( | ||
'/path/to/hypothesis/data', | ||
hypothesis_backups, | ||
)) | ||
# | ||
|
||
# 4. now we can use it! | ||
os.chdir(my_repo) | ||
os.chdir('my_repo/src') | ||
|
||
check_call([python, '-c', ''' | ||
import my.hypothesis | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/my |
This file was deleted.
Oops, something went wrong.
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
""" | ||
Utils specific to hpi core, shouldn't really be used by HPI modules | ||
""" | ||
from __future__ import annotations | ||
|
||
|
||
def assert_subpackage(name: str) -> None: | ||
# can lead to some unexpected issues if you 'import cachew' which being in my/core directory.. so let's protect against it | ||
# NOTE: if we use overlay, name can be smth like my.origg.my.core.cachew ... | ||
assert name == '__main__' or 'my.core' in name, f'Expected module __name__ ({name}) to be __main__ or start with my.core' | ||
|
||
|
||
def _is_editable(package_name: str) -> bool: | ||
import importlib.metadata | ||
|
||
dist = importlib.metadata.distribution(package_name) | ||
dist_files = dist.files or [] | ||
for path in dist_files: | ||
if str(path).endswith('.pth'): | ||
return True | ||
return False | ||
|
||
|
||
def warn_if_not_using_src_layout(path: list[str]) -> None: | ||
contains_src = any('/src/my/' in p for p in path) | ||
if contains_src: | ||
return | ||
|
||
# __package__ won't work because it's gonna be 'my' rather than 'hpi' | ||
# seems like it's quite annoying to get distribition name from within the package, so easier to hardcode.. | ||
distribution_name = 'hpi' | ||
try: | ||
editable = _is_editable(distribution_name) | ||
except: | ||
# it would be annoying if this somehow fails during the very first HPI import... | ||
# so just make defensive | ||
return | ||
|
||
if not editable: | ||
# nothing to check | ||
return | ||
|
||
|
||
from . import warnings | ||
|
||
MSG = ''' | ||
Seems that your HPI is installed as editable and uses flat layout ( my/ directory next to .git folder). | ||
This was the case in older HPI versions (pre-20250123), but now src-layout is recommended ( src/my/ directory next to .git folder). | ||
Reinstall your HPI as editable again via 'pip install --editable /path/to/hpi'. | ||
See https://github.com/karlicoss/HPI/issues/316 for more info. | ||
''' | ||
|
||
warnings.high(MSG) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
from my.coding.commits import commits | ||
from my.core.cfg import tmp_config | ||
|
||
from .common import hpi_repo_root | ||
|
||
|
||
pytestmark = pytest.mark.skipif( | ||
os.name == 'nt', | ||
reason='TODO figure out how to install fd-find on Windows', | ||
|
@@ -29,14 +32,11 @@ def prepare(tmp_path: Path): | |
# - bare repos | ||
# - canonical name | ||
# - caching? | ||
hpi_repo_root = Path(__file__).absolute().parent.parent.parent | ||
assert (hpi_repo_root / '.git').exists(), hpi_repo_root | ||
|
||
class config: | ||
class commits: | ||
emails = {'[email protected]'} | ||
names = {'Dima'} | ||
roots = [hpi_repo_root] | ||
roots = [hpi_repo_root()] | ||
|
||
with tmp_config(modules='my.coding.commits', config=config): | ||
yield |
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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