This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #710 from robotpy/misc
Misc
- Loading branch information
Showing
6 changed files
with
89 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
--- | ||
|
||
functions: | ||
GetLaunchDirectory: | ||
GetOperatingDirectory: | ||
GetDeployDirectory: | ||
GetOperatingDirectoryFs: | ||
ignore: true | ||
GetDeployDirectoryFs: | ||
ignore: true |
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
#pragma once | ||
|
||
#include <wpi/fs.h> | ||
|
||
namespace robotpy::filesystem { | ||
|
||
/** | ||
* Obtains the operating directory of the program. On the roboRIO, this | ||
* is /home/lvuser/py. In simulation, it is the location of robot.py | ||
* | ||
* @return The result of the operating directory lookup. | ||
*/ | ||
std::string GetOperatingDirectory(); | ||
|
||
/** | ||
* Obtains the deploy directory of the program, which is the remote location | ||
* the deploy directory is deployed to by default. On the roboRIO, this is | ||
* /home/lvuser/py/deploy. In simulation, it is where the simulation was launched | ||
* from, in the subdirectory "deploy" (`dirname(robot.py)`/deploy). | ||
* | ||
* @return The result of the operating directory lookup | ||
*/ | ||
std::string GetDeployDirectory(); | ||
|
||
// intended to be used by C++ bindings, returns same as GetOperatingDirectory | ||
fs::path GetOperatingDirectoryFs(); | ||
// intended to be used by C++ bindings, returns same as GetDeployDirectory | ||
fs::path GetDeployDirectoryFs(); | ||
|
||
} // namespace robotpy::filesystem | ||
|
||
#include "Filesystem.inc" |
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,45 @@ | ||
|
||
// TODO: this should be in a shared library, but robotpy-build does not support that | ||
|
||
#include <pybind11/eval.h> | ||
#include <robotpy_build.h> | ||
|
||
namespace robotpy::filesystem { | ||
|
||
static fs::path getMainPath() { | ||
py::gil_scoped_acquire gil; | ||
py::dict locals; | ||
py::exec(R"( | ||
import sys, os.path | ||
main = sys.modules['__main__']; | ||
if hasattr(main, '__file__'): | ||
main_path = os.path.abspath(os.path.dirname(main.__file__)) | ||
)", | ||
py::globals(), locals); | ||
|
||
if (locals.contains("main_path")) { | ||
return fs::path(py::cast<std::string>(locals["main_path"])); | ||
} else { | ||
#ifdef __FRC_ROBORIO__ | ||
return fs::path("/home/lvuser/py"); | ||
#else | ||
return fs::current_path(); | ||
#endif | ||
} | ||
} | ||
|
||
inline std::string GetOperatingDirectory() { | ||
return GetOperatingDirectoryFs().string(); | ||
} | ||
|
||
inline std::string GetDeployDirectory() { return GetDeployDirectoryFs().string(); } | ||
|
||
inline fs::path GetOperatingDirectoryFs() { | ||
static fs::path operatingPath = getMainPath(); | ||
return operatingPath; | ||
} | ||
|
||
inline fs::path GetDeployDirectoryFs() { return GetOperatingDirectoryFs() / "deploy"; } | ||
|
||
} // namespace robotpy::filesystem |