[GitHub] [airflow] kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the use of imp.load_source with another solution.

2020-01-10 Thread GitBox
kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the 
use of imp.load_source with another solution.
URL: https://github.com/apache/airflow/pull/7099#discussion_r365212566
 
 

 ##
 File path: airflow/models/dagbag.py
 ##
 @@ -248,7 +247,11 @@ def process_file(self, filepath, only_if_updated=True, 
safe_mode=True):
 
 with timeout(self.DAGBAG_IMPORT_TIMEOUT):
 try:
-m = imp.load_source(mod_name, filepath)
+loader = importlib.machinery.SourceFileLoader(mod_name, 
filepath)
+spec = importlib.util.spec_from_loader(mod_name, loader)
+m = importlib.util.module_from_spec(spec)
+sys.modules[spec.name] = m
 
 Review comment:
   You are right, thanks for pointing out that link.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the use of imp.load_source with another solution.

2020-01-09 Thread GitBox
kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the 
use of imp.load_source with another solution.
URL: https://github.com/apache/airflow/pull/7099#discussion_r364951020
 
 

 ##
 File path: airflow/models/dagbag.py
 ##
 @@ -248,7 +247,11 @@ def process_file(self, filepath, only_if_updated=True, 
safe_mode=True):
 
 with timeout(self.DAGBAG_IMPORT_TIMEOUT):
 try:
-m = imp.load_source(mod_name, filepath)
+loader = importlib.machinery.SourceFileLoader(mod_name, 
filepath)
+spec = importlib.util.spec_from_loader(mod_name, loader)
+m = importlib.util.module_from_spec(spec)
+sys.modules[spec.name] = m
 
 Review comment:
   We shouldn't be updating the sys.modules directly.
   
   I will fallback to what other committers think @potiuk @ashb : 


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the use of imp.load_source with another solution.

2020-01-08 Thread GitBox
kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the 
use of imp.load_source with another solution.
URL: https://github.com/apache/airflow/pull/7099#discussion_r364488560
 
 

 ##
 File path: airflow/models/dagbag.py
 ##
 @@ -248,7 +247,11 @@ def process_file(self, filepath, only_if_updated=True, 
safe_mode=True):
 
 with timeout(self.DAGBAG_IMPORT_TIMEOUT):
 try:
-m = imp.load_source(mod_name, filepath)
+loader = importlib.machinery.SourceFileLoader(mod_name, 
filepath)
+spec = importlib.util.spec_from_loader(mod_name, loader)
+m = importlib.util.module_from_spec(spec)
+sys.modules[spec.name] = m
 
 Review comment:
   Ok but you should not need "sys.modules[spec.name] = m"


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the use of imp.load_source with another solution.

2020-01-08 Thread GitBox
kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the 
use of imp.load_source with another solution.
URL: https://github.com/apache/airflow/pull/7099#discussion_r364446643
 
 

 ##
 File path: airflow/models/dagbag.py
 ##
 @@ -248,7 +247,11 @@ def process_file(self, filepath, only_if_updated=True, 
safe_mode=True):
 
 with timeout(self.DAGBAG_IMPORT_TIMEOUT):
 try:
-m = imp.load_source(mod_name, filepath)
+loader = importlib.machinery.SourceFileLoader(mod_name, 
filepath)
+spec = importlib.util.spec_from_loader(mod_name, loader)
+m = importlib.util.module_from_spec(spec)
+sys.modules[spec.name] = m
 
 Review comment:
   The following should also work:
   
   ```python
   spec = importlib.util.spec_from_file_location(module_name, module_path)
   module = importlib.util.module_from_spec(spec)
   spec.loader.exec_module(module
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the use of imp.load_source with another solution.

2020-01-08 Thread GitBox
kaxil commented on a change in pull request #7099: [AIRFLOW-6507] Replace the 
use of imp.load_source with another solution.
URL: https://github.com/apache/airflow/pull/7099#discussion_r364443683
 
 

 ##
 File path: airflow/models/dagbag.py
 ##
 @@ -248,7 +247,11 @@ def process_file(self, filepath, only_if_updated=True, 
safe_mode=True):
 
 with timeout(self.DAGBAG_IMPORT_TIMEOUT):
 try:
-m = imp.load_source(mod_name, filepath)
+loader = importlib.machinery.SourceFileLoader(mod_name, 
filepath)
+spec = importlib.util.spec_from_loader(mod_name, loader)
+m = importlib.util.module_from_spec(spec)
+sys.modules[spec.name] = m
 
 Review comment:
   We don't need this, do we?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services