EOF error requiring file when compiling - crystal-lang

So I currently have the current directory structure:
- project
- lib
- struct
- external
- external.cr
- src
- project
- version.cr
- project.cr
- ...
- shard.yml
I am currently compiling my code using the current command, whilst in the main project directory (containing shard.yml):
`crystal src/project.cr`
I then receive the following error:
Error in src/project.cr:2: while requiring "struct/external"
require "struct/external"
^
Syntax error in lib/struct/external/external.cr:15: expecting identifier 'end', not 'EOF'
My project.cr file looks like this:
require "./project/*"
require "struct/external"
# Doc omitted
module Project
extend self
end
My external.cr file looks like this:
#
class External
def initialize(#vertices : Array(SubclassOne), #edges : Array(SubclassTwo))
end
#
class SubclassOne
def initialize()
end
#
class SubclassTwo
def initialize()
end

The functions within the classes in the external file were missing the end keyword.

Related

PyYAML shows "ScannerError: mapping values are not allowed here" in my unittest

I am trying to test a number of Python 2.7 classes using unittest.
Here is the exception:
ScannerError: mapping values are not allowed here
in "<unicode string>", line 3, column 32:
... file1_with_path: '../../testdata/concat1.csv'
Here is the example the error message relates to:
class TestConcatTransform(unittest.TestCase):
def setUp(self):
filename1 = os.path.dirname(os.path.realpath(__file__)) + '/../../testdata/concat1.pkl'
self.df1 = pd.read_pickle(filename1)
filename2 = os.path.dirname(os.path.realpath(__file__)) + '/../../testdata/concat2.pkl'
self.df2 = pd.read_pickle(filename2)
self.yamlconfig = u'''
--- !ConcatTransform
file1_with_path: '../../testdata/concat1.csv'
file2_with_path: '../../testdata/concat2.csv'
skip_header_lines: [0]
duplicates: ['%allcolumns']
outtype: 'dataframe'
client: 'testdata'
addcolumn: []
'''
self.testconcat = yaml.load(self.yamlconfig)
What is the the problem?
Something not clear to me is that the directory structure I have is:
app
app/etl
app/tests
The ConcatTransform is in app/etl/concattransform.py and TestConcatTransform is in app/tests. I import ConcatTransform into the TestConcatTransform unittest with this import:
from app.etl import concattransform
How does PyYAML associate that class with the one defined in yamlconfig?
A YAML document can start with a document start marker ---, but that has to be at the beginning of a line, and yours is indented eight positions on the second line of the input. That causes the --- to be interpreted as the beginning of a multi-line plain (i.e. non-quoted) scalar, and within such a scalar you cannot have a : (colon + space). You can only have : in quoted scalars. And if your document does not have a mapping or sequence at the root level, as yours doesn't, the whole document can only consists of a single scalar.
If you want to keep your sources nicely indented like you have now, I recommend you use dedent from textwrap.
The following runs without error:
import ruamel.yaml
from textwrap import dedent
yaml_config = dedent(u'''\
--- !ConcatTransform
file1_with_path: '../../testdata/concat1.csv'
file2_with_path: '../../testdata/concat2.csv'
skip_header_lines: [0]
duplicates: ['%allcolumns']
outtype: 'dataframe'
client: 'testdata'
addcolumn: []
''')
yaml = ruamel.yaml.YAML()
data = yaml.load(yaml_config)
You should get into the habit to put the backslash (\) at the end of your first triple-quotes, so your YAML document. If you do that, your error would have actually indicated line 2 because the document doesn't start with an empty line anymore.
During loading the YAML parser encouncters the tag !ConcatTransform. A constructor for an object is probably registered with the PyYAML loader, associating that tag with the using PyYAML's add_constructor, during the import.
Unfortunately they registered their constructor with the default, non-safe, loader, which is not necessary, they could have registered with the SafeLoader, and thereby not force users to risk problems with non-controlled input.

SwiftLint: Exclude file for specific rule

I'm trying to do something like this in my .swiftlint.yml file:
force_cast:
severity: warning # explicitly
excluded:
- Dog.swift
I have this code and I don't like the force_try warning I'm getting for it:
let cell = tableView.dequeueReusableCellWithIdentifier(Constants.dogViewCellReuseIdentifier,
forIndexPath: indexPath) as! DogViewCell
I want to suppress the warning for this file by excluding this file from the rule.
Is there a way to do that ?
Well, if you don't want some specific rules to be applied to a specific file you can use the technique mentioned by #Benno Kress. For that you need to add a comment in your swift file as given below.
The rules will be disabled until the end of the file or until the linter sees a matching enable comment:
// swiftlint:disable <rule1>
YOUR CODE WHERE NO rule1 is applied
// swiftlint:enable <rule1>
It is also possible to skip some files by configuring swiftlint.
add a ".swiftlint.yml" file in the directory where you'll run SwiftLint.
Add the following content to exclude some files. Lets say file1, file2 ... etc
excluded:
- file1
- file2
- folder1
- folder1/ExcludedFile.swift
To disable some rules completely add the following to the same ".swiftlint.yml" file.
disabled_rules: # rule identifiers to exclude from running
- colon
- comma
- control_statement
for more information, refer the following links.
https://swifting.io/blog/2016/03/29/11-swiftlint/
https://github.com/realm/SwiftLint#disable-rules-in-code
You can write // swiftlint:disable force_cast at the beginning of the file in which you want to supress the warning for this rule. It gets disabled until the end of the file or until you add the line // swiftlint:enable force_cast.
Source: https://github.com/realm/SwiftLint#disable-rules-in-code
I just get rid with force_cast
Step 1:
cd path-to-your-project
Step 2:
touch .swiftlint.yml
Step 3:
open .swiftlint.yml and add the rule
disabled_rules: # rule identifiers to exclude from running
- force_cast
Reference - https://github.com/realm/SwiftLint#disable-rules-in-code
Configure SwiftLint by adding a .swiftlint.yml file from the directory you'll run SwiftLint from. Here is the complete set of options you can use in your .swiftlint.yml file
disabled_rules: # rule identifiers to exclude from running
- colon
- comma
- control_statement
opt_in_rules: # some rules are only opt-in
- empty_count
# Find all the available rules by running:
# swiftlint rules
included: # paths to include during linting. `--path` is ignored if present.
- Source
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods
- Source/ExcludedFolder
- Source/ExcludedFile.swift
- Source/*/ExcludedFile.swift # Exclude files with a wildcard
analyzer_rules: # Rules run by `swiftlint analyze` (experimental)
- explicit_self
# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 110
# they can set both implicitly with an array
type_body_length:
- 300 # warning
- 400 # error
# or they can set both explicitly
file_length:
warning: 500
error: 1200
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
min_length: 4 # only warning
max_length: # warning and error
warning: 40
error: 50
excluded: iPhone # excluded via string
identifier_name:
min_length: # only min_length
error: 4 # only error
excluded: # excluded via string array
- id
- URL
- GlobalAPIKey
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)
Reference: github.com/realm/SwiftLint#disable-rules-in-code
You can add a new .swiftlint.yml file to the excluded folder and override rules there:
project_root/.swiftlint.yml:
opt_in_rules:
force_unwrapping
.. and other rules
and in
project_root/your_excluded_folder/.swiftlint.yml
disabled_rules:
- force_unwrapping
Then force_unwrapping will not be applied to your_excluded_folder and all subfolders
Config file from subfolder will "override" rules in the root config file.
This is useful for example for the unit tests folder
Maybe this is a better approach:
guard let cell = tableView.dequeueReusableCellWithIdentifier(Constants.dogViewCellReuseIdentifier,
forIndexPath: indexPath) as? DogViewCell else {
return UITableviewCell()
}

How I can call properties into .robot file in robot framework? Im doing the scripting in PyCharm

This is the program I implemented into my TestObject.py file
import random
import sys
import os
class MyClass:
def __init__(self,x):
self.setX(x)
def getX(self):
return self.x
def setX(self, x):
if x < 0:
self.x = 0
elif x > 1000:
self.x = 1000
else:
self.x= x
I want to call the above code into my suite where I implemented the keywords "robot framework".
How can I instantiate the objects of the above class into the robot file.
*** Settings ***
Library ../../ObjectsRepository/EngageAO/TestObject.py
I'm not getting how I can call fields, variables, functions into the .robot file
With the way you have it set up, and assuming the folder that contains this module is on your python path, you can import the class like this:
*** Settings ***
| Library | TestObject.MyClass
The methods of this class will then become keywords, eg:
*** Test cases ***
| Example
| | SetX | 10
If the path that contains the file is not on your python path, you cannot both specify the path to the file and import arbitrary classes within the file.
A common solution is for your file to have a class that that has the same name as the filename. In your case you would name the class TestObject, or name the file MyClass.py. When you do this, robot will automatically create an instance of the class and make all of the methods available as keywords.
This is documented in the section Creating test library class or module of the robot framework user guide.
I think class name and file name must be the same
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html
"If the modifier is given as a path, the class name must be same as the file name."
Btw, if we didn't define getX function, do you have anyway to get x value?

Rails `unitialized constant` for a constant defined in app/classes subdirectory in staging env

the error happens in :staging environment only
config/initializers/activity_api.rb:4:in 'block in <top (required)>'
Rails.application.config.to_prepare do
config = YAML.load_file('config/activity.yml')[Rails.env] || {}
config.deep_symbolize_keys!
Activity::API.config = config
end
And I have Activity::API class definition in app/classes/activity/api.rb
module Activity
class API
...
end
end
Shall I explicitely define a module Activity in app/classes/activity.rb and require files in app/classes/activity or there is something I misunderstand?
Maybe app/classes subdirectories are not in autoload path?
Creating an empty module Activity would help.
You can also try to user the inline class declaration style:
class Activity::Api
end

SCons: How can I attach a listener?

I need to attach to the SCons build in order to be notified when things happened during it: file compilation, files linkage, etc.
I know similar is possible for ANT builds via -listener option. Could you please tell how to do it for SCons builds?
When targets are built in SCons, you can associate a post action via the AddPostAction(target, action) function as documented here.
Here is a simple example with a python function action:
# Create yourAction here:
# can be a python function or external (shell) command line
def helloWorldAction(target = None, source = None, env = None):
'''
target: a Node object representing the target file
source: a Node object representing the source file
env: the construction environment used for building the target file
The target and source arguments may be lists of Node objects if there
is more than one target file or source file.
'''
print "PostAction for target: %s" % str(target)
# you can get a map of the source files like this:
# source_file_names = map(lambda x: str(x), source)
# compilation options, etc can be retrieved from the env
return 0
env = Environment()
progTarget = env.Program(target = "helloWorld", source = "helloWorld.cc")
env.AddPostAction(progTarget, helloWorldAction)
# Or create the action object like this:
# a = Action(helloWorldAction)
Then, each time helloWorld is built, the helloWorldAction python function will be executed afterwords.
Regarding doing this without modifying the given SConstruct, I dont see how that would be possible.