mik-laj commented on a change in pull request #16860:
URL: https://github.com/apache/airflow/pull/16860#discussion_r665734044
##########
File path: airflow/models/dag.py
##########
@@ -734,15 +759,22 @@ def task_group(self) -> "TaskGroup":
@property
def filepath(self) -> str:
- """File location of where the dag object is instantiated"""
- fn = self.full_filepath.replace(settings.DAGS_FOLDER + '/', '')
- fn = fn.replace(os.path.dirname(__file__) + '/', '')
+ """:meta private:"""
+ warnings.warn(
+ "filepath is deprecated, use relative_fileloc instead",
DeprecationWarning, stacklevel=2
+ )
+ return self.relative_fileloc
+
+ @property
+ def relative_fileloc(self) -> str:
+ """File location of the importable dag 'file' relative to the
configured DAGs folder."""
+ fn = self.fileloc.replace(settings.DAGS_FOLDER + '/', '')
Review comment:
Now strange boundaries may appear when the user has a non-standard DAG
folder path e.g. `/dags/`. If the user then creates another `/dag/` folder in
this directory, they will get the wrong path
```
>>> '/dags/tomek/dags/'.replace('/dags/', '')
'tomek'
```
Do you consider to use
[os.path.relpath](https://docs.python.org/3/library/os.path.html#os.path.relpath)
instead?
```
>>> path.relpath('/dags/tomek/dags/', '/dags/')
'tomek/dags'
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]