Skip to content

Commit

Permalink
Merge pull request #511 from girardinsamuel/fix/510
Browse files Browse the repository at this point in the history
Fix using PackageProvider without installing package locally
  • Loading branch information
josephmancuso committed Jan 23, 2022
2 parents daf08b9 + 3d4e290 commit 66edeec
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/masonite/packages/providers/PackageProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ...utils.time import migration_timestamp
from ...routes import Route
from ...utils.structures import load
from ...utils.str import modularize
from ...utils.filesystem import make_directory

from ..reserved_names import PACKAGE_RESERVED_NAMES
Expand Down Expand Up @@ -59,9 +60,20 @@ def publish(self, resources, dry=False):
return published_resources

def root(self, relative_dir):
module = load(relative_dir)
self.package.module_root = relative_dir
self.package.abs_root = dirname(module.__file__)
"""Define python package module root path and absolute package root path.
It works when installing the package locally with: pip install . or pip install -e .
and when installing the package from production release with: pip install package-name
"""
# load module provider
provider_module = load(self.__module__)
# get relative module path to package root
relative_module_path = modularize(relative_dir)
self.package.module_root = self.__module__[
0 : self.__module__.find(relative_module_path) + len(relative_module_path)
]
self.package.abs_root = provider_module.__file__[
0 : provider_module.__file__.find(relative_dir) + len(relative_dir)
]
return self

def name(self, name):
Expand Down

0 comments on commit 66edeec

Please sign in to comment.