I'm doing a small F# program where I am reading a markdown file, and store it as a string:
open System.IO
[<EntryPoint>]
let main argv =
let text = File.ReadAllText("/home/ask/RiderProjects/ConsoleApp1/ConsoleApp1/File.md")
printfn "%s" text
0
It works like it is here, where I provide the full path. But I need to use a relative path, since I need to put this on a server at some point.
My Program.fs and File.md is in the same directory, So i've tried all these paths, that have'nt worked.
- File.md
- /File.md
- ~/File.md
NOthing works. How do I provide the correct path?
I'm running ubuntu
EDIT
I accidentally wrote "txt" as the extension for some of my examples above. This is now corrected.
The directory that I am working in looks like this:
├── ConsoleApp1
│ ├── bin
│ ├── ConsoleApp1.fsproj
│ ├── File.md
│ ├── obj
│ └── Program.fs
└── ConsoleApp1.sln
Program.fs is the F# file, with my code in. File.md is the file I want to read
One of the more useful utilities is __SOURCE_DIRECTORY__ so you can reference things like files relative to the source file's directory. So just a simple Path.Join will get you the file.
let mdPath = Path.Join(__SOURCE_DIRECTORY__, "File.md")
Related
I have a complex config search path consisting of multiple locations where each location looks similar to this:
├── conf
│ └── foo
│ ├── foo.yaml
│ └── bar.yaml
└── files
├── foo.txt
└── bar.txt
with foo.yaml:
# #package _group_
path: "../../files/foo.txt"
and bar.yaml:
# #package _group_
path: "../../files/bar.txt"
Now the problem is: how do I find the correct location of the files specified in the configurations? I am aware of the to_absolute_path() method provided by hydra, but it interprets the path relative to the directory in which the application was started. However, I would like to interpret that path relative to the position of the configuration file. I cannot do this manually in my code, because I don't know how hydra resolved the configuration file and where exactly it is used to.
Is there some mechanism to determine the location of a config file from hydra? I really want to refrain from putting hard coded absolute paths in my configurations.
You can't get the path of a config file. In fact, it may not be a file at all (such as the case for Structured Configs), or it can be inside a python wheel (even in a zipped wheel).
You can do something like
path = os.path.join(os.path.dirname(__file__), "relative_path_from_config")
You can use also APIs designed for loading resources files from Python modules.
Here is a good answer in the topic.
I've an external dependency declared in WORKSPACE as a new_git_repository and provided a BUILD file for it.
proj/
├── BUILD
├── external
│ ├── BUILD.myDep
│ └── code.bzl
└── WORKSPACE
in the BUILD.myDep file, I want to load code.bzl nearby, but when I load it (load("//:external/code.bzl", "some_func")) bazel tries to load #myDep//:external/code.bzl instead!
Of course it's not a target in #myDep repository, but in my local worksapce.
Seems I Rubber Duck ed the Stackoverflow. since the solution appeared when writing the question!
However, the solution is to explicitly mention the local workspace when loading the .bzl file:
Suppose we have declared the name in the WORKSPACE as below:
workspace(name = "local_proj")
Now instead of load("//:external/code.bzl", "some_func"), just load it explicitly as a local workspace file:
load("#local_proj//:external/code.bzl", "some_func")
NOTE: When using this trick just be careful about potential dependency loops (i.e. loading a generated file that itself is produced by a rule depending on the same external repo!)
Problem Background :
I have made my own library in C++ with its respective .h and .cc files. They are organized in a small directory structure as shown :
.trillBPP
├── BPSK
│ ├── finddata.cc
│ ├── finddata.h
│ ├── trigger.cc
│ └── trigger.h
├── config.h
├── config_msvc.h
├── miscfunc.cc
├── miscfunc.h
└── vector
├── binary.cpp
├── binary.h
├── mat1.cpp
├── mat1.h
├── misc.cpp
├── misc.h
├── sort.h
├── vec.cpp
└── vec.h
The header files in C++ are included simply with a call like - #include <trillBPP/vector/vec.h> or #include <trillBPP/config.h> depending on the ,file name and directory.
Problem Statement :
I'm porting this C++ code and I'm trying to create a framework in Xcode but as it turns out, Xcode flattens the directory structure and gives an error for the header file calls, the error that it gives says trillBPP/vector/vec.h file not found.
This is how the project looks like :
I've tried adding the files as Folder References instead of groups, but then it won't even recognize the header-files as header files! In Header Search Paths in Build Settings, I've also added -I and /, with no success. I came across the answer Keeping directory structure when creating frameworks in xcode , but that didn't help out because of less details for me since I'm an Xcode newbie.
So, 1. Without changing the header file call how can I tell Xcode to keep the directory structure in the final framework, 2. and also keep the header file calls the same?
I have a web dir, which contains some css and js files:
├── bootstrap-wysiwyg
│ ├── index.html
│ ├── packages -> ../../packages
│ └── republish.sh
├── css
│ ├── bootstrap-combined.no-icons.min.css
│ ├── packages -> ../../packages
│ ├── prettify.css
│ └── screen.css
├── images
│ └── packages -> ../../packages
├── js
│ ├── bootstrap.min.js
│ ├── packages -> ../../packages
│ ├── prettify.js
│ └── prettify.js.1
├── lib
│ ├── font-awesome-3.2.1
│ └── packages -> ../../packages
└── packages -> ../packages
You can see there are one packages link in each subdir of the web dir. I deleted them once, but it will appear when I run pub install.
I can't understand why pub will create them for me, and is there any way to disable it? I don't want them because when I run build command in my IDEA Dart-plugin, it will reports errors since it can't handle them correctly.
When Dart sees an import like:
import 'package:foo/foo.dart';
It translates it to:
import '<url of your entrypoint>/packages/foo/foo.dart';
So, say your app's entrypoint is in:
myapp/web/app/main.dart
If it has a "package:" import, like above, it will remap it to:
import 'myapp/web/app/packages/foo/foo.dart';
That means that for Dart to be able to find foo.dart, there needs to be a packages directory inside app that contains foo/foo.dart. Part of pub's job is to set that up for you.
This is definitely not the nicest part of working with Dart and pub. Spewing symlinks everywhere is gross, but it deals with the limitations that the language places on us. Over time, we're hoping to move away from having to create these symlinks.
More details on this here.
When developing OpenLaszlo applications, it's sometimes useful to generate the ActionScript 3 source code of an application written in lzx, e.g. when you want to compile OpenLaszlo into an Adobe AIR application.
What is the simplest way to generate the ActionScript 3 source code into a predefined folder?
The lzc command line tool which can be found in the $LPS_HOME/WEB-INF/lps/server/bin/ has on option for that:
--lzxonly
for as3 runtime, emit intermediate as files,
but don't call backend as3 compiler
By default the OpenLaszlo compiler will generate the ActionScript 3 code into the system specific Java temp folder, but the $JAVA_OPTS environment variable can be used to change that folder.
Here's an example of how the command can be used in combination with $JAVA_OPTS on Linux:
a) Create a simple LZX file, e.g.
<canvas>
<button text="Hello world" />
</canvas>
and save it as test.lzx.
b) Set the $JAVA_OPTS variable
The following syntax is for Linux or OS X:
export JAVA_OPTS="-Djava.io.tmpdir=./tmp -DXmx1024M"
c) Compile the LZX into ActionScript 3
> lzc --lzxonly test.lzx --runtime=swf10
Compiling: test.lzx to test.swf10.swf
The tmp folder will contain the generated ActionScript 3 files
tmp
├── lzccache
└── lzswf9
└── build
└── test
├── app.swf
├── build.sh
├── LzApplication.as
├── $lzc$class_basebutton.as
├── $lzc$class_basecomponent.as
├── $lzc$class_basefocusview.as
├── $lzc$class_button.as
├── $lzc$class__componentmanager.as
├── $lzc$class_focusoverlay.as
├── $lzc$class__m2u.as
├── $lzc$class__m2v.as
├── $lzc$class__m2w.as
├── $lzc$class__m2x.as
├── $lzc$class__m2y.as
├── $lzc$class__m2z.as
├── $lzc$class__m30.as
├── $lzc$class__m31.as
├── $lzc$class__mm.as
├── $lzc$class__mn.as
├── $lzc$class__mo.as
├── $lzc$class__mp.as
├── $lzc$class_statictext.as
├── $lzc$class_style.as
├── $lzc$class_swatchview.as
├── LZC_COMPILER_OPTIONS
├── LzPreloader.as
└── LzSpriteApplication.as
The folder structure follows the following scheme:
{JAVA_TEMP_FOLDER}/lzswf9/build/{LZX_FILENAME_WITHOUT_ENDING}, therefore in our case
tmp/lzswf9/build/test/
The main applicaton file is LzSpriteApplication.as, and you can look into the build.sh file to get an idea how the Flex SDK's mxmlc command is used to compile the generated source code.