Is there a way to include a C library in a Swift project without creating a git repository? That seems to be the only way explained on the Package manager documentation. Starting a git repo just to include some C headers that are already on my computer seems unwieldy.
I tried using a module.map file in a module, just like for any pure Swift module, and the C module imports fine, but contains no symbols.
This is what my project looks like:
Project
├── Package.swift
└── Sources
├── Project
│ └── main.swift
├── The_C_module_i_want
│ ├── module.modulemap
│ └── Package.swift (empty, else it won’t compile)
└── Some_Swift_module
└── taylor.swift
The top level Package.swift looks like
import PackageDescription
let package = Package(name: "Project",
targets : [
Target(name: "Project",
dependencies: ["Some_Swift_module",
"The_C_module_i_want"]),
Target(name: "Some_Swift_module"),
Target(name: "The_C_module_i_want")
]
)
and the module map looks like this:
module The_C_module_i_want {
header "/usr/local/include/The_C_library/the_c_library.h"
export *
link ...
link ...
...
}
Related
I have been having a lot of trouble trying to run pytest. Basically the importing was not working properly. Let me explain. The folder structure of my project is the following:
src
└── api
├── __init__.py
├── app.py
├── document.py
└── tests
├── __init__.py
└── test_app.py
And app.py has the following import statement:
from document import Document
and obviously test_app.py imports app
Whenever I runned pytest from the src folder it would throw the following error:
ModuleNotFoundError: No module named 'document'
But once I removed the __init__.py file from the api directory it just works out of the box.
src
└── api
├── __init__.py <--- REMOVED
├── app.py
├── document.py
└── tests
├── __init__.py
└── test_app.py
I have been reading many different threads, but none of them explains why this is so.
Anyone understands why?
Sources I have been reading through:
pytest cannot import module while python can
PATH issue with pytest 'ImportError: No module named YadaYadaYada'
https://docs.pytest.org/en/6.2.x/pythonpath.html
I have a flutter project, and updated it to nullsafety just now. And I found that intl_translation plugin are not support for nullsafety. So I remove it and want to use the intl comes with the framwork of flutter.
According to the official documents, I add 2 lines: intl: ^0.17.0 # , generate: true and new a file named l10n.yaml .
l10n.yaml 's content as follow:
arb-dir: lib/l10n
template-arb-file: intl_en.arb
output-localization-file: lib/generated/intl/l10n.dart
Then my file tree as follow:
lib
├── data
│ ├── ......
├── generated
│ ├── intl
│ │ ├── messages_all.dart
│ │ ├── messages_en.dart
│ │ └── messages_zh.dart
│ └── l10n.dart
├── l10n
│ ├── intl_en.arb
│ └── intl_zh.arb
├── ......
├── ......
├── ui
│ ├── ......
└── utilities.dart
Then I flutter run my project. The ERRORS show that
Invalid ARB resource name "UPCredit" in LocalFile: '.../lib/l10n/intl_en.arb'.
Resources names must be valid Dart method names: they have to be camel case, cannot start with a number or underscore, and cannot contain non-alphanumeric characters.
Generating synthetic localizations package has failed.
The error position is in my intl_en.arb as follows:
"UPxxt": "Uxxx Cxxxit",
"UPxit": "Unxxx Dxxxt",
"UPSxit": "Uxxx Sxxxed xxxit",
MY PROBLEM:
NoBody talk me not to do like this(Maybe I can not find something about it). Can anybody help me about how to solve it? Something about document(how to find this?).
Basically, the means exactly camelCase this kind of naming convention to be used hence you'll need to stick with upCredit instead of UpCredit.
In Python 3.5, for a directory structure that looks like this:
.
└── project
└── __init__.py
└── project.py
└── module1
├── __init__.py
└── module1.py
└── module2
├── __init__.py
└── module2.py
Why do I receive "No module named 'project'" error when calling
import project.module1
from module2.py?
As far as I can tell, the docs say this should work.
I've been using Gradle for most of my Scala projects, but I want to evaluate the suitability of SBT as a replacement. One of the things I've done in Gradle is to exclude a certain resource directory from the final build (for example, using CoffeeScript to write JavaScript files that will be included as final resources).
In Gradle, I'd do this by:
sourceSets {
main {
resources {
exclude 'com/example/export/dev' // exclude development resources
}
}
}
And this would exclude the resource package com.example.export.dev package from the final build.
How would I do the same in SBT? I've tried
unmanagedResourceDirectories in Compile -= (resourceDirectory in Compile).value / "com/example/export/dev"
but that doesn't do a thing (I understand why, but that doesn't really help). And the documentation on the SBT web site only talks about excluding file patterns (at Classpaths, sources, and resources).
As a more descriptive image, say we have the following resource directory structure:
com
\---example
\---export
\---dev
\---something
In the final output, I want:
com
\---example
\---export
\---something
The way to think in SBT is a bit different and I know it can be hard at first.
In your example, you need to modify the task that generate the resource files (or the task that selects the folders to look for resource files).
Here is an example of how I can select only the resource files that start with character 'a'.
(unmanagedResources in Compile) := (unmanagedResources in Compile).value.filter(_.getName.startsWith("a"))
Similarly if you want to modify the entire directory of the resource files you can do that like this:
(unmanagedResourceDirectories in Compile) := (unmanagedResourceDirectories in Compile).value.filter(_.getName.startsWith("a"))
Obviously my filters here are just and example, you can have any complex pattern that Scala supports.
The nice thing about SBT is that it's interactive. So you can check the result of your task by simply typing these at the REPL of your project:
> show compile:unmanagedResources
> show compile: unmanagedResourceDirectories
To check all the dependencies to the task do this from the REPL:
> inspect tree compile:unmanagedResources
Assumption:
SBT knows where to find all resources using the standard maven build directory layout. The above solution assumes that all resources are under the /resources directory. You can then access them from your Scala code using getClass.getResource("/folderInsideResources/file.txt").
Here is a sample directory layout for a mixed Java/Scala project with resources:
.
├── main
│ ├── java
│ │ └── com
│ │ └── a
│ │ └── b
│ │ └── Hello.java
│ ├── resources
│ │ ├── a.tx
│ │ └── b.tx
│ └── scala
│ └── com
│ └── a
│ └── b
│ └── ScalaHello.scala
└── test
├── resources
└── scala
└── com
└── a
└── b
└── ScalaHello.scala
To access the resource file just use:
getClass.getResource("/a.txt")
getClass.getResource("/b.txt")
From https://github.com/sbt/sbt-jshint/issues/14:
excludeFilter in unmanagedResources := {
val public = ((resourceDirectory in Compile).value / "com" / "example" / "export" / "dev").getCanonicalPath
new SimpleFileFilter(_.getCanonicalPath startsWith public)
}
I'm new to both Scala and IntelliJ. I've installed Scala plugin for IntelliJ
I've installed Scala in my Ubuntu system with
sudo apt-get install scala
When I try to create new scala project, I'm required to do Scala Settings.
But the problem is I couldn't find the the home directory for my Scala installation.
What is the home directory for Scala in my ubuntu?
Thanks.
The plugin wants to know where the Scala libraries are installed (as it would want to know where the Java SDK is located for a Java module). Note that for different Scala projects you might use different versions of Scala: 2.9.0 or 2.10.2, etc. The dialog offers to download them or you can go to the Scala site and download them yourself. For example, I downloaded scala-2.10.2.tgz from http://www.scala-lang.org/download/ and expanded it in /home/glenn/Applications/Scala/ to
/home/glenn/Applications/Scala/scala-2.10.2/. This latter path is what goes in the "Set Scala Home" field in the dialog.
Note that in my case this is preferable to using the apt-get installation of Scala because the API changes so much that I usually end up with different versions of Scala for different projects that I experiment with.
Follow the version links at http://www.scala-lang.org/download/all.html to the version page with the download for the docs.
Note that for me, IDEA wanted the docs to be in the "doc/scala-devel-docs" directory, whereas the downloaded docs decompressed to "scala-docs-2.10.2". I made a link so that IDEA can find them. My 2.10.2 directory looks like this, now.
scala-2.10.2
├── bin
├── doc
│ ├── scala-devel-docs -> scala-docs-2.10.2
│ ├── scaladoc
│ │ └── lib
│ ├── scala-docs-2.10.2
│ │ └── api
│ └── tools
│ ├── css
│ └── images
├── examples
│ ├── actors
│ ├── monads
│ ├── parsing
│ │ └── lambda
│ ├── tcpoly
│ │ └── monads
│ └── xml
│ └── phonebook
├── lib
├── man
│ └── man1
├── misc
│ └── scala-devel
│ └── plugins
└── src
Run
$ dpkg -L scala
It will show a list of files in that package. Search for scalac:
$ dpkg -L scala | grep scalac
It will be something like /usr/share/scala/bin/scalac. Strip off /bin/scalac part and you will get Scala home: /usr/share/scala.
Update
It seems that there is no dedicated Scala home in Ubuntu. scala-library package files are installed simply to /usr/share/java. I guess then that the most simple way to get proper Scala home is to download a tarball from http://scala-lang.org/, extract it somewhere and use extracted directory as Scala home.